fxmeng commited on
Commit
f4f8a92
1 Parent(s): d25ad55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -31,12 +31,13 @@ def GenerateImageByCode(client, message, code_prompt):
31
  )
32
  run = wait_on_run(run, client, thread)
33
  run_steps = client.beta.threads.runs.steps.list(thread_id=thread.id, run_id=run.id, order="asc")
 
34
  for data in run_steps.model_dump()['data']:
35
  if "tool_calls" in data['step_details']:
36
  code = data['step_details']['tool_calls'][0]['code_interpreter']['input']
37
  if 'image' in data['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0].keys():
38
  image_id = data['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]['image']['file_id']
39
- assert image_id
40
  image_bytes = client.files.with_raw_response.content(image_id).content
41
  with open(f'{image_id}.png', 'wb') as f:
42
  f.write(image_bytes)
 
31
  )
32
  run = wait_on_run(run, client, thread)
33
  run_steps = client.beta.threads.runs.steps.list(thread_id=thread.id, run_id=run.id, order="asc")
34
+ image_id = None
35
  for data in run_steps.model_dump()['data']:
36
  if "tool_calls" in data['step_details']:
37
  code = data['step_details']['tool_calls'][0]['code_interpreter']['input']
38
  if 'image' in data['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0].keys():
39
  image_id = data['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]['image']['file_id']
40
+ assert image_id is not None
41
  image_bytes = client.files.with_raw_response.content(image_id).content
42
  with open(f'{image_id}.png', 'wb') as f:
43
  f.write(image_bytes)