mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 03:26:17 +00:00
Gracefully degrade when model asks for nonexistent tool (#268)
Not yet tested, but very simple change, assumption is that we're cool with just producing a generic output when tool is not found
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
from typing import Any, List, Mapping, Optional, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from langchain.agents.react.base import ReActChain, ReActDocstoreAgent
|
||||
from langchain.agents.tools import Tool
|
||||
from langchain.docstore.base import Docstore
|
||||
@@ -94,10 +92,12 @@ def test_react_chain() -> None:
|
||||
|
||||
def test_react_chain_bad_action() -> None:
|
||||
"""Test react chain when bad action given."""
|
||||
bad_action_name = "BadAction"
|
||||
responses = [
|
||||
"I should probably search\nAction 1: BadAction[langchain]",
|
||||
f"I'm turning evil\nAction 1: {bad_action_name}[langchain]",
|
||||
"Oh well\nAction 2: Finish[curses foiled again]",
|
||||
]
|
||||
fake_llm = FakeListLLM(responses)
|
||||
react_chain = ReActChain(llm=fake_llm, docstore=FakeDocstore())
|
||||
with pytest.raises(KeyError):
|
||||
react_chain.run("when was langchain made")
|
||||
output = react_chain.run("when was langchain made")
|
||||
assert output == "curses foiled again"
|
||||
|
Reference in New Issue
Block a user