mirror of
https://github.com/open-webui/computer.git
synced 2026-11-24 06:20:21 -05:00
refac
This commit is contained in:
1 parent
867c0eadad
commit
3f50e3c7e9
2 files changed
+48
-21
No files matched your search
@@ -35,7 +35,9 @@ def _prompt_from_messages(messages: list[dict[str, Any]]) -> str:
|
||||
return "\n\n".join(parts)
|
||||
|
||||
|
||||
def _claude_query_input(prompt: str, attachments: PreparedAgentAttachments) -> Any:
|
||||
def _claude_query_input(
|
||||
prompt: str, attachments: PreparedAgentAttachments
|
||||
) -> str | AsyncIterator[dict[str, Any]]:
|
||||
if not attachments.images:
|
||||
return prompt
|
||||
content: list[dict[str, Any]] = []
|
||||
@@ -52,7 +54,15 @@ def _claude_query_input(prompt: str, attachments: PreparedAgentAttachments) -> A
|
||||
},
|
||||
}
|
||||
)
|
||||
return content
|
||||
|
||||
async def messages() -> AsyncIterator[dict[str, Any]]:
|
||||
yield {
|
||||
"type": "user",
|
||||
"message": {"role": "user", "content": content},
|
||||
"parent_tool_use_id": None,
|
||||
}
|
||||
|
||||
return messages()
|
||||
|
||||
|
||||
def _chat_approval_mode(chat_params: dict[str, Any]) -> str:
|
||||
|
||||
+36
-19
@@ -1521,21 +1521,22 @@ async def run_chat_task(
|
||||
runner = runners.get(agent_target.agent)
|
||||
if runner is None:
|
||||
raise RuntimeError(f"Unsupported agent type: {agent_target.agent}")
|
||||
reasoning_buffer = ""
|
||||
reasoning_item_id = f"reasoning-{message_id}"
|
||||
|
||||
def _active_reasoning_item():
|
||||
return next(
|
||||
(
|
||||
item
|
||||
for item in reversed(output_items)
|
||||
if item.get("type") == "reasoning" and item.get("status") == "in_progress"
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
async def _finish_reasoning_item():
|
||||
existing = next(
|
||||
(item for item in output_items if item.get("id") == reasoning_item_id), None
|
||||
)
|
||||
if not existing or existing.get("status") == "completed":
|
||||
existing = _active_reasoning_item()
|
||||
if not existing:
|
||||
return
|
||||
item = {
|
||||
"type": "reasoning",
|
||||
"id": reasoning_item_id,
|
||||
"status": "completed",
|
||||
"content": [{"type": "reasoning_text", "text": reasoning_buffer}],
|
||||
}
|
||||
item = {**existing, "status": "completed"}
|
||||
_upsert_output_item(output_items, item)
|
||||
await emit(output=item)
|
||||
_sync_state()
|
||||
@@ -1557,13 +1558,29 @@ async def run_chat_task(
|
||||
await emit(delta=event.text)
|
||||
_sync_state()
|
||||
elif isinstance(event, AgentReasoningDelta):
|
||||
reasoning_buffer += event.text
|
||||
item = {
|
||||
"type": "reasoning",
|
||||
"id": reasoning_item_id,
|
||||
"status": "in_progress",
|
||||
"content": [{"type": "reasoning_text", "text": reasoning_buffer}],
|
||||
}
|
||||
existing = _active_reasoning_item()
|
||||
if existing:
|
||||
blocks = existing.get("content") or []
|
||||
text = next(
|
||||
(
|
||||
block.get("text", "")
|
||||
for block in blocks
|
||||
if isinstance(block, dict) and block.get("type") == "reasoning_text"
|
||||
),
|
||||
"",
|
||||
)
|
||||
item = {
|
||||
**existing,
|
||||
"content": [{"type": "reasoning_text", "text": f"{text}{event.text}"}],
|
||||
}
|
||||
else:
|
||||
section = sum(item.get("type") == "reasoning" for item in output_items) + 1
|
||||
item = {
|
||||
"type": "reasoning",
|
||||
"id": f"reasoning-{message_id}-{section}",
|
||||
"status": "in_progress",
|
||||
"content": [{"type": "reasoning_text", "text": event.text}],
|
||||
}
|
||||
_upsert_output_item(output_items, item)
|
||||
await emit(output=item)
|
||||
_sync_state()
|
||||
|
||||
Reference in new issue
Block a user