bstraehle commited on
Commit
7ddca6e
·
verified ·
1 Parent(s): 21b27f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -28
app.py CHANGED
@@ -100,34 +100,16 @@ def get_run_steps(client, thread, run):
100
  return run_steps
101
 
102
  def get_run_step_details(run_steps):
 
 
103
  for step in run_steps.data:
104
  step_details = step.step_details
 
105
 
106
  show_json("step_details", step_details)
107
 
108
- ###
109
- if hasattr(step_details, "tool_calls"):
110
- for tool_call in step_details.tool_calls:
111
- print("\n\n")
112
- show_json("tool_call", tool_call)
113
- print("\n\n")
114
- if hasattr(tool_call, "code_interpreter"):
115
- print(tool_call.code_interpreter)
116
- print("\n\n")
117
- if hasattr(tool_call.code_interpreter, "outputs"):
118
- print(tool_call.code_interpreter.outputs)
119
- # [CodeInterpreterOutputImage(image=CodeInterpreterOutputImageImage(file_id='file-qmr1d6ObICSjyGvmoncXvBPj'), type='image')]
120
- if len(tool_call.code_interpreter.outputs) > 0:
121
- if hasattr(tool_call.code_interpreter.outputs[0], "image"):
122
- print("\n111")
123
- file_id = tool_call.code_interpreter.outputs[0].image.file_id
124
- download = f"Download file here: https://platform.openai.com/storage/files/{file_id}"
125
- print("\n222")
126
- print(download)
127
- print("\n333")
128
- #img = generate_markdown_image(content.arrayBuffer())
129
- return download
130
-
131
  def get_messages(client, thread):
132
  messages = client.beta.threads.messages.list(
133
  thread_id=thread.id
@@ -143,9 +125,11 @@ def extract_content_values(data):
143
  for item in data.data:
144
  for content in item.content:
145
  if content.type == "text":
146
- text_values.append(content.text.value)
 
147
  if content.type == "image_file":
148
- image_values.append(content.image_file.file_id)
 
149
 
150
  return text_values, image_values
151
 
@@ -174,13 +158,17 @@ def chat(message, history):
174
 
175
  text_values, image_values = extract_content_values(messages)
176
 
 
 
177
  print("###")
178
- print(text_values)
179
  print("###")
180
- print(image_values)
 
 
181
  print("###")
182
 
183
- return {text_values[1]}
184
 
185
  gr.ChatInterface(
186
  fn=chat,
 
100
  return run_steps
101
 
102
  def get_run_step_details(run_steps):
103
+ run_step_details = []
104
+
105
  for step in run_steps.data:
106
  step_details = step.step_details
107
+ run_step_details.append(step_details)
108
 
109
  show_json("step_details", step_details)
110
 
111
+ return run_step_details
112
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  def get_messages(client, thread):
114
  messages = client.beta.threads.messages.list(
115
  thread_id=thread.id
 
125
  for item in data.data:
126
  for content in item.content:
127
  if content.type == "text":
128
+ text_value = content.text.value
129
+ text_values.append(text_value)
130
  if content.type == "image_file":
131
+ image_value = content.image_file.file_id
132
+ image_values.append(image_value)
133
 
134
  return text_values, image_values
135
 
 
158
 
159
  text_values, image_values = extract_content_values(messages)
160
 
161
+ download_link = ""
162
+
163
  print("###")
164
+ print(text_values[0])
165
  print("###")
166
+ if len(image values) > 0:
167
+ print(image_values[0])
168
+ download_link = f"https://platform.openai.com/storage/files/{image_values[0]}"
169
  print("###")
170
 
171
+ return f"{text_values[0]}{download_link}"
172
 
173
  gr.ChatInterface(
174
  fn=chat,