Commit ·
292c68a
1
Parent(s): 453ce7d
fix random
Browse files- Gradio_UI.py +3 -13
Gradio_UI.py
CHANGED
|
@@ -40,17 +40,15 @@ def pull_messages_from_step(
|
|
| 40 |
if hasattr(step_log, "model_output") and step_log.model_output is not None:
|
| 41 |
# Clean up the LLM output
|
| 42 |
model_output = step_log.model_output.strip()
|
| 43 |
-
# Remove any
|
| 44 |
-
model_output = re.sub(r"```
|
| 45 |
-
model_output = re.sub(r"<end_code>\s*
|
| 46 |
-
model_output = re.sub(r"```\s*\n\s*<end_code>", "```", model_output) # handles ```\n<end_code>
|
| 47 |
model_output = model_output.strip()
|
| 48 |
yield gr.ChatMessage(role="assistant", content=model_output)
|
| 49 |
|
| 50 |
# For tool calls, create a parent message
|
| 51 |
if hasattr(step_log, "tool_calls") and step_log.tool_calls is not None:
|
| 52 |
first_tool_call = step_log.tool_calls[0]
|
| 53 |
-
used_code = first_tool_call.name == "python_interpreter"
|
| 54 |
parent_id = f"call_{len(step_log.tool_calls)}"
|
| 55 |
|
| 56 |
# Tool call becomes the parent message with timing info
|
|
@@ -61,14 +59,6 @@ def pull_messages_from_step(
|
|
| 61 |
else:
|
| 62 |
content = str(args).strip()
|
| 63 |
|
| 64 |
-
if used_code:
|
| 65 |
-
# Clean up the content by removing any end code tags
|
| 66 |
-
content = re.sub(r"```.*?\n", "", content) # Remove existing code blocks
|
| 67 |
-
content = re.sub(r"\s*<end_code>\s*", "", content) # Remove end_code tags
|
| 68 |
-
content = content.strip()
|
| 69 |
-
if not content.startswith("```python"):
|
| 70 |
-
content = f"```python\n{content}\n```"
|
| 71 |
-
|
| 72 |
parent_message_tool = gr.ChatMessage(
|
| 73 |
role="assistant",
|
| 74 |
content=content,
|
|
|
|
| 40 |
if hasattr(step_log, "model_output") and step_log.model_output is not None:
|
| 41 |
# Clean up the LLM output
|
| 42 |
model_output = step_log.model_output.strip()
|
| 43 |
+
# Remove any code-related formatting
|
| 44 |
+
model_output = re.sub(r"```.*?\n", "", model_output) # Remove code blocks
|
| 45 |
+
model_output = re.sub(r"\s*<end_code>\s*", "", model_output) # Remove end_code tags
|
|
|
|
| 46 |
model_output = model_output.strip()
|
| 47 |
yield gr.ChatMessage(role="assistant", content=model_output)
|
| 48 |
|
| 49 |
# For tool calls, create a parent message
|
| 50 |
if hasattr(step_log, "tool_calls") and step_log.tool_calls is not None:
|
| 51 |
first_tool_call = step_log.tool_calls[0]
|
|
|
|
| 52 |
parent_id = f"call_{len(step_log.tool_calls)}"
|
| 53 |
|
| 54 |
# Tool call becomes the parent message with timing info
|
|
|
|
| 59 |
else:
|
| 60 |
content = str(args).strip()
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
parent_message_tool = gr.ChatMessage(
|
| 63 |
role="assistant",
|
| 64 |
content=content,
|