BBr*_*lyn 2 python langchain large-language-model py-langchain
我正在尝试LangChain的AgentType.CHAT_ZERO_SHOT_REACT
代理。从它的名字来看,我认为这是一个用于聊天的代理,我已经给了它内存,但它似乎无法访问它的内存。我还需要做什么才能访问它的内存?或者我是否错误地认为该代理可以处理聊天?
这是我的代码和示例输出:
llm = ChatOpenAI(model_name="gpt-4",
temperature=0)
tools = load_tools(["llm-math", "wolfram-alpha", "wikipedia"], llm=llm)
memory = ConversationBufferMemory(memory_key="chat_history")
agent_test = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors=True,
memory=memory,
verbose=True
)
Run Code Online (Sandbox Code Playgroud)
>>> agent_test.run("What is the height of the empire state building?")
'The Empire State Building stands a total of 1,454 feet tall, including its antenna.'
>>> agent_test.run("What was the last question I asked?")
"I'm sorry, but I can't provide the information you're looking for."
Run Code Online (Sandbox Code Playgroud)
它不是。这表示只需zero-shot
查看当前提示即可。从这里
\n\n零样本意味着代理仅在当前操作上运行 \xe2\x80\x94 它\n没有记忆。它使用 ReAct 框架仅根据工具\xe2\x80\x99s 描述来决定使用哪个工具。
\n
我认为当您使用这种代理类型时,您应该添加description
到该工具中。这样llm就会根据描述推断出使用了哪个工具。这是description
“zero-shot-react-description”的一部分。来自上面同一链接的示例:
math_tool = Tool(\n name=\'Calculator\',\n func=llm_math.run,\n description=\'Useful for when you need to answer questions about math.\'\n)\n
Run Code Online (Sandbox Code Playgroud)\n当 llm 看到提示时,如果它推断该提示与数学相关,它将使用math_tool
如果你想使用内存,你应该使用chat-conversational-react-description
\nfrom langchain.memory import ConversationBufferMemory\nfrom langchain.chat_models import ChatOpenAI\n\nmemory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)\nllm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, temperature=0)\nagent_chain = initialize_agent(tools, llm, agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, verbose=True, memory=memory)\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
3648 次 |
最近记录: |