Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Provider-qualified model references and OpenAI-compatible clients."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from scripts.provider_router import (
|
||||
ModelReference,
|
||||
parse_model_reference,
|
||||
provider_configs,
|
||||
resolve_model_route,
|
||||
)
|
||||
|
||||
|
||||
def provider_label(provider: str) -> str:
|
||||
return provider_configs()[provider].label
|
||||
|
||||
|
||||
def chat_completion_options(reference: ModelReference) -> dict:
|
||||
"""Provider/model-specific options needed for usable final-answer output."""
|
||||
if (
|
||||
reference.provider == "siliconflow"
|
||||
and reference.model_id.startswith("Qwen/Qwen3.5-")
|
||||
):
|
||||
return {"extra_body": {"enable_thinking": False}}
|
||||
return {}
|
||||
|
||||
|
||||
def client_for(reference: ModelReference, *, timeout: float | None = None):
|
||||
"""Create a provider-specific client, or return ``None`` if its key is absent."""
|
||||
|
||||
route = resolve_model_route(reference, require_credentials=False)
|
||||
if route is None:
|
||||
return None
|
||||
# Keep cached-profile rebuilds independent from the optional live-pipeline
|
||||
# dependency. The import is only needed when an actual request is possible.
|
||||
import openai
|
||||
|
||||
kwargs = {
|
||||
"base_url": route.url.removesuffix("/chat/completions").rstrip("/"),
|
||||
"api_key": route.api_key,
|
||||
"max_retries": 0,
|
||||
}
|
||||
if timeout is not None:
|
||||
kwargs["timeout"] = timeout
|
||||
return openai.OpenAI(**kwargs)
|
||||
Reference in New Issue
Block a user