mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-10 06:10:01 +08:00
♻️ refactor(core): 重构 AI 编排框架与记忆及 RAG 子系统 (#2149)
* ♻️ refactor(core): 重构 AI 编排框架与记忆及 RAG 子系统 - 【重构】重构 `BaseRunnable` 并引入统一的 `RunIntent` 意图载体,规范 Agent、Team 和 Workflow 的执行流 - 【解耦】将中期记忆槽和长期向量记忆从 `MemoryConfig` 中解耦,转为独立的能力组件与工具箱进行管理 - 【记忆】移除 `MemoryReader` 和 `MemoryWriter`,统一封装为 `SessionMemoryContext` 会话记忆门面 - 【RAG】重构检索器与存储后端接口,统一采用 `QueryRequest` 进行多维度联合检索,并引入 `InMemoryScorer` 提升打分性能 - 【事件】优化 `EventBus` 异步事件分发机制,引入队列机制确保事件按序处理,避免并发竞态问题 - 【依赖注入】移除 `memory` 注入项,优化 `DependencyInjector` 的签名解析缓存以提升性能 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
webjoin111
pre-commit-ci[bot]
parent
922d092650
commit
52f7dbdedf
@@ -2,13 +2,18 @@
|
||||
LLM 生成配置相关类和函数
|
||||
"""
|
||||
|
||||
from typing import Any, Literal
|
||||
import inspect
|
||||
from typing import Any, Literal, cast
|
||||
from typing_extensions import Self
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.services.ai.config import get_gemini_safety_threshold
|
||||
from zhenxun.services.ai.core.exceptions import ConfigurationException
|
||||
from zhenxun.services.ai.core.options import (
|
||||
GenerationConfig,
|
||||
ResponseFormat,
|
||||
StructuredOutputStrategy,
|
||||
)
|
||||
from zhenxun.services.ai.utils.logger import log_llm as logger
|
||||
from zhenxun.utils.pydantic_compat import model_json_schema, model_validate
|
||||
@@ -94,20 +99,12 @@ class IntentBuilder:
|
||||
强制要求结构化输出意图。
|
||||
支持自动处理 Pydantic 模型并转换为厂商所需的 JSON Schema。
|
||||
"""
|
||||
import inspect
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.services.ai.core.options import StructuredOutputStrategy
|
||||
|
||||
self._config.output.response_format = ResponseFormat.JSON
|
||||
self._config.output.response_mime_type = "application/json"
|
||||
if schema:
|
||||
if inspect.isclass(schema) and issubclass(schema, BaseModel):
|
||||
self._config.output.response_schema = model_json_schema(schema)
|
||||
else:
|
||||
from typing import cast
|
||||
|
||||
self._config.output.response_schema = cast(dict[str, Any], schema)
|
||||
if strict:
|
||||
self._config.output.structured_output_strategy = (
|
||||
@@ -137,8 +134,6 @@ class IntentBuilder:
|
||||
安全合规意图。
|
||||
level 取值: 'strict' (最严格), 'moderate' (中等), 'none' (完全无限制)。
|
||||
"""
|
||||
from zhenxun.services.ai.config import get_gemini_safety_threshold
|
||||
|
||||
if level == "strict":
|
||||
self.gemini.set_safety_threshold("BLOCK_LOW_AND_ABOVE")
|
||||
elif level == "none":
|
||||
|
||||
Reference in New Issue
Block a user