赞
踩
以下使用千问是报错的,用chatglm 是没有问题的 。
# !pip install -U langchain # !pip install -U langchainhub # !pip install -U langchain_openai # !pip install -U dashscope from langchain.chains import LLMChain from langchain_community.llms import Tongyi import ChatGLM from langchain.agents import AgentExecutor, create_structured_chat_agent, load_tools from langchain import hub import os from langchain.prompts import PromptTemplate os.environ["DASHSCOPE_API_KEY"] = "sk-cc1c8314fdbd43ceaf26ec1824d5dd3b" os.environ["SERPAPI_API_KEY"] = "sk-cc1c8314fdbd43ceaf26ec1824d5dd3b" # llm = Tongyi() llm = ChatGLM.ChatGLM_LLM() from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI from langchain.agents import load_tools from langchain_community.tools.tavily_search import TavilySearchResults os.environ["TAVILY_API_KEY"] = "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" os.environ["SERPAPI_API_KEY"] = "378cc16ff5396044a3a85721dc492f3d26a69e20" prompt = hub.pull("hwchase17/structured-chat-agent") tools = load_tools(["requests_all"]) agent = create_structured_chat_agent(llm, tools, prompt) agent_executor = AgentExecutor( agent=agent, tools=tools ) output = agent_executor.invoke({"input": "孙悟空是谁?"}) print(output["output"])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。