refactor: streamline model provider resolution in chat start handler

This commit is contained in:
Dhaval
2026-04-02 12:53:57 +05:30
committed by Nathan Esquenazi
parent 669412cbc9
commit d9293c6097

View File

@@ -685,29 +685,21 @@ def _handle_chat_start(handler, body):
model_cfg = cfg.get('model', {}) model_cfg = cfg.get('model', {})
base_url = model_cfg.get('base_url', '') base_url = model_cfg.get('base_url', '')
# If a model is selected that matches our custom endpoint, use that base_url AND local provider # Use resolve_model_provider to get the correct model, provider, and base_url
if base_url and model: # This handles all providers including local Ollama/LM Studio endpoints
# Check if the model name contains "qwen" (your local model) from api.config import resolve_model_provider
if 'qwen' in model.lower(): resolved_model, resolved_provider, resolved_base_url = resolve_model_provider(model)
# Use the local endpoint with "local" provider
if base_url.endswith('/v1'):
effective_base_url = base_url[:-3]
else:
effective_base_url = base_url + '/v1'
effective_provider = 'custom'
print(f"DEBUG: Using custom base_url for {model}: {effective_base_url}", file=sys.stderr)
stream_id = uuid.uuid4().hex stream_id = uuid.uuid4().hex
q = queue.Queue() q = queue.Queue()
with STREAMS_LOCK: STREAMS[stream_id] = q with STREAMS_LOCK: STREAMS[stream_id] = q
kwargs = {} kwargs = {}
if 'effective_base_url' in locals(): # Pass resolved provider and base_url to the streaming handler
kwargs['base_url'] = effective_base_url kwargs['provider'] = resolved_provider
if 'effective_provider' in locals(): kwargs['base_url'] = resolved_base_url
kwargs['provider'] = effective_provider
thr = threading.Thread( thr = threading.Thread(
target=_run_agent_streaming, target=_run_agent_streaming,
args=(s.session_id, msg, model, workspace, stream_id, attachments), args=(s.session_id, msg, resolved_model, workspace, stream_id, attachments),
kwargs=kwargs, kwargs=kwargs,
daemon=True, daemon=True,
) )