feat(cloud): manage LLM providers in database
Tests / Test passed: 664

This commit is contained in:
2026-07-14 00:31:47 +08:00
parent b613a315ff
commit a166ffd8a4
35 changed files with 2432 additions and 204 deletions
+17 -2
View File
@@ -46,10 +46,12 @@ class AnthropicToolCallingClient:
model: str,
transport: Any | None = None,
max_tokens: int = 1024,
api_key: str | None = None,
) -> None:
self.model = model
self._transport = transport
self.max_tokens = max_tokens
self._api_key = api_key
def decide(
self,
@@ -118,7 +120,11 @@ class AnthropicToolCallingClient:
except Exception as exc:
raise ToolCallUnavailable("anthropic SDK is unavailable") from exc
self._transport = anthropic.Anthropic()
self._transport = (
anthropic.Anthropic(api_key=self._api_key)
if self._api_key is not None
else anthropic.Anthropic()
)
return self._transport
@@ -129,10 +135,14 @@ class OpenAIToolCallingClient:
model: str,
transport: Any | None = None,
max_tokens: int = 1024,
api_key: str | None = None,
base_url: str | None = None,
) -> None:
self.model = model
self._transport = transport
self.max_tokens = max_tokens
self._api_key = api_key
self._base_url = base_url
def decide(
self,
@@ -193,7 +203,12 @@ class OpenAIToolCallingClient:
except Exception as exc:
raise ToolCallUnavailable("openai SDK is unavailable") from exc
self._transport = OpenAI()
kwargs: dict[str, str] = {}
if self._api_key is not None:
kwargs["api_key"] = self._api_key
if self._base_url is not None:
kwargs["base_url"] = self._base_url
self._transport = OpenAI(**kwargs)
return self._transport