mirror of
https://github.com/open-webui/open-webui
synced 2025-04-08 22:55:18 +00:00
refac
This commit is contained in:
parent
09cd95bffe
commit
78853a67e4
@ -1103,10 +1103,15 @@ async def process_chat_response(
|
||||
|
||||
elif block["type"] == "code_interpreter":
|
||||
attributes = block.get("attributes", {})
|
||||
lang = attributes.get("lang", "")
|
||||
attribute_type = attributes.get("type", "")
|
||||
output = block.get("output", {})
|
||||
|
||||
lang = attributes.get("lang", "")
|
||||
|
||||
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'
|
||||
|
||||
content = f"{content}```{lang if lang else attribute_type}\n{block['content']}\n```\n"
|
||||
else:
|
||||
block_content = str(block["content"]).strip()
|
||||
content = f"{content}{block['type']}: {block_content}\n"
|
||||
@ -1205,7 +1210,7 @@ async def process_chat_response(
|
||||
DETECT_CODE_INTERPRETER = True
|
||||
|
||||
reasoning_tags = ["think", "reason", "reasoning", "thought", "Thought"]
|
||||
code_interpreter_tags = ["oi::code_interpreter"]
|
||||
code_interpreter_tags = ["code_interpreter"]
|
||||
|
||||
try:
|
||||
for event in events:
|
||||
@ -1339,12 +1344,13 @@ async def process_chat_response(
|
||||
and retries < MAX_RETRIES
|
||||
):
|
||||
retries += 1
|
||||
log.debug(f"Retrying code interpreter block: {retries}")
|
||||
|
||||
try:
|
||||
if content_blocks[-1]["attributes"].get("type") == "code":
|
||||
output = await event_caller(
|
||||
{
|
||||
"type": "execute:pyodide",
|
||||
"type": "execute:python",
|
||||
"data": {
|
||||
"id": str(uuid4()),
|
||||
"code": content_blocks[-1]["content"],
|
||||
@ -1354,15 +1360,7 @@ async def process_chat_response(
|
||||
except Exception as e:
|
||||
output = str(e)
|
||||
|
||||
content_blocks.append(
|
||||
{
|
||||
"type": "code_interpreter",
|
||||
"attributes": {
|
||||
"type": "output",
|
||||
},
|
||||
"content": output,
|
||||
}
|
||||
)
|
||||
content_blocks[-1]["output"] = output
|
||||
content_blocks.append(
|
||||
{
|
||||
"type": "text",
|
||||
@ -1370,6 +1368,15 @@ async def process_chat_response(
|
||||
}
|
||||
)
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
"type": "chat:completion",
|
||||
"data": {
|
||||
"content": serialize_content_blocks(content_blocks),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
res = await generate_chat_completion(
|
||||
request,
|
||||
@ -1397,15 +1404,6 @@ async def process_chat_response(
|
||||
log.debug(e)
|
||||
break
|
||||
|
||||
await event_emitter(
|
||||
{
|
||||
"type": "chat:completion",
|
||||
"data": {
|
||||
"content": serialize_content_blocks(content_blocks),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
title = Chats.get_chat_title_by_id(metadata["chat_id"])
|
||||
data = {
|
||||
"done": True,
|
||||
|
@ -195,7 +195,7 @@
|
||||
</ul>
|
||||
{/if}
|
||||
{:else if token.type === 'details'}
|
||||
<Collapsible title={token.summary} attributes={token?.attributes} className="w-fit space-y-1">
|
||||
<Collapsible title={token.summary} attributes={token?.attributes} className="w-full space-y-1">
|
||||
<div class=" mb-1.5" slot="content">
|
||||
<svelte:self id={`${id}-${tokenIdx}-d`} tokens={marked.lexer(token.text)} />
|
||||
</div>
|
||||
|
@ -248,8 +248,8 @@
|
||||
tags.set(await getAllTags(localStorage.token));
|
||||
}
|
||||
} else {
|
||||
if (type === 'execute:pyodide') {
|
||||
console.log('execute:pyodide', data);
|
||||
if (type === 'execute:python') {
|
||||
console.log('execute:python', data);
|
||||
executePythonAsWorker(data.id, data.code, cb);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user