Add quick LLM provider setup

This commit is contained in:
2026-07-07 13:12:27 +08:00
parent bcdf91c85d
commit dada4aafcd
5 changed files with 208 additions and 88 deletions

View File

@@ -138,11 +138,7 @@ def _call_anthropic_messages(model: ModelConfig, rag_result: RagResult) -> str:
_put_if_not_none(payload, "top_k", model.top_k)
payload.update(_load_extra_params(model.extra_params))
headers = {
"x-api-key": model.api_key,
"anthropic-version": model.api_version or "2023-06-01",
"Content-Type": "application/json",
}
headers = _anthropic_headers(model)
try:
response = httpx.post(
_resolve_anthropic_endpoint(model),
@@ -263,6 +259,19 @@ def _auth_headers(model: ModelConfig) -> dict[str, str]:
return headers
def _anthropic_headers(model: ModelConfig) -> dict[str, str]:
headers = {"Content-Type": "application/json"}
if model.auth_type == "bearer":
headers["Authorization"] = f"Bearer {model.api_key}"
else:
headers["x-api-key"] = model.api_key
if model.api_version:
headers["anthropic-version"] = model.api_version
elif model.provider == "anthropic":
headers["anthropic-version"] = "2023-06-01"
return headers
def _decimal_to_float(value: Any) -> float | None:
return float(value) if value is not None else None