mirror of
https://github.com/open-webui/computer.git
synced 2026-12-01 09:22:45 -05:00
refac
This commit is contained in:
1 parent
288223204d
commit
22b29c6358
34 files changed
+2325
-1360
No files matched your search
+20
-7
@@ -72,6 +72,7 @@ from cptr.utils.agents.events import (
|
||||
)
|
||||
from cptr.utils.agents.attachments import prepare_agent_attachments
|
||||
from cptr.utils.model_targets import AgentModelTarget, ApiModelTarget, ModelTarget
|
||||
from cptr.utils.identity import identity_for_context
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -364,6 +365,8 @@ def get_pending_input_lock(chat_id: str) -> asyncio.Lock:
|
||||
|
||||
|
||||
def start_task(
|
||||
request,
|
||||
*,
|
||||
message_id: str,
|
||||
chat_id: str,
|
||||
user_id: str,
|
||||
@@ -386,13 +389,14 @@ def start_task(
|
||||
)
|
||||
task = asyncio.create_task(
|
||||
run_chat_task(
|
||||
message_id,
|
||||
chat_id,
|
||||
user_id,
|
||||
target,
|
||||
workspace,
|
||||
regeneration_prompt,
|
||||
output_queue,
|
||||
request,
|
||||
message_id=message_id,
|
||||
chat_id=chat_id,
|
||||
user_id=user_id,
|
||||
target=target,
|
||||
workspace=workspace,
|
||||
regeneration_prompt=regeneration_prompt,
|
||||
output_queue=output_queue,
|
||||
)
|
||||
)
|
||||
_tasks[message_id] = task
|
||||
@@ -641,6 +645,7 @@ async def process_pending_chat_inputs(chat_id: str, user_id: str, workspace: str
|
||||
|
||||
# Start new task and continue draining other ready branch batches.
|
||||
start_task(
|
||||
None,
|
||||
message_id=assistant_msg.id,
|
||||
chat_id=chat_id,
|
||||
user_id=user_id,
|
||||
@@ -765,6 +770,7 @@ async def review_tool_approval(
|
||||
args_text[:1000],
|
||||
)
|
||||
parsed = await generate_json(
|
||||
None,
|
||||
model_id=configured_model,
|
||||
active_connection=connection,
|
||||
active_model=model,
|
||||
@@ -820,6 +826,7 @@ async def generate_chat_title(
|
||||
|
||||
try:
|
||||
parsed = await generate_json(
|
||||
None,
|
||||
model_id=await Config.get("chat.title_generation.model"),
|
||||
active_connection=connection,
|
||||
active_model=model,
|
||||
@@ -1382,6 +1389,8 @@ def _default_base_url(provider: str) -> str:
|
||||
|
||||
|
||||
async def run_chat_task(
|
||||
request,
|
||||
*,
|
||||
message_id: str,
|
||||
chat_id: str,
|
||||
user_id: str,
|
||||
@@ -1545,6 +1554,7 @@ async def run_chat_task(
|
||||
from cptr.utils.agents.pi import run_pi_agent
|
||||
|
||||
chat_obj = await Chat.get_by_id(chat_id)
|
||||
identity = await identity_for_context({"request": request, "user_id": user_id})
|
||||
chat_params = (chat_obj.meta or {}).get("params", {}) if chat_obj else {}
|
||||
agent_workspace = workspace or str(Path.home())
|
||||
messages, loaded_summary = await _load_message_history(chat_id, message_id)
|
||||
@@ -1576,6 +1586,7 @@ async def run_chat_task(
|
||||
current_user_files = meta_files
|
||||
agent_attachments = await prepare_agent_attachments(
|
||||
workspace=agent_workspace,
|
||||
user_id=user_id,
|
||||
chat_id=chat_id,
|
||||
message_id=(msg.parent_id if msg and msg.parent_id else message_id),
|
||||
files=current_user_files,
|
||||
@@ -1637,6 +1648,7 @@ async def run_chat_task(
|
||||
chat_params=chat_params,
|
||||
resume_state=resume_state,
|
||||
attachments=agent_attachments,
|
||||
identity=identity,
|
||||
):
|
||||
if isinstance(event, AgentTextDelta):
|
||||
await _finish_reasoning_item()
|
||||
@@ -2085,6 +2097,7 @@ async def run_chat_task(
|
||||
tool_ctx = {
|
||||
"workspace": workspace,
|
||||
"user_id": user_id,
|
||||
"request": request,
|
||||
"model_id": model,
|
||||
"full_model_id": ((chat_obj.meta or {}).get("last_model") if chat_obj else None)
|
||||
or model,
|
||||
|
||||
Reference in new issue
Block a user