List validated chat model providers
This commit is contained in:
+20
-3
@@ -18,6 +18,14 @@ class OpenAICompatError(RuntimeError):
|
||||
"""Raised when the local OpenAI-compatible backend returns an invalid response."""
|
||||
|
||||
|
||||
PROVIDER_MIN_TEMPERATURES = {
|
||||
# 实测这些 provider 会拒绝 temperature=0;这里做最小值兜底,
|
||||
# 保持默认确定性取向的同时避免模型切换后请求直接 400。
|
||||
'minimax': 0.01,
|
||||
'wenxin': 0.1,
|
||||
}
|
||||
|
||||
|
||||
def _join_url(base_url: str, suffix: str) -> str:
|
||||
base = base_url.rstrip('/')
|
||||
return f'{base}/{suffix.lstrip("/")}'
|
||||
@@ -88,6 +96,14 @@ def _optional_int(value: Any) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def _temperature_for_model(model: str, configured: float) -> float:
|
||||
provider = model.split('/', 1)[0].strip().lower() if '/' in model else ''
|
||||
minimum = PROVIDER_MIN_TEMPERATURES.get(provider)
|
||||
if minimum is None:
|
||||
return configured
|
||||
return max(configured, minimum)
|
||||
|
||||
|
||||
def _parse_usage(payload: Any) -> UsageStats:
|
||||
if not isinstance(payload, dict):
|
||||
return UsageStats()
|
||||
@@ -258,11 +274,12 @@ class OpenAICompatClient:
|
||||
payload: dict[str, Any] = {
|
||||
'model': self.config.model,
|
||||
'messages': messages,
|
||||
'tools': tools,
|
||||
'tool_choice': 'auto',
|
||||
'temperature': self.config.temperature,
|
||||
'temperature': _temperature_for_model(self.config.model, self.config.temperature),
|
||||
'stream': stream,
|
||||
}
|
||||
if tools:
|
||||
payload['tools'] = tools
|
||||
payload['tool_choice'] = 'auto'
|
||||
if stream:
|
||||
payload['stream_options'] = {'include_usage': True}
|
||||
response_format = _build_response_format(output_schema)
|
||||
|
||||
Reference in New Issue
Block a user