Skip to content

Commit

Permalink
standard tests: add test for few-shot examples (#21019)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed May 13, 2024
1 parent db22fcb commit 01a3228
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,43 @@ def test_tool_message_histories_list_content(
]
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)

0 comments on commit 01a3228

Please sign in to comment.