Spaces:
Running
Running
dont send full traces to endpoint
Browse files
app.py
CHANGED
|
@@ -83,7 +83,7 @@ def execute_jupyter_agent(
|
|
| 83 |
)
|
| 84 |
message_history.append({"role": "user", "content": user_input})
|
| 85 |
|
| 86 |
-
print("history:", message_history)
|
| 87 |
|
| 88 |
for notebook_html, notebook_data, messages in run_interactive_notebook(
|
| 89 |
client, model, message_history, sbx, max_new_tokens=max_new_tokens
|
|
|
|
| 83 |
)
|
| 84 |
message_history.append({"role": "user", "content": user_input})
|
| 85 |
|
| 86 |
+
#print("history:", message_history)
|
| 87 |
|
| 88 |
for notebook_html, notebook_data, messages in run_interactive_notebook(
|
| 89 |
client, model, message_history, sbx, max_new_tokens=max_new_tokens
|
utils.py
CHANGED
|
@@ -81,6 +81,19 @@ def parse_exec_result_llm(execution, max_code_output=1000):
|
|
| 81 |
output.append(truncate_if_needed(execution.error.traceback))
|
| 82 |
return "\n".join(output)
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def run_interactive_notebook(client, model, messages, sbx, max_new_tokens=512):
|
| 86 |
notebook = JupyterNotebook(messages)
|
|
@@ -91,21 +104,17 @@ def run_interactive_notebook(client, model, messages, sbx, max_new_tokens=512):
|
|
| 91 |
max_code_output = 1000
|
| 92 |
turns = 0
|
| 93 |
done = False
|
| 94 |
-
|
| 95 |
-
print("SBX INFO", sbx.get_info())
|
| 96 |
|
| 97 |
while not done and (turns <= MAX_TURNS):
|
| 98 |
turns += 1
|
| 99 |
-
|
| 100 |
try:
|
| 101 |
# Inference client call - might fail
|
| 102 |
response = client.chat.completions.create(
|
| 103 |
-
messages=messages,
|
| 104 |
model=model,
|
| 105 |
tools=TOOLS,
|
| 106 |
tool_choice="auto",
|
| 107 |
)
|
| 108 |
-
|
| 109 |
except Exception as e:
|
| 110 |
# Handle inference client errors
|
| 111 |
notebook.add_error(f"Inference failed: {str(e)}")
|
|
|
|
| 81 |
output.append(truncate_if_needed(execution.error.traceback))
|
| 82 |
return "\n".join(output)
|
| 83 |
|
| 84 |
+
def clean_messages_for_api(messages):
|
| 85 |
+
"""
|
| 86 |
+
Create a clean copy of messages without raw_execution fields for API calls.
|
| 87 |
+
This prevents 413 errors caused by large execution data.
|
| 88 |
+
"""
|
| 89 |
+
cleaned_messages = []
|
| 90 |
+
for message in messages:
|
| 91 |
+
cleaned_message = message.copy()
|
| 92 |
+
if "raw_execution" in cleaned_message:
|
| 93 |
+
cleaned_message.pop("raw_execution")
|
| 94 |
+
cleaned_messages.append(cleaned_message)
|
| 95 |
+
return cleaned_messages
|
| 96 |
+
|
| 97 |
|
| 98 |
def run_interactive_notebook(client, model, messages, sbx, max_new_tokens=512):
|
| 99 |
notebook = JupyterNotebook(messages)
|
|
|
|
| 104 |
max_code_output = 1000
|
| 105 |
turns = 0
|
| 106 |
done = False
|
|
|
|
|
|
|
| 107 |
|
| 108 |
while not done and (turns <= MAX_TURNS):
|
| 109 |
turns += 1
|
|
|
|
| 110 |
try:
|
| 111 |
# Inference client call - might fail
|
| 112 |
response = client.chat.completions.create(
|
| 113 |
+
messages=clean_messages_for_api(messages),
|
| 114 |
model=model,
|
| 115 |
tools=TOOLS,
|
| 116 |
tool_choice="auto",
|
| 117 |
)
|
|
|
|
| 118 |
except Exception as e:
|
| 119 |
# Handle inference client errors
|
| 120 |
notebook.add_error(f"Inference failed: {str(e)}")
|