feat: 公司支持多模型提供商与会话消歧选型

This commit is contained in:
2026-09-20 16:35:06 +08:00
parent d7e4a987c1
commit 9350323ff2
30 changed files with 1031 additions and 448 deletions
+3 -1
View File
@@ -58,7 +58,8 @@ class Session:
title: str = "新对话"
status: SessionStatus = SessionStatus.ACTIVE
summary: str | None = None
# 会话选用的模型 id;空则对话时回落公司默认
# 会话选用的提供商 + 模型(同名 model 靠 provider 消歧)
llm_provider_id: int | None = None
llm_model: str | None = None
created_at: datetime = field(default_factory=datetime.utcnow)
updated_at: datetime = field(default_factory=datetime.utcnow)
@@ -105,6 +106,7 @@ class LlmRuntimeConfig:
base_url: str
api_key: str
model: str
provider_id: int | None = None
extra_headers: dict[str, str] = field(default_factory=dict)
# 租户配置的上下文窗口;None 表示由 Agent 按模型名估计
context_window: int | None = None
+10 -5
View File
@@ -64,7 +64,10 @@ class MemoryRepository(ABC):
class LlmRuntimeCache(ABC):
@abstractmethod
async def get(
self, company_id: int, model: str | None = None
self,
company_id: int,
provider_id: int | None = None,
model: str | None = None,
) -> LlmRuntimeConfig | None: ...
@abstractmethod
@@ -73,11 +76,10 @@ class LlmRuntimeCache(ABC):
company_id: int,
config: LlmRuntimeConfig,
ttl_seconds: int,
model: str | None = None,
) -> None: ...
@abstractmethod
async def delete(self, company_id: int, model: str | None = None) -> None: ...
async def delete(self, company_id: int) -> None: ...
class LlmRuntimeGateway(ABC):
@@ -85,7 +87,10 @@ class LlmRuntimeGateway(ABC):
@abstractmethod
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: ...
@@ -101,5 +106,5 @@ class ChatStreamer(ABC):
user_text: str,
system_prompt: str,
tools: list[Any] | None = None,
max_tool_result_chars: int = 8000,
max_tool_result_chars: int = 4000,
) -> AsyncIterator[StreamEvent]: ...