bstraehle commited on
Commit
e45b8de
1 Parent(s): e3ca97c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -102,7 +102,7 @@ def get_run_steps(client, thread, run):
102
  def get_run_step_details(run_steps):
103
  for step in run_steps.data:
104
  step_details = step.step_details
105
- #extract_file_id(step_details) #XXXXX
106
 
107
  show_json("step_details", step_details)
108
 
@@ -116,15 +116,26 @@ def get_messages(client, thread):
116
  return messages
117
 
118
  #XXXXX
119
- def extract_file_id(step_details):
120
- for step in step_details:
121
- if hasattr(step["step_details"], "tool_calls"):
122
- for tool_call in step['step_details'].tool_calls:
123
- if hasattr(tool_call, "code_interpreter") and hasattr(tool_call.code_interpreter, "outputs"):
124
- for output in tool_call.code_interpreter.outputs:
125
- if hasattr(output, "image") and hasattr(output.image, "file_id"):
126
- file_id = output.image.file_id
127
- print(f"#############################################3Found file_id: {file_id}")
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  def extract_content_values(data):
130
  content_values = []
 
102
  def get_run_step_details(run_steps):
103
  for step in run_steps.data:
104
  step_details = step.step_details
105
+ extract_file_ids(step_details) #XXXXX
106
 
107
  show_json("step_details", step_details)
108
 
 
116
  return messages
117
 
118
  #XXXXX
119
+ def extract_file_ids(data: Dict[str, Any]) -> List[str]:
120
+ file_ids = []
121
+ steps = data.get('data', [])
122
+
123
+ for step in steps:
124
+ step_details = step.get('step_details', {})
125
+ tool_calls = step_details.get('tool_calls', [])
126
+
127
+ for tool_call in tool_calls:
128
+ code_interpreter = tool_call.get('code_interpreter', {})
129
+ outputs = code_interpreter.get('outputs', [])
130
+
131
+ for output in outputs:
132
+ if 'image' in output:
133
+ file_id = output['image'].get('file_id')
134
+ if file_id:
135
+ file_ids.append(file_id)
136
+ print(f"\n\n\n\n\n{file_id}")
137
+
138
+ return file_ids
139
 
140
  def extract_content_values(data):
141
  content_values = []