mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 03:18:23 -05:00
refac
This commit is contained in:
@@ -2551,22 +2551,21 @@ async def process_chat_response(
|
|||||||
See: https://openresponses.org/specification
|
See: https://openresponses.org/specification
|
||||||
"""
|
"""
|
||||||
output_items = []
|
output_items = []
|
||||||
item_counter = 0
|
|
||||||
|
|
||||||
def next_id(prefix):
|
def next_id(prefix):
|
||||||
nonlocal item_counter
|
return f"{prefix}_{uuid4().hex[:24]}"
|
||||||
item_counter += 1
|
|
||||||
return f"{prefix}_{item_counter}"
|
|
||||||
|
|
||||||
for block in content_blocks:
|
for block in content_blocks:
|
||||||
block_type = block.get("type", "")
|
block_type = block.get("type", "")
|
||||||
|
# Use backend-provided ID if available, fallback to generated
|
||||||
|
block_id = block.get("id")
|
||||||
|
|
||||||
if block_type == "text":
|
if block_type == "text":
|
||||||
text_content = block.get("content", "").strip()
|
text_content = block.get("content", "").strip()
|
||||||
if text_content:
|
if text_content:
|
||||||
output_items.append({
|
output_items.append({
|
||||||
"type": "message",
|
"type": "message",
|
||||||
"id": next_id("msg"),
|
"id": block_id or next_id("msg"),
|
||||||
"status": "completed",
|
"status": "completed",
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": [{"type": "output_text", "text": text_content}],
|
"content": [{"type": "output_text", "text": text_content}],
|
||||||
@@ -2582,7 +2581,7 @@ async def process_chat_response(
|
|||||||
func = tool_call.get("function", {})
|
func = tool_call.get("function", {})
|
||||||
output_items.append({
|
output_items.append({
|
||||||
"type": "function_call",
|
"type": "function_call",
|
||||||
"id": next_id("fc"),
|
"id": call_id or next_id("fc"), # Use call_id as item id if available
|
||||||
"call_id": call_id,
|
"call_id": call_id,
|
||||||
"name": func.get("name", ""),
|
"name": func.get("name", ""),
|
||||||
"arguments": func.get("arguments", "{}"),
|
"arguments": func.get("arguments", "{}"),
|
||||||
@@ -2593,7 +2592,7 @@ async def process_chat_response(
|
|||||||
for result in results:
|
for result in results:
|
||||||
output_items.append({
|
output_items.append({
|
||||||
"type": "function_call_output",
|
"type": "function_call_output",
|
||||||
"id": next_id("fco"),
|
"id": result.get("id") or next_id("fco"),
|
||||||
"call_id": result.get("tool_call_id", ""),
|
"call_id": result.get("tool_call_id", ""),
|
||||||
"output": [{"type": "input_text", "text": result.get("content", "")}],
|
"output": [{"type": "input_text", "text": result.get("content", "")}],
|
||||||
"status": "completed",
|
"status": "completed",
|
||||||
@@ -2606,7 +2605,7 @@ async def process_chat_response(
|
|||||||
duration = block.get("duration")
|
duration = block.get("duration")
|
||||||
output_items.append({
|
output_items.append({
|
||||||
"type": "reasoning",
|
"type": "reasoning",
|
||||||
"id": next_id("r"),
|
"id": block_id or next_id("r"),
|
||||||
"status": "completed" if duration is not None else "in_progress",
|
"status": "completed" if duration is not None else "in_progress",
|
||||||
"content": [{"type": "output_text", "text": reasoning_content}] if reasoning_content else None,
|
"content": [{"type": "output_text", "text": reasoning_content}] if reasoning_content else None,
|
||||||
"summary": None,
|
"summary": None,
|
||||||
@@ -2618,7 +2617,7 @@ async def process_chat_response(
|
|||||||
attrs = block.get("attributes", {})
|
attrs = block.get("attributes", {})
|
||||||
output_items.append({
|
output_items.append({
|
||||||
"type": "open_webui:code_interpreter",
|
"type": "open_webui:code_interpreter",
|
||||||
"id": next_id("ci"),
|
"id": block_id or next_id("ci"),
|
||||||
"status": "completed" if output_val is not None else "in_progress",
|
"status": "completed" if output_val is not None else "in_progress",
|
||||||
"lang": attrs.get("lang", ""),
|
"lang": attrs.get("lang", ""),
|
||||||
"code": code,
|
"code": code,
|
||||||
|
|||||||
Reference in New Issue
Block a user