多模态智能助手系统技术文档
1. 系统概述
本系统是一个基于LangChain框架构建的多模态智能助手,结合了通义千问大语言模型和视觉理解模型,能够处理文本、图像等多种类型的信息。系统具有以下核心功能:
- 数据库查询功能:通过自然语言查询SQLite数据库中的信息
- 天气查询功能:获取指定城市的实时天气信息
- 图像识别功能:对图像内容进行识别和分析
2. 系统架构
2.1 主要组件
-
Agent代理模块 ([dashscope_ocr.py](file:///Users/laraveljun/big_model/langchain-learn/dashscope_ocr.py))
- 使用
ChatTongyi模型作为核心推理引擎 - 集成多种工具(天气查询、数据库查询等)
- 动态路由中间件,根据输入内容类型选择合适的模型处理
- 使用
-
动态路由中间件
- 根据输入内容决定使用哪种模型处理
- 对于包含图像的内容,使用视觉模型([qwen3-vl-flash](file:///Users/laraveljun/big_model/langchain-learn/dashscope2.py#L11-L11))处理
- 对于纯文本内容,使用常规语言模型([qwen-turbo](file:///Users/laraveljun/big_model/langchain-learn/dashscope2.py#L10-L10))处理
-
工具模块
- 天气查询工具 ([func_tool/weather.py](file:///Users/laraveljun/big_model/langchain-learn/func_tool/weather.py)):提供城市天气查询功能
- 数据库工具 ([func_tool/db_tools.py](file:///Users/laraveljun/big_model/langchain-learn/func_tool/db_tools.py)):提供数据库查询相关工具
2.2 工作流程
- 用户输入查询内容(文本或图像)
- 动态路由中间件分析输入内容类型
- 根据内容类型选择合适的模型进行处理
- Agent调用相应工具执行具体任务
- 整合结果并返回给用户
3. 核心模块详解
3.1 Agent代理模块 ([dashscope_ocr.py](file:///Users/laraveljun/big_model/langchain-learn/dashscope_ocr.py))
from dotenv import load_dotenv
import os
# 加载.env文件中的环境变量
load_dotenv(override=True)
from func_tool.weather import query_weather
from func_tool.db_tools import get_sql_tools
from langchain.agents.middleware import (wrap_model_call,
ModelRequest, ModelResponse)
from typing import Callable
from langchain.agents import create_agent
from langchain_community.chat_models import ChatTongyi
model = ChatTongyi(model="qwen-turbo", api_key=os.getenv("DASHSCOPE_API_KEY"))
vl_model = ChatTongyi(model="qwen3-vl-flash", api_key=os.getenv("DASHSCOPE_API_KEY"))
# 创建可以同时使用天气和数据库工具的智能助手
database_uri = "sqlite:///student_quiz.db" # 示例数据库URI
tools = get_sql_tools(database_uri, model)
@wrap_model_call
def dynamic_routing_model(
request: ModelRequest,
handler

最低0.47元/天 解锁文章
1574

被折叠的 条评论
为什么被折叠?



