♻️ refactor!: 重构LLM服务架构并统一Pydantic兼容性处理 (#2002)
检查bot是否运行正常 / bot check (push) Waiting to run
Sequential Lint and Type Check / ruff-call (push) Waiting to run
Sequential Lint and Type Check / pyright-call (push) Blocked by required conditions
Release Drafter / Update Release Draft (push) Waiting to run
Force Sync to Aliyun / sync (push) Waiting to run
Update Version / update-version (push) Waiting to run
CodeQL Code Security Analysis / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL Code Security Analysis / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled

* ♻️ refactor(pydantic): 提取 Pydantic 兼容函数到独立模块

* ♻️ refactor!(llm): 重构LLM服务,引入现代化工具和执行器架构

🏗️ **架构变更**
- 引入ToolProvider/ToolExecutable协议,取代ToolRegistry
- 新增LLMToolExecutor,分离工具调用逻辑
- 新增BaseMemory抽象,解耦会话状态管理

🔄 **API重构**
- 移除:analyze, analyze_multimodal, pipeline_chat
- 新增:generate_structured, run_with_tools
- 重构:chat, search, code变为无状态调用

🛠️ **工具系统**
- 新增@function_tool装饰器
- 统一工具定义到ToolExecutable协议
- 移除MCP工具系统和mcp_tools.json

---------

Co-authored-by: webjoin111 <455457521@qq.com>
This commit is contained in:
Rumio
2025-08-04 23:36:12 +08:00
committed by GitHub
co-authored by webjoin111
parent 59d72c3b3d
commit 7c153721f0
27 changed files with 1495 additions and 1795 deletions
+25 -4
View File
@@ -86,14 +86,23 @@ def _cache_model(cache_key: str, model: LLMModel):
def clear_model_cache():
"""清空模型缓存"""
"""
清空模型缓存,释放所有缓存的模型实例。
用于在内存不足或需要强制重新加载模型配置时清理缓存。
"""
global _model_cache
_model_cache.clear()
logger.info("已清空模型缓存")
def get_cache_stats() -> dict[str, Any]:
"""获取缓存统计信息"""
"""
获取模型缓存的统计信息。
返回:
dict[str, Any]: 包含缓存大小、最大容量、TTL和已缓存模型列表的统计信息。
"""
return {
"cache_size": len(_model_cache),
"max_cache_size": _max_cache_size,
@@ -169,7 +178,13 @@ def find_model_config(
def list_available_models() -> list[dict[str, Any]]:
"""列出所有配置的可用模型"""
"""
列出所有配置的可用模型及其详细信息。
返回:
list[dict[str, Any]]: 模型信息列表,每个字典包含提供商名称、模型名称、
能力信息、是否为嵌入模型等详细信息。
"""
providers = get_configured_providers()
model_list = []
for provider in providers:
@@ -215,7 +230,13 @@ def list_model_identifiers() -> dict[str, list[str]]:
def list_embedding_models() -> list[dict[str, Any]]:
"""列出所有配置的嵌入模型"""
"""
列出所有配置的嵌入模型。
返回:
list[dict[str, Any]]: 嵌入模型信息列表,从所有可用模型中筛选出
支持嵌入功能的模型。
"""
all_models = list_available_models()
return [model for model in all_models if model.get("is_embedding_model", False)]