feat:初始化工程
This commit is contained in:
45
agent.py
Normal file
45
agent.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from langchain.agents import create_agent
|
||||
from langchain.chat_models import init_chat_model
|
||||
import sqlite3
|
||||
|
||||
from langchain_tavily import TavilySearch
|
||||
from langgraph.checkpoint.sqlite import SqliteSaver
|
||||
|
||||
# 连接sqlite
|
||||
connection = sqlite3.connect("chief.db", check_same_thread=False)
|
||||
# 初始化checkpointer
|
||||
checkpointer = SqliteSaver(connection)
|
||||
# 自动建表
|
||||
checkpointer.setup()
|
||||
|
||||
# web搜索工具,使用tavily作为web搜索工具
|
||||
web_search = TavilySearch(
|
||||
tavily_api_key="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",
|
||||
max_results=5,
|
||||
topic="general"
|
||||
)
|
||||
|
||||
system_prompt = """
|
||||
你是一名私人厨师。收到用户提供的清单后,请按以下流程操作:
|
||||
1.识别和评估食材:根据用户提供的信息,整理出一份“当前可用食材清单”。
|
||||
2.智能食谱检索:优先调用 web_search 工具,以“可用食材清单”为核心关键词,查找可行菜谱。
|
||||
3.多维度评估与排序:从营养价值和制作难度两个维度对检索到的候选食谱进行量化打分,并根据得分排序,制作简单且营养丰富的排名靠前。
|
||||
4.结构化方案输出:把排序后的食谱整理为一份结构清晰的建议报告,要包含食谱信息、得分、推荐理由、食谱的参考图片,帮助用户快速做出决策。
|
||||
|
||||
请严格按照流程,优先调用 web_search 工具搜索食谱,搜索不到的情况下才能自己发挥。
|
||||
"""
|
||||
|
||||
model = init_chat_model(
|
||||
model="qwen3-max-2026-01-23",
|
||||
model_provider="openai",
|
||||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||
api_key="sk-52bcd98e9c1d45908437c4e8706eefff",
|
||||
temperature=1.5,
|
||||
)
|
||||
|
||||
agent = create_agent(
|
||||
model=model, # 模型
|
||||
tools=[web_search], # 工具
|
||||
checkpointer=checkpointer, # 记忆
|
||||
system_prompt=system_prompt # 系统提示词
|
||||
)
|
||||
Reference in New Issue
Block a user