mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
refac
This commit is contained in:
@@ -148,19 +148,22 @@ def convert_output_to_messages(output: list, raw: bool = False) -> list[dict]:
|
||||
messages = []
|
||||
pending_tool_calls = []
|
||||
pending_content = []
|
||||
pending_reasoning = ''
|
||||
|
||||
def flush_pending():
|
||||
nonlocal pending_content, pending_tool_calls
|
||||
if pending_content or pending_tool_calls:
|
||||
nonlocal pending_content, pending_tool_calls, pending_reasoning
|
||||
if pending_content or pending_tool_calls or pending_reasoning:
|
||||
messages.append(
|
||||
{
|
||||
'role': 'assistant',
|
||||
'content': '\n'.join(pending_content) if pending_content else '',
|
||||
**({'tool_calls': pending_tool_calls} if pending_tool_calls else {}),
|
||||
**({'reasoning_content': pending_reasoning} if pending_reasoning else {}),
|
||||
}
|
||||
)
|
||||
pending_content = []
|
||||
pending_tool_calls = []
|
||||
pending_reasoning = ''
|
||||
|
||||
for item in output:
|
||||
item_type = item.get('type', '')
|
||||
@@ -245,6 +248,10 @@ def convert_output_to_messages(output: list, raw: bool = False) -> list[dict]:
|
||||
start_tag = item.get('start_tag', '<think>')
|
||||
end_tag = item.get('end_tag', '</think>')
|
||||
pending_content.append(f'{start_tag}{reasoning_text}{end_tag}')
|
||||
# Preserve raw reasoning text as reasoning_content for
|
||||
# providers that require it on assistant tool-call messages
|
||||
# (e.g. Moonshot/Kimi K2.5).
|
||||
pending_reasoning += reasoning_text
|
||||
# else: skip reasoning blocks for normal LLM messages
|
||||
|
||||
elif item_type == 'open_webui:code_interpreter':
|
||||
|
||||
Reference in New Issue
Block a user