Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,6 +126,7 @@ def create_issues_repairs_agent(client):
|
|
| 126 |
def create_thread(client):
|
| 127 |
thread = client.beta.threads.create()
|
| 128 |
#show_json("thread", thread)
|
|
|
|
| 129 |
return thread
|
| 130 |
|
| 131 |
def create_message(client, thread, msg):
|
|
@@ -135,6 +136,7 @@ def create_message(client, thread, msg):
|
|
| 135 |
content=msg,
|
| 136 |
)
|
| 137 |
#show_json("message", message)
|
|
|
|
| 138 |
return message
|
| 139 |
|
| 140 |
def create_run(client, assistant, thread):
|
|
@@ -143,6 +145,7 @@ def create_run(client, assistant, thread):
|
|
| 143 |
thread_id=thread.id,
|
| 144 |
)
|
| 145 |
#show_json("run", run)
|
|
|
|
| 146 |
return run
|
| 147 |
|
| 148 |
def wait_on_run(client, thread, run):
|
|
@@ -153,6 +156,7 @@ def wait_on_run(client, thread, run):
|
|
| 153 |
)
|
| 154 |
time.sleep(0.25)
|
| 155 |
#show_json("run", run)
|
|
|
|
| 156 |
return run
|
| 157 |
|
| 158 |
###
|
|
@@ -160,6 +164,7 @@ def execute_tool_call(tool_call):
|
|
| 160 |
name = tool_call.function.name
|
| 161 |
args = json.loads(tool_call.function.arguments)
|
| 162 |
print(f"{name}, {args}")
|
|
|
|
| 163 |
#return tools[name](**args)
|
| 164 |
###
|
| 165 |
|
|
@@ -174,11 +179,11 @@ def list_run_steps(client, thread, run):
|
|
| 174 |
step_details = step.step_details
|
| 175 |
show_json("step_details", step_details)
|
| 176 |
|
| 177 |
-
if not step_details.tool_calls:
|
| 178 |
-
|
| 179 |
|
| 180 |
-
for tool_call in step_details.tool_calls:
|
| 181 |
-
|
| 182 |
|
| 183 |
return run_steps
|
| 184 |
|
|
@@ -187,14 +192,17 @@ def list_messages(client, thread):
|
|
| 187 |
thread_id=thread.id
|
| 188 |
)
|
| 189 |
#show_json("messages", messages)
|
|
|
|
| 190 |
return messages
|
| 191 |
|
| 192 |
def extract_content_values(data):
|
| 193 |
content_values = []
|
|
|
|
| 194 |
for item in data.data:
|
| 195 |
for content in item.content:
|
| 196 |
if content.type == 'text':
|
| 197 |
content_values.append(content.text.value)
|
|
|
|
| 198 |
return content_values
|
| 199 |
|
| 200 |
#
|
|
@@ -238,6 +246,7 @@ def chat(message, history, openai_api_key):
|
|
| 238 |
|
| 239 |
assistant = get_current_agent()
|
| 240 |
show_json("Current Agent", assistant)
|
|
|
|
| 241 |
thread = get_current_thread()
|
| 242 |
#show_json("Current Thread", thread)
|
| 243 |
|
|
|
|
| 126 |
def create_thread(client):
|
| 127 |
thread = client.beta.threads.create()
|
| 128 |
#show_json("thread", thread)
|
| 129 |
+
|
| 130 |
return thread
|
| 131 |
|
| 132 |
def create_message(client, thread, msg):
|
|
|
|
| 136 |
content=msg,
|
| 137 |
)
|
| 138 |
#show_json("message", message)
|
| 139 |
+
|
| 140 |
return message
|
| 141 |
|
| 142 |
def create_run(client, assistant, thread):
|
|
|
|
| 145 |
thread_id=thread.id,
|
| 146 |
)
|
| 147 |
#show_json("run", run)
|
| 148 |
+
|
| 149 |
return run
|
| 150 |
|
| 151 |
def wait_on_run(client, thread, run):
|
|
|
|
| 156 |
)
|
| 157 |
time.sleep(0.25)
|
| 158 |
#show_json("run", run)
|
| 159 |
+
|
| 160 |
return run
|
| 161 |
|
| 162 |
###
|
|
|
|
| 164 |
name = tool_call.function.name
|
| 165 |
args = json.loads(tool_call.function.arguments)
|
| 166 |
print(f"{name}, {args}")
|
| 167 |
+
|
| 168 |
#return tools[name](**args)
|
| 169 |
###
|
| 170 |
|
|
|
|
| 179 |
step_details = step.step_details
|
| 180 |
show_json("step_details", step_details)
|
| 181 |
|
| 182 |
+
#if not step_details.tool_calls:
|
| 183 |
+
# break
|
| 184 |
|
| 185 |
+
#for tool_call in step_details.tool_calls:
|
| 186 |
+
# result = execute_tool_call(tool_call)
|
| 187 |
|
| 188 |
return run_steps
|
| 189 |
|
|
|
|
| 192 |
thread_id=thread.id
|
| 193 |
)
|
| 194 |
#show_json("messages", messages)
|
| 195 |
+
|
| 196 |
return messages
|
| 197 |
|
| 198 |
def extract_content_values(data):
|
| 199 |
content_values = []
|
| 200 |
+
|
| 201 |
for item in data.data:
|
| 202 |
for content in item.content:
|
| 203 |
if content.type == 'text':
|
| 204 |
content_values.append(content.text.value)
|
| 205 |
+
|
| 206 |
return content_values
|
| 207 |
|
| 208 |
#
|
|
|
|
| 246 |
|
| 247 |
assistant = get_current_agent()
|
| 248 |
show_json("Current Agent", assistant)
|
| 249 |
+
|
| 250 |
thread = get_current_thread()
|
| 251 |
#show_json("Current Thread", thread)
|
| 252 |
|