Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -148,7 +148,28 @@ async def chat(input_data: ChatInput):
|
|
| 148 |
yield f"{json.dumps({'type': 'tool_start', 'tool': event['name'], 'input': tool_input})}\n"
|
| 149 |
|
| 150 |
elif kind == "on_tool_end":
|
| 151 |
-
tool_output = event['data'].get('output', '').content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
yield f"{json.dumps({'type': 'tool_end', 'tool': event['name'], 'output': tool_output})}\n"
|
| 153 |
return EventSourceResponse(
|
| 154 |
generate(),
|
|
|
|
| 148 |
yield f"{json.dumps({'type': 'tool_start', 'tool': event['name'], 'input': tool_input})}\n"
|
| 149 |
|
| 150 |
elif kind == "on_tool_end":
|
| 151 |
+
tool_output = event['data'].get('output', '').content
|
| 152 |
+
#print(type(tool_output))
|
| 153 |
+
#print(dir(tool_output))
|
| 154 |
+
#print the keys
|
| 155 |
+
pattern = r'data: (.*?)\ndata:'
|
| 156 |
+
match = re.search(pattern, tool_output)
|
| 157 |
+
print(tool_output)
|
| 158 |
+
|
| 159 |
+
if match:
|
| 160 |
+
tool_output_json = match.group(1).strip()
|
| 161 |
+
try:
|
| 162 |
+
tool_output = json.loads(tool_output_json)
|
| 163 |
+
if "artifacts" in tool_output:
|
| 164 |
+
for artifact in tool_output["artifacts"]:
|
| 165 |
+
artifact_content = requests.get(f"{API_URL}/artifact/{artifact['artifact_id']}").content
|
| 166 |
+
print(artifact_content)
|
| 167 |
+
tool_output["artifacts"][artifact["artifact_id"]] = artifact_content
|
| 168 |
+
except Exception as e:
|
| 169 |
+
print(e)
|
| 170 |
+
print("Error parsing tool output as json: ", tool_output)
|
| 171 |
+
else:
|
| 172 |
+
print("No match found in tool output")
|
| 173 |
yield f"{json.dumps({'type': 'tool_end', 'tool': event['name'], 'output': tool_output})}\n"
|
| 174 |
return EventSourceResponse(
|
| 175 |
generate(),
|