mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +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":
|
elif block["type"] == "code_interpreter":
|
||||||
attributes = block.get("attributes", {})
|
attributes = block.get("attributes", {})
|
||||||
lang = attributes.get("lang", "")
|
output = block.get("output", {})
|
||||||
attribute_type = attributes.get("type", "")
|
|
||||||
|
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:
|
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,15 +1360,7 @@ async def process_chat_response(
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
output = str(e)
|
output = str(e)
|
||||||
|
|
||||||
content_blocks.append(
|
content_blocks[-1]["output"] = output
|
||||||
{
|
|
||||||
"type": "code_interpreter",
|
|
||||||
"attributes": {
|
|
||||||
"type": "output",
|
|
||||||
},
|
|
||||||
"content": output,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
content_blocks.append(
|
content_blocks.append(
|
||||||
{
|
{
|
||||||
"type": "text",
|
"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:
|
try:
|
||||||
res = await generate_chat_completion(
|
res = await generate_chat_completion(
|
||||||
request,
|
request,
|
||||||
@ -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,
|
||||||
|
@ -195,7 +195,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if token.type === 'details'}
|
{: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">
|
<div class=" mb-1.5" slot="content">
|
||||||
<svelte:self id={`${id}-${tokenIdx}-d`} tokens={marked.lexer(token.text)} />
|
<svelte:self id={`${id}-${tokenIdx}-d`} tokens={marked.lexer(token.text)} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -248,8 +248,8 @@
|
|||||||
tags.set(await getAllTags(localStorage.token));
|
tags.set(await getAllTags(localStorage.token));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (type === 'execute:pyodide') {
|
if (type === 'execute:python') {
|
||||||
console.log('execute:pyodide', data);
|
console.log('execute:python', data);
|
||||||
executePythonAsWorker(data.id, data.code, cb);
|
executePythonAsWorker(data.id, data.code, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user