standard-tests[patch]: improve runnable tool description (#24210)

This commit is contained in:
Bagatur 2024-07-12 14:33:56 -07:00 committed by GitHub
parent e8ee781a42
commit 12950cc602
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -191,12 +191,22 @@ class ChatModelIntegrationTests(ChatModelTests):
pytest.skip("Test requires tool calling.")
prompt = ChatPromptTemplate.from_messages(
[("human", "Hello. Please respond in the style of {answer_style}.")]
[
("system", "Repeat what the user says in the style of {answer_style}."),
("human", "{user_input}"),
]
)
llm = GenericFakeChatModel(messages=iter(["hello matey"]))
chain = prompt | llm | StrOutputParser()
model_with_tools = model.bind_tools([chain.as_tool()])
query = "Using the tool, ask a Pirate how it would say hello."
tool_ = chain.as_tool(
name="repeat_in_answer_style",
description="Repeat the user_input in a particular style of speaking.",
)
model_with_tools = model.bind_tools([tool_])
query = (
"Using the repeat_in_answer_style tool, ask a Pirate how they would say "
"hello."
)
result = model_with_tools.invoke(query)
assert isinstance(result, AIMessage)
assert result.tool_calls