观察:Python REPL 不是一个有效的工具,请尝试 [python_repl_ast] 之一。在朗链

问题描述 投票:0回答:1
from langchain.agents import initialize_agent
from langchain.llms.fake import FakeListLLM
from langchain.agents import AgentType
from langchain_experimental.tools import PythonAstREPLTool
res = ["Action: Python REPL\nAction Input: print(2.2 + 2.22)", "Final Answer: 4.42"]
llm = FakeListLLM(responses=res)
agent = initialize_agent(tools=[PythonAstREPLTool()],
llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
agent.run("what is 2.2 + 2.22?")

这段代码有什么问题?我收到以下错误:

REPL is not a valid tool

有人可以向我解释一下使用

Langchain
实现假 LLM 的更好方法吗?

python artificial-intelligence langchain large-language-model
1个回答
0
投票

观察结果说明了一切。使用

python_repl_ast
代替
Python REPL
。以下是更新后的代码:

from langchain.agents import initialize_agent
from langchain.llms.fake import FakeListLLM
from langchain.agents import AgentType
from langchain_experimental.tools import PythonAstREPLTool

res = ["Action: python_repl_ast\nAction Input: print(2.2 + 2.22)", "Final Answer: 4.42"]
llm = FakeListLLM(responses=res)
agent = initialize_agent(tools=[PythonAstREPLTool()], llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent.run("what is 2.2 + 2.22?")

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.