Commit
·
e8809f1
1
Parent(s):
8362096
Implement proper buffering of the output
Browse filesSigned-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
- mcp_openai_client.py +27 -10
mcp_openai_client.py
CHANGED
@@ -65,6 +65,7 @@ When responding you must always plan the steps and enumerate all the tools that
|
|
65 |
- Present the data in clear, user-friendly language.
|
66 |
- You may summarize or explain the data retrieved, but do **not** elaborate based on outside or implicit knowledge.
|
67 |
- You may describe the data in a way that is easy to understand but you MUST NOT elaborate based on external knowledge.
|
|
|
68 |
|
69 |
6. **Presentation**:
|
70 |
- Present the data in a way that is easy to understand.
|
@@ -215,18 +216,21 @@ class MCPClientWrapper:
|
|
215 |
}
|
216 |
)
|
217 |
messages[-1]["content"] += partial[-1]["delta"]
|
218 |
-
|
219 |
-
|
220 |
-
yield (
|
221 |
-
messages,
|
222 |
-
gr.Textbox(value=""),
|
223 |
-
gr.Textbox(value=previous_response_id),
|
224 |
-
)
|
225 |
-
await asyncio.sleep(0.01)
|
226 |
-
continue
|
227 |
else:
|
228 |
is_delta = False
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
print(partial)
|
231 |
|
232 |
yield (
|
@@ -378,6 +382,19 @@ class MCPClientWrapper:
|
|
378 |
is_tool_call = False
|
379 |
tool_name = None
|
380 |
tool_args = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
elif isinstance(event, ResponseTextDeltaEvent):
|
382 |
yield [{"role": "assistant", "content": None, "delta": event.delta}]
|
383 |
|
|
|
65 |
- Present the data in clear, user-friendly language.
|
66 |
- You may summarize or explain the data retrieved, but do **not** elaborate based on outside or implicit knowledge.
|
67 |
- You may describe the data in a way that is easy to understand but you MUST NOT elaborate based on external knowledge.
|
68 |
+
- Provide summary of the answer in the last step describing some observations and insights solely based on the data.
|
69 |
|
70 |
6. **Presentation**:
|
71 |
- Present the data in a way that is easy to understand.
|
|
|
216 |
}
|
217 |
)
|
218 |
messages[-1]["content"] += partial[-1]["delta"]
|
219 |
+
if partial[-1].get("status") == "done":
|
220 |
+
await asyncio.sleep(0.05)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
else:
|
222 |
is_delta = False
|
223 |
+
if partial[-1].get("response_id"):
|
224 |
+
previous_response_id = partial[-1]["response_id"]
|
225 |
+
yield (
|
226 |
+
messages,
|
227 |
+
gr.Textbox(value=""),
|
228 |
+
gr.Textbox(value=previous_response_id),
|
229 |
+
)
|
230 |
+
await asyncio.sleep(0.01)
|
231 |
+
continue
|
232 |
+
else:
|
233 |
+
messages.extend(partial)
|
234 |
print(partial)
|
235 |
|
236 |
yield (
|
|
|
382 |
is_tool_call = False
|
383 |
tool_name = None
|
384 |
tool_args = None
|
385 |
+
|
386 |
+
elif (
|
387 |
+
isinstance(event, ResponseContentPartDoneEvent)
|
388 |
+
and event.type == "response.content_part.done"
|
389 |
+
):
|
390 |
+
yield [
|
391 |
+
{
|
392 |
+
"role": "assistant",
|
393 |
+
"content": "",
|
394 |
+
"delta": "",
|
395 |
+
"status": "done",
|
396 |
+
}
|
397 |
+
]
|
398 |
elif isinstance(event, ResponseTextDeltaEvent):
|
399 |
yield [{"role": "assistant", "content": None, "delta": event.delta}]
|
400 |
|