diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 35410ca..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml -# 基于编辑器的 HTTP 客户端请求 -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/MarsCodeWorkspaceAppSettings.xml deleted file mode 100644 index d36d10b..0000000 --- a/.idea/MarsCodeWorkspaceAppSettings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/agent_proj.iml b/.idea/agent_proj.iml deleted file mode 100644 index 5e376b1..0000000 --- a/.idea/agent_proj.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 10ef16f..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f86cb7f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 46804c5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/01_Agent.py b/01_Agent.py deleted file mode 100644 index 01614ed..0000000 --- a/01_Agent.py +++ /dev/null @@ -1,26 +0,0 @@ -from langchain.agents import create_agent -from langchain_community.chat_models.tongyi import ChatTongyi -from langchain_core.tools import tool - -@tool(description="查询天气") -def get_weather(): - return "晴天" - - -agent = create_agent( - model=ChatTongyi(model="qwen3-max"), - tools=[get_weather], - system_prompt="你是一个聊天助手,可以回答用户问题" -) - -res = agent.invoke( - { - "messages": [ - {"role": "user", "content": "明天深圳的天气如何"}, - ] - } -) - -for msg in res["messages"]: - print(f"{type(msg).__name__}: {msg.content}") - \ No newline at end of file diff --git a/02_Stream.py b/02_Stream.py deleted file mode 100644 index 9092556..0000000 --- a/02_Stream.py +++ /dev/null @@ -1,37 +0,0 @@ -from langchain.agents import create_agent -from langchain_community.chat_models.tongyi import ChatTongyi -from langchain_core.tools import tool - - -@tool(description="查询股票价格") -def get_price(name: str) -> str: - return f"股票{name}的价格是20元" - - -@tool(description="查询股票信息") -def get_info(name: str) -> str: - return f"股票{name}是一家A股上市公司" - - -agent = create_agent( - model=ChatTongyi(model="qwen3-max"), - tools=[get_price, get_info], - system_prompt="你是一个智能助手,可以回答股票相关问题,请告知我思考过程,让我知道你为什么调用某个工具" -) - -res = agent.stream( - {"messages": [{ - "role": "user", "content": "kk公司股价多少,并介绍一下" - }]}, - stream_mode="values" -) - -for chunk in res: - last_msg = chunk["messages"][-1] - if last_msg.content: - print(type(last_msg).__name__, last_msg.content) - - if type(last_msg).__name__ == "AIMessage": - if last_msg.tool_calls: - tool_list = [tc['name'] for tc in last_msg.tool_calls] - print(f"工具调佣 {tool_list}") diff --git a/03_ReAct.py b/03_ReAct.py deleted file mode 100644 index 00c6485..0000000 --- a/03_ReAct.py +++ /dev/null @@ -1,39 +0,0 @@ -from langchain.agents import create_agent -from langchain_community.chat_models.tongyi import ChatTongyi -from langchain_core.tools import tool - - -@tool(description="获取体重,返回值整数,单位千克") -def get_weight() -> int: - return 93 - - -@tool(description="获取身高,返回值整数,单位厘米") -def get_height() -> int: - return 185 - - -agent = create_agent( - model=ChatTongyi(model="qwen3-max"), - tools=[get_height, get_weight], - system_prompt="""你是严格遵循ReAct框架的智能体,必须按[思考,行动,观察,再思考]的流程解决问题 - 每轮仅能思考并调用1个工具,禁止单词调用多个工具。并告知我你的思考过程,工具调用的原因,按思考、行动 - 、观察三个结构告知我""" -) - -res = agent.stream( - {"messages": [{ - "role": "user", "content": "计算我的BMI" - }]}, - stream_mode="values" -) - -for chunk in res: - last_msg = chunk["messages"][-1] - if last_msg.content: - print(type(last_msg).__name__, last_msg.content) - - if type(last_msg).__name__ == "AIMessage": - if last_msg.tool_calls: - tool_list = [tc['name'] for tc in last_msg.tool_calls] - print(f"工具调佣 {tool_list}") diff --git a/04_middle_ware.py b/04_middle_ware.py deleted file mode 100644 index 0c52cc2..0000000 --- a/04_middle_ware.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -agent 前后 -model 前后 -工具 中 -模型 中 -""" - -from langchain.agents import create_agent, AgentState -from langchain.agents.middleware import before_agent, after_agent, before_model, after_model, wrap_model_call, \ - wrap_tool_call -from langchain_community.chat_models.tongyi import ChatTongyi -from langchain_core.tools import tool -from langgraph.runtime import Runtime - - -@tool(description="查询天气, 传入城市名称字符串,返回字符串天气信息") -def get_weather(city: str) -> str: - return f"{city} : 晴天" - - -@before_agent -def log_before_agent(state: AgentState, runtime: Runtime) -> None: - print(f"before agent: info_num: {len(state["messages"])}") - - -@after_agent -def log_after_agent(state: AgentState, runtime: Runtime) -> None: - print(f"after agent: info_num: {len(state["messages"])}") - - -@before_model -def log_before_model(state: AgentState, runtime: Runtime) -> None: - print(f"before model: info_num: {len(state["messages"])}") - - -@after_model -def log_after_model(state: AgentState, runtime: Runtime) -> None: - print(f"after model: info_num: {len(state["messages"])}") - - -@wrap_model_call -def model_call_hook(request, handler): - print(f"model call: {request}") - return handler(request) - - -@wrap_tool_call -def model_tool_hook(request, handler): - print(f"model tool: {request.tool_call['name']}") - print(f"args: {request.tool_call['args']}") - return handler(request) - -agent = create_agent( - model=ChatTongyi(model="qwen3-max"), - tools=[get_weather], - middleware=[model_call_hook, model_tool_hook, log_before_model, - log_after_model, log_before_agent, log_after_agent], - system_prompt="""你是严格遵循ReAct框架的智能体,必须按[思考,行动,观察,再思考]的流程解决问题 - 每轮仅能思考并调用1个工具,禁止单词调用多个工具。并告知我你的思考过程,工具调用的原因,按思考、行动 - 、观察三个结构告知我""" -) - -res = agent.stream( - {"messages": [{ - "role": "user", "content": "查询北京的天气" - }]}, - stream_mode="values" -) -for chunk in res: - print(chunk["messages"][-1].content) diff --git a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/link_lists.bin b/app.py similarity index 100% rename from chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/link_lists.bin rename to app.py diff --git a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/data_level0.bin b/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/data_level0.bin deleted file mode 100644 index c004b51..0000000 Binary files a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/data_level0.bin and /dev/null differ diff --git a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/header.bin b/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/header.bin deleted file mode 100644 index b4a33c1..0000000 Binary files a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/header.bin and /dev/null differ diff --git a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/length.bin b/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/length.bin deleted file mode 100644 index cb3e162..0000000 Binary files a/chroma_db/b6f0b699-0f70-4425-90e0-14336ce44f8f/length.bin and /dev/null differ diff --git a/chroma_db/chroma.sqlite3 b/chroma_db/chroma.sqlite3 deleted file mode 100644 index aa6c5a3..0000000 Binary files a/chroma_db/chroma.sqlite3 and /dev/null differ