fix: code review P0/P1 fixes — history param bug, llm dict access, WS ping

- Fix P0: _build_history_messages(conv.id, message_text) passed string as
  limit param causing TypeError at runtime — removed erroneous second arg
- Fix P0: llm.py /llm/models used attribute access on dict (model_config.max_tokens)
  causing AttributeError — changed to dict.get() access
- Fix P1: Portal WS ignored ping messages — added pong response handler
- Fix: composition.py f-string without placeholders
This commit is contained in:
chiguyong 2026-06-15 08:30:49 +08:00
parent 99fe4c99f7
commit 0c63d813dc
3 changed files with 9 additions and 5 deletions

View File

@ -30,9 +30,9 @@ async def list_models(req: Request):
"id": f"{provider_name}/{model_name}",
"provider": provider_name,
"model": model_name,
"max_tokens": model_config.max_tokens,
"cost_per_1k_input": model_config.cost_per_1k_input,
"cost_per_1k_output": model_config.cost_per_1k_output,
"max_tokens": model_config.get("max_tokens"),
"cost_per_1k_input": model_config.get("cost_per_1k_input"),
"cost_per_1k_output": model_config.get("cost_per_1k_output"),
})
aliases = config.model_aliases if config.model_aliases else {}

View File

@ -571,6 +571,10 @@ async def portal_websocket(websocket: WebSocket):
await websocket.send_json({"type": "result", "data": {"status": "cancelled"}})
return
if msg_type == "ping":
await websocket.send_json({"type": "pong"})
continue
if msg_type != "chat":
continue
@ -683,7 +687,7 @@ async def portal_websocket(websocket: WebSocket):
)
chat_messages.append({"role": "user", "content": message_text})
# Inject conversation history for context continuity
history_msgs = _build_history_messages(conv.id, message_text)
history_msgs = _build_history_messages(conv.id)
for hm in history_msgs:
chat_messages.insert(-1, hm)
response = await llm_gateway.chat(

View File

@ -223,7 +223,7 @@ class DynamicSelector(Tool):
prompt = (
f"Given the following input:\n{json.dumps(kwargs, ensure_ascii=False)}\n\n"
f"Available tools:\n" + "\n".join(tool_descriptions) + "\n\n"
f"Which tool number should be used? Reply with just the number."
"Which tool number should be used? Reply with just the number."
)
try: