standard tests: add test for few-shot examples (#21019)

pull/21413/merge
ccurme 2 weeks ago committed by GitHub
parent db22fcb58b
commit 01a3228d8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -217,3 +217,43 @@ class ChatModelIntegrationTests(ABC):
]
result_list_content = model_with_tools.invoke(messages_list_content)
assert isinstance(result_list_content, AIMessage)
def test_structured_few_shot_examples(
self,
chat_model_class: Type[BaseChatModel],
chat_model_params: dict,
chat_model_has_tool_calling: bool,
) -> None:
"""
Test that model can process few-shot examples with tool calls.
"""
if not chat_model_has_tool_calling:
pytest.skip("Test requires tool calling.")
model = chat_model_class(**chat_model_params)
model_with_tools = model.bind_tools([my_adder_tool])
function_name = "my_adder_tool"
function_args = {"a": 1, "b": 2}
function_result = json.dumps({"result": 3})
messages_string_content = [
HumanMessage(content="What is 1 + 2"),
AIMessage(
content="",
tool_calls=[
{
"name": function_name,
"args": function_args,
"id": "abc123",
},
],
),
ToolMessage(
name=function_name,
content=function_result,
tool_call_id="abc123",
),
AIMessage(content=function_result),
HumanMessage(content="What is 3 + 4"),
]
result_string_content = model_with_tools.invoke(messages_string_content)
assert isinstance(result_string_content, AIMessage)

Loading…
Cancel
Save