[Refractor] refract chat: 重构了当前算法chat部分的内容#22
Open
chenhao0205 wants to merge 15 commits intoLazyAGI:mainfrom
Open
[Refractor] refract chat: 重构了当前算法chat部分的内容#22chenhao0205 wants to merge 15 commits intoLazyAGI:mainfrom
chenhao0205 wants to merge 15 commits intoLazyAGI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request modularizes the chat application by restructuring API routes, core services, and RAG pipelines, and introduces a centralized configuration system. The review identified several critical issues, including blocking I/O in an asynchronous health check, a syntax error in module exports due to a missing comma, and incorrect import paths for configuration files. Furthermore, a path traversal vulnerability was found in the file validation logic, and improvements were suggested to prevent temporary file leaks and replace inefficient polling in streaming responses with more robust asynchronous patterns.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ea3485d to
080929f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更概述
本次PR对LazyRAG的chat模块进行了全面的架构重构,将原有的扁平化结构改造为更清晰的分层组件化设计。
主要改动
1. 目录结构重组
新增
app/目录: 包含FastAPI应用入口、路由定义和服务核心逻辑api/: 路由层 (chat_routes.py,health_routes.py)core/: 服务核心 (chat_server.py,chat_service.py)chat.py: 精简为服务启动入口新增
components/目录: 按功能域划分的组件层generate/: 生成相关组件(结果聚合、提示词格式化、输出解析)process/: 处理组件(自适应topk选择、敏感词过滤、多轮查询改写、上下文扩展)tools/: 工具组件(SQL工具、工具注册)tmp/: 临时/本地模型组件新增
pipelines/目录: 核心流水线定义builders/: Pipeline构建器(模型获取、搜索pipeline、生成pipeline)agentic.py/naive.py: 两种RAG模式实现新增
utils/目录: 工具层统一封装schema.py: 数据模型定义(合并原message.py)config.py: 配置管理helpers.py: 辅助函数2. 关键优化
get_automodel(),支持配置驱动和流式包装ContextExpansionComponent,支持检索结果上下文增强chat.py(旧)、modules/目录、chat_pipelines/目录目录结构重构对比
chat/ ├── chat.py ├── chat_pipelines/ │ ├── agentic.py │ ├── naive.py │ └── configs/ │ └── auto_model.yaml ├── data/ │ └── sensitive_words.txt ├── modules/ │ ├── algo/ │ │ ├── adaptive_topk.py │ │ ├── multiturn_query_rewriter.py │ │ └── prompt_formatter.py │ └── engineering/ │ ├── aggregate.py │ ├── load_model.py │ ├── output_parser.py │ ├── sensitive_filter.py │ ├── simple_llm.py │ ├── tool_registry.py │ └── workflow_utils.py ├── prompts/ │ └── agentic.py ├── tools/ │ └── sql.py └── utils/ ├── message.py ├── stream_scanner.py └── url.py