Files
langchain/cookbook/fake_llm.ipynb
T
standby24x7 16e64d889a docs: Update function "run" to "invoke" in fake_llm.ipynb (#19570)
This patch updates function "run" to "invoke" in fake_llm.ipynb. Without
this patch, you see following warning.

LangChainDeprecationWarning: The function `run` was deprecated in
LangChain 0.1.0 and will be removed in 0.2.0. Use invoke instead.

Signed-off-by: Masanari Iida <standby24x7@gmail.com>
2024-03-26 09:54:31 -04:00

2.9 KiB

Fake LLM

LangChain provides a fake LLM class that can be used for testing. This allows you to mock out calls to the LLM and simulate what would happen if the LLM responded in a certain way.

In this notebook we go over how to use this.

We start this with using the FakeLLM in an agent.

In [1]:
from langchain_community.llms.fake import FakeListLLM
In [2]:
from langchain.agents import AgentType, initialize_agent, load_tools
In [3]:
tools = load_tools(["python_repl"])
In [16]:
responses = ["Action: Python REPL\nAction Input: print(2 + 2)", "Final Answer: 4"]
llm = FakeListLLM(responses=responses)
In [17]:
agent = initialize_agent(
    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
In [18]:
agent.invoke("whats 2 + 2")
Out [18]:

> Entering new AgentExecutor chain...
Action: Python REPL
Action Input: print(2 + 2)
Observation: 4

Thought:Final Answer: 4

> Finished chain.
'4'
In [ ]: