mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
705d1aeaf2
commit
1fa3c55ac4
7 files changed
+46
-22
No files matched your search
+5
-11
@@ -505,12 +505,6 @@ _UTILITY_PATTERNS = [
|
||||
"tags_generation",
|
||||
]
|
||||
|
||||
_UTILITY_MODEL_CONFIG_KEYS = {
|
||||
"summary_generation": "chat.context_compaction.model",
|
||||
"title_generation": "chat.title_generation.model",
|
||||
}
|
||||
|
||||
|
||||
async def _intercept_task(
|
||||
request: Request,
|
||||
body: ChatCompletionRequest,
|
||||
@@ -700,11 +694,11 @@ async def _resolve_utility_model(request: Request, workspace: str, app_state=Non
|
||||
|
||||
candidates: list[str] = []
|
||||
task_header = request.headers.get(OWUI_TASK_HEADER, "").strip()
|
||||
preferred_config_key = _UTILITY_MODEL_CONFIG_KEYS.get(task_header)
|
||||
if preferred_config_key:
|
||||
preferred_model = await Config.get(preferred_config_key)
|
||||
if isinstance(preferred_model, str) and preferred_model.strip():
|
||||
candidates.append(preferred_model.strip())
|
||||
if task_header:
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
if preferred_model := await configured_utility_model(task_header):
|
||||
candidates.append(preferred_model)
|
||||
|
||||
gateway_model = await Config.get("gateway.model")
|
||||
if isinstance(gateway_model, str) and gateway_model.strip():
|
||||
|
||||
+5
-4
@@ -642,13 +642,14 @@ async def generate_commit_message(request: Request, body: CommitMessageRequest):
|
||||
if not patch:
|
||||
raise HTTPException(status_code=400, detail="No staged changes")
|
||||
|
||||
from cptr.models import Config
|
||||
|
||||
message_model = body.model_id.strip() if isinstance(body.model_id, str) else None
|
||||
if message_model is None:
|
||||
configured_model = await Config.get("git.commit_message_generation.model")
|
||||
message_model = configured_model.strip() if isinstance(configured_model, str) else None
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
message_model = await configured_utility_model("git_commit_message_generation")
|
||||
if not message_model:
|
||||
from cptr.models import Config
|
||||
|
||||
default_model = await Config.get("chat.default_model")
|
||||
message_model = default_model.strip() if isinstance(default_model, str) else None
|
||||
text = await generate_text(
|
||||
|
||||
@@ -763,7 +763,9 @@ async def review_tool_approval(
|
||||
args_text = json.dumps(arguments, ensure_ascii=False, default=str)
|
||||
if len(args_text) > 4000:
|
||||
args_text = args_text[:3500] + "\n...(truncated)"
|
||||
configured_model = await Config.get("tool_approval.review.model")
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
configured_model = await configured_utility_model("tool_approval_review")
|
||||
logger.info(
|
||||
"[tool-approval] auto review start tool=%s policy=%s active_model=%s review_model=%s args=%s",
|
||||
tool_name,
|
||||
@@ -828,9 +830,11 @@ async def generate_chat_title(
|
||||
truncated += "..."
|
||||
|
||||
try:
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
parsed = await generate_json(
|
||||
None,
|
||||
model_id=await Config.get("chat.title_generation.model"),
|
||||
model_id=await configured_utility_model("title_generation"),
|
||||
active_connection=connection,
|
||||
active_model=model,
|
||||
messages=[{"role": "user", "content": truncated}],
|
||||
|
||||
@@ -1652,13 +1652,14 @@ async def run_memory_review(
|
||||
) -> None:
|
||||
try:
|
||||
from cptr.utils.ai import generate_json
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
memory_state = await read_memory_state(request, user_id, workspace)
|
||||
transcript = summarize_recent_conversation(conversation_messages, assistant_reply)
|
||||
prompt = build_memory_review_prompt(memory_state, workspace, transcript)
|
||||
parsed = await generate_json(
|
||||
None,
|
||||
model_id=await Config.get("memory.background_review.model"),
|
||||
model_id=await configured_utility_model("memory_background_review"),
|
||||
active_connection=model_connection,
|
||||
active_model=model,
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
|
||||
@@ -799,9 +799,9 @@ async def run_skill_review(
|
||||
skill_create_requested: bool,
|
||||
) -> None:
|
||||
try:
|
||||
from cptr.models import Config
|
||||
from cptr.utils.ai import generate_json
|
||||
from cptr.utils.memory import summarize_recent_conversation
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
skills = discover_skills(workspace)
|
||||
transcript = summarize_recent_conversation(conversation_messages, assistant_reply)
|
||||
@@ -844,7 +844,7 @@ async def run_skill_review(
|
||||
)
|
||||
parsed = await generate_json(
|
||||
None,
|
||||
model_id=await Config.get("skills.background_review.model"),
|
||||
model_id=await configured_utility_model("skills_background_review"),
|
||||
active_connection=model_connection,
|
||||
active_model=model,
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
|
||||
@@ -63,12 +63,12 @@ async def summarize_messages(
|
||||
text = text[:15_000] + "\n...\n" + text[-10_000:]
|
||||
|
||||
try:
|
||||
from cptr.models import Config
|
||||
from cptr.utils.ai import generate_text
|
||||
from cptr.utils.utility_models import configured_utility_model
|
||||
|
||||
result = await generate_text(
|
||||
None,
|
||||
model_id=await Config.get("chat.context_compaction.model"),
|
||||
model_id=await configured_utility_model("summary_generation"),
|
||||
active_connection=connection,
|
||||
active_model=model,
|
||||
messages=[{"role": "user", "content": text}],
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Computer utility task model configuration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
UTILITY_MODEL_CONFIG_KEYS: dict[str, str] = {
|
||||
"title_generation": "chat.title_generation.model",
|
||||
"summary_generation": "chat.context_compaction.model",
|
||||
"tool_approval_review": "tool_approval.review.model",
|
||||
"memory_background_review": "memory.background_review.model",
|
||||
"skills_background_review": "skills.background_review.model",
|
||||
"git_commit_message_generation": "git.commit_message_generation.model",
|
||||
}
|
||||
|
||||
|
||||
async def configured_utility_model(task: str) -> str | None:
|
||||
"""Return the configured model id for a Computer utility task, if set."""
|
||||
key = UTILITY_MODEL_CONFIG_KEYS.get(task)
|
||||
if not key:
|
||||
return None
|
||||
|
||||
from cptr.models import Config
|
||||
|
||||
value = await Config.get(key)
|
||||
return value.strip() if isinstance(value, str) and value.strip() else None
|
||||
Reference in new issue
Block a user