bstraehle commited on
Commit
26f3de7
1 Parent(s): 1e8146c

Update assistants.py

Browse files
Files changed (1) hide show
  1. assistants.py +12 -10
assistants.py CHANGED
@@ -8,7 +8,7 @@ from datetime import date
8
  from openai import OpenAI
9
  from tavily import TavilyClient
10
  from typing import List
11
- from utils import function_to_schema, show_json
12
 
13
  openai_client, assistant, thread = None, None, None
14
 
@@ -85,12 +85,12 @@ def create_assistant():
85
 
86
  def load_assistant():
87
  assistant = openai_client.beta.assistants.retrieve(assistant_id)
88
- show_json("assistant", assistant)
89
  return assistant
90
 
91
  def create_thread():
92
  thread = openai_client.beta.threads.create()
93
- show_json("thread", thread)
94
  return thread
95
 
96
  def create_message(thread, msg):
@@ -100,7 +100,7 @@ def create_message(thread, msg):
100
  content=msg,
101
  )
102
 
103
- show_json("message", message)
104
  return message
105
 
106
  def create_run(assistant, thread):
@@ -110,7 +110,7 @@ def create_run(assistant, thread):
110
  parallel_tool_calls=False,
111
  )
112
 
113
- show_json("run", run)
114
  return run
115
 
116
  def wait_on_run(thread, run):
@@ -122,7 +122,7 @@ def wait_on_run(thread, run):
122
 
123
  time.sleep(1)
124
 
125
- show_json("run", run)
126
 
127
  if hasattr(run, "last_error") and run.last_error:
128
  raise gr.Error(run.last_error)
@@ -136,7 +136,7 @@ def get_run_steps(thread, run):
136
  order="asc",
137
  )
138
 
139
- show_json("run_steps", run_steps)
140
  return run_steps
141
 
142
  def execute_tool_call(tool_call):
@@ -162,11 +162,13 @@ def execute_tool_calls(run_steps):
162
  for step in run_steps.data:
163
  step_details = step.step_details
164
  run_step_details.append(step_details)
165
- show_json("step_details", step_details)
166
 
167
  if hasattr(step_details, "tool_calls"):
168
  for tool_call in step_details.tool_calls:
169
- gr.Info(f"Tool call: {show_json("tool_call", tool_call)}")
 
 
170
 
171
  if hasattr(tool_call, "function"):
172
  tool_call_ids.append(tool_call.id)
@@ -209,7 +211,7 @@ def get_messages(thread):
209
  thread_id=thread.id
210
  )
211
 
212
- show_json("messages", messages)
213
  return messages
214
 
215
  def extract_content_values(data):
 
8
  from openai import OpenAI
9
  from tavily import TavilyClient
10
  from typing import List
11
+ from utils import function_to_schema, get_json
12
 
13
  openai_client, assistant, thread = None, None, None
14
 
 
85
 
86
  def load_assistant():
87
  assistant = openai_client.beta.assistants.retrieve(assistant_id)
88
+ print(get_json("assistant", assistant))
89
  return assistant
90
 
91
  def create_thread():
92
  thread = openai_client.beta.threads.create()
93
+ print(get_json("thread", thread))
94
  return thread
95
 
96
  def create_message(thread, msg):
 
100
  content=msg,
101
  )
102
 
103
+ print(get_json("message", message))
104
  return message
105
 
106
  def create_run(assistant, thread):
 
110
  parallel_tool_calls=False,
111
  )
112
 
113
+ print(get_json("run", run))
114
  return run
115
 
116
  def wait_on_run(thread, run):
 
122
 
123
  time.sleep(1)
124
 
125
+ print(get_json("run", run))
126
 
127
  if hasattr(run, "last_error") and run.last_error:
128
  raise gr.Error(run.last_error)
 
136
  order="asc",
137
  )
138
 
139
+ print(get_json("run_steps", run_steps))
140
  return run_steps
141
 
142
  def execute_tool_call(tool_call):
 
162
  for step in run_steps.data:
163
  step_details = step.step_details
164
  run_step_details.append(step_details)
165
+ print(get_json("step_details", step_details))
166
 
167
  if hasattr(step_details, "tool_calls"):
168
  for tool_call in step_details.tool_calls:
169
+ str = get_json("tool_call", tool_call)
170
+ print(str)
171
+ gr.Info(str)
172
 
173
  if hasattr(tool_call, "function"):
174
  tool_call_ids.append(tool_call.id)
 
211
  thread_id=thread.id
212
  )
213
 
214
+ print(get_json("messages", messages))
215
  return messages
216
 
217
  def extract_content_values(data):