|
@@ -1103,10 +1103,15 @@ async def process_chat_response(
|
|
|
|
|
|
elif block["type"] == "code_interpreter":
|
|
elif block["type"] == "code_interpreter":
|
|
attributes = block.get("attributes", {})
|
|
attributes = block.get("attributes", {})
|
|
|
|
+ output = block.get("output", {})
|
|
|
|
+
|
|
lang = attributes.get("lang", "")
|
|
lang = attributes.get("lang", "")
|
|
- attribute_type = attributes.get("type", "")
|
|
|
|
|
|
|
|
- content = f"{content}```{lang if lang else attribute_type}\n{block['content']}\n```\n"
|
|
|
|
|
|
+ if output:
|
|
|
|
+ content = f'{content}<details type="code_interpreter" done="true">\n<summary>Analyzed</summary>\n```{lang}\n{block["content"]}\n```\n```output\n{output}\n```\n</details>\n'
|
|
|
|
+ else:
|
|
|
|
+ content = f'{content}<details type="code_interpreter" done="false">\n<summary>Analyzing...</summary>\n```{lang}\n{block["content"]}\n```\n</details>\n'
|
|
|
|
+
|
|
else:
|
|
else:
|
|
block_content = str(block["content"]).strip()
|
|
block_content = str(block["content"]).strip()
|
|
content = f"{content}{block['type']}: {block_content}\n"
|
|
content = f"{content}{block['type']}: {block_content}\n"
|
|
@@ -1205,7 +1210,7 @@ async def process_chat_response(
|
|
DETECT_CODE_INTERPRETER = True
|
|
DETECT_CODE_INTERPRETER = True
|
|
|
|
|
|
reasoning_tags = ["think", "reason", "reasoning", "thought", "Thought"]
|
|
reasoning_tags = ["think", "reason", "reasoning", "thought", "Thought"]
|
|
- code_interpreter_tags = ["oi::code_interpreter"]
|
|
|
|
|
|
+ code_interpreter_tags = ["code_interpreter"]
|
|
|
|
|
|
try:
|
|
try:
|
|
for event in events:
|
|
for event in events:
|
|
@@ -1339,12 +1344,13 @@ async def process_chat_response(
|
|
and retries < MAX_RETRIES
|
|
and retries < MAX_RETRIES
|
|
):
|
|
):
|
|
retries += 1
|
|
retries += 1
|
|
|
|
+ log.debug(f"Retrying code interpreter block: {retries}")
|
|
|
|
|
|
try:
|
|
try:
|
|
if content_blocks[-1]["attributes"].get("type") == "code":
|
|
if content_blocks[-1]["attributes"].get("type") == "code":
|
|
output = await event_caller(
|
|
output = await event_caller(
|
|
{
|
|
{
|
|
- "type": "execute:pyodide",
|
|
|
|
|
|
+ "type": "execute:python",
|
|
"data": {
|
|
"data": {
|
|
"id": str(uuid4()),
|
|
"id": str(uuid4()),
|
|
"code": content_blocks[-1]["content"],
|
|
"code": content_blocks[-1]["content"],
|
|
@@ -1354,19 +1360,20 @@ async def process_chat_response(
|
|
except Exception as e:
|
|
except Exception as e:
|
|
output = str(e)
|
|
output = str(e)
|
|
|
|
|
|
|
|
+ content_blocks[-1]["output"] = output
|
|
content_blocks.append(
|
|
content_blocks.append(
|
|
{
|
|
{
|
|
- "type": "code_interpreter",
|
|
|
|
- "attributes": {
|
|
|
|
- "type": "output",
|
|
|
|
- },
|
|
|
|
- "content": output,
|
|
|
|
|
|
+ "type": "text",
|
|
|
|
+ "content": "",
|
|
}
|
|
}
|
|
)
|
|
)
|
|
- content_blocks.append(
|
|
|
|
|
|
+
|
|
|
|
+ await event_emitter(
|
|
{
|
|
{
|
|
- "type": "text",
|
|
|
|
- "content": "",
|
|
|
|
|
|
+ "type": "chat:completion",
|
|
|
|
+ "data": {
|
|
|
|
+ "content": serialize_content_blocks(content_blocks),
|
|
|
|
+ },
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
@@ -1397,15 +1404,6 @@ async def process_chat_response(
|
|
log.debug(e)
|
|
log.debug(e)
|
|
break
|
|
break
|
|
|
|
|
|
- await event_emitter(
|
|
|
|
- {
|
|
|
|
- "type": "chat:completion",
|
|
|
|
- "data": {
|
|
|
|
- "content": serialize_content_blocks(content_blocks),
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
title = Chats.get_chat_title_by_id(metadata["chat_id"])
|
|
title = Chats.get_chat_title_by_id(metadata["chat_id"])
|
|
data = {
|
|
data = {
|
|
"done": True,
|
|
"done": True,
|