AUXteam commited on
Commit
107ce46
·
verified ·
1 Parent(s): 0f8d212

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +2 -1
  2. app.py +1 -1
  3. run.py +7 -6
  4. utils.py +1 -1
README.md CHANGED
@@ -15,11 +15,12 @@ This is a Gradio demo of the WebVoyager agent, which can complete user instructi
15
 
16
  ## Setup
17
 
18
- To use this space, you must set your OpenAI API key as a secret.
19
 
20
  1. Go to the "Settings" tab of this space.
21
  2. Scroll down to the "Secrets" section.
22
  3. Click on "New secret" and add your `BLABLADOR_API_KEY`.
 
23
 
24
  ## How to use
25
 
 
15
 
16
  ## Setup
17
 
18
+ To use this space, you must set your `BLABLADOR_API_KEY` and `OPENAI_API_KEY` as secrets.
19
 
20
  1. Go to the "Settings" tab of this space.
21
  2. Scroll down to the "Secrets" section.
22
  3. Click on "New secret" and add your `BLABLADOR_API_KEY`.
23
+ 4. Click on "New secret" and add your `OPENAI_API_KEY`.
24
 
25
  ## How to use
26
 
app.py CHANGED
@@ -68,7 +68,7 @@ def run_script_for_gradio(url, task):
68
  max_iter=5,
69
  api_key=os.environ.get("BLABLADOR_API_KEY"),
70
  api_base_url="https://api.helmholtz-blablador.fz-juelich.de/v1",
71
- api_model="alias-fats",
72
  output_dir=os.path.join(temp_dir, 'results'),
73
  seed=None,
74
  max_attached_imgs=1,
 
68
  max_iter=5,
69
  api_key=os.environ.get("BLABLADOR_API_KEY"),
70
  api_base_url="https://api.helmholtz-blablador.fz-juelich.de/v1",
71
+ api_model="alias-fast",
72
  output_dir=os.path.join(temp_dir, 'results'),
73
  seed=None,
74
  max_attached_imgs=1,
run.py CHANGED
@@ -85,19 +85,19 @@ def format_msg(it, init_msg, pdf_obs, warn_obs, web_img_b64, web_text):
85
  ]
86
  }
87
 
88
- def call_gpt4v_api(args, openai_client, messages):
89
  retry_times = 0
90
  wait_time = 5 # Initial wait time
91
  while True:
92
  try:
93
  if not args.text_only:
94
  logging.info('Calling gpt4v API...')
95
- openai_response = openai_client.chat.completions.create(
96
- model=args.api_model, messages=messages, max_tokens=1000, seed=args.seed
97
  )
98
  else:
99
  logging.info('Calling gpt4 API...')
100
- openai_response = openai_client.chat.completions.create(
101
  model='alias-large', messages=messages, max_tokens=1000, seed=args.seed, timeout=30
102
  )
103
 
@@ -253,7 +253,8 @@ def webvoyager_run(args, task, task_dir):
253
  """
254
  A generator function that yields log messages for each step of the WebVoyager run.
255
  """
256
- client = OpenAI(api_key=args.api_key, base_url=args.api_base_url, http_client=httpx.Client(trust_env=False))
 
257
  options = driver_config(args)
258
  setup_logger(task_dir)
259
 
@@ -278,7 +279,7 @@ def webvoyager_run(args, task, task_dir):
278
  # Log the user message
279
  yield json.dumps(curr_msg)
280
 
281
- for status, result in call_gpt4v_api(args, client, messages):
282
  if status == "status":
283
  yield json.dumps({"status": result})
284
  elif status == "result":
 
85
  ]
86
  }
87
 
88
+ def call_gpt4v_api(args, client_blablador, client_openai, messages):
89
  retry_times = 0
90
  wait_time = 5 # Initial wait time
91
  while True:
92
  try:
93
  if not args.text_only:
94
  logging.info('Calling gpt4v API...')
95
+ openai_response = client_openai.chat.completions.create(
96
+ model="gpt-4-vision-preview", messages=messages, max_tokens=1000, seed=args.seed
97
  )
98
  else:
99
  logging.info('Calling gpt4 API...')
100
+ openai_response = client_blablador.chat.completions.create(
101
  model='alias-large', messages=messages, max_tokens=1000, seed=args.seed, timeout=30
102
  )
103
 
 
253
  """
254
  A generator function that yields log messages for each step of the WebVoyager run.
255
  """
256
+ client_blablador = OpenAI(api_key=args.api_key, base_url=args.api_base_url, http_client=httpx.Client(trust_env=False))
257
+ client_openai = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), http_client=httpx.Client(trust_env=False))
258
  options = driver_config(args)
259
  setup_logger(task_dir)
260
 
 
279
  # Log the user message
280
  yield json.dumps(curr_msg)
281
 
282
+ for status, result in call_gpt4v_api(args, client_blablador, client_openai, messages):
283
  if status == "status":
284
  yield json.dumps({"status": result})
285
  elif status == "result":
utils.py CHANGED
@@ -370,7 +370,7 @@ def get_pdf_retrieval_ans_from_assistant(client, pdf_path, task):
370
  logging.info("Create assistant...")
371
  assistant = client.beta.assistants.create(
372
  instructions="You are a helpful assistant that can analyze the content of a PDF file and give an answer that matches the given task, or retrieve relevant content that matches the task.",
373
- model="alias-fats",
374
  tools=[{"type": "retrieval"}],
375
  file_ids=[file.id]
376
  )
 
370
  logging.info("Create assistant...")
371
  assistant = client.beta.assistants.create(
372
  instructions="You are a helpful assistant that can analyze the content of a PDF file and give an answer that matches the given task, or retrieve relevant content that matches the task.",
373
+ model="alias-fast",
374
  tools=[{"type": "retrieval"}],
375
  file_ids=[file.id]
376
  )