mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:49:19 +08:00
feat: 公司支持多模型提供商与会话消歧选型
This commit is contained in:
@@ -14,17 +14,22 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ServerLlmRuntimeGateway(LlmRuntimeGateway):
|
||||
"""GET /api/internal/agent/llm-runtime?companyId=&model=(Agent Bearer)。"""
|
||||
"""GET /api/internal/agent/llm-runtime?companyId=&providerId=&model=。"""
|
||||
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
self._settings = settings
|
||||
|
||||
async def fetch(
|
||||
self, company_id: int, model: str | None = None
|
||||
self,
|
||||
company_id: int,
|
||||
provider_id: int | None = None,
|
||||
model: str | None = None,
|
||||
) -> LlmRuntimeConfig | None:
|
||||
url = f"{self._settings.server_base_url.rstrip('/')}/api/internal/agent/llm-runtime"
|
||||
headers = {"Authorization": f"Bearer {self._settings.mcp_bearer_token}"}
|
||||
params: dict[str, str | int] = {"companyId": company_id}
|
||||
if provider_id is not None:
|
||||
params["providerId"] = provider_id
|
||||
if model:
|
||||
params["model"] = model
|
||||
try:
|
||||
@@ -37,10 +42,12 @@ class ServerLlmRuntimeGateway(LlmRuntimeGateway):
|
||||
data = body.get("data") if isinstance(body, dict) else None
|
||||
if not isinstance(data, dict):
|
||||
return None
|
||||
pid = data.get("providerId")
|
||||
return LlmRuntimeConfig(
|
||||
base_url=str(data.get("baseUrl") or "").rstrip("/"),
|
||||
api_key=str(data.get("apiKey") or ""),
|
||||
model=str(data.get("model") or ""),
|
||||
provider_id=int(pid) if pid is not None else provider_id,
|
||||
extra_headers={
|
||||
str(k): str(v)
|
||||
for k, v in (data.get("extraHeaders") or {}).items()
|
||||
@@ -49,8 +56,9 @@ class ServerLlmRuntimeGateway(LlmRuntimeGateway):
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"拉取 Server LLM runtime 失败 company_id=%s model=%s",
|
||||
"拉取 Server LLM runtime 失败 company_id=%s provider_id=%s model=%s",
|
||||
company_id,
|
||||
provider_id,
|
||||
model,
|
||||
)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user