Skip to content

Commit c6a22ed

Browse files
author
Olivier Chafik
committed
Greedy sampling in tool call tests
1 parent cce1166 commit c6a22ed

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

examples/server/server.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,10 @@ struct server_task_result_cmpl_final : server_task_result {
687687
finish_reason = "stop";
688688
}
689689

690-
common_chat_msg parsed_tool_calls;
691690
json tool_calls;
692691
json message_content;
693692
if (oaicompat_tool_call_style != common_tool_call_style::COMMON_TOOL_CALL_STYLE_NONE && !oaicompat_tools.is_null()) {
694-
parsed_tool_calls = parse_tool_calls(oaicompat_tool_call_style, oaicompat_tools, content);
693+
auto parsed_tool_calls = parse_tool_calls(oaicompat_tool_call_style, oaicompat_tools, content);
695694
if (!parsed_tool_calls.tool_calls.empty()) {
696695
finish_reason = "tool_calls";
697696
message_content = parsed_tool_calls.content;
@@ -716,7 +715,7 @@ struct server_task_result_cmpl_final : server_task_result {
716715
json choice {
717716
{"finish_reason", finish_reason},
718717
{"index", 0},
719-
{"message", {
718+
{"message", json {
720719
{"content", message_content},
721720
{"tool_calls", tool_calls},
722721
{"role", "assistant"},

examples/server/tests/unit/test_chat_completion.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,20 @@ def test_chat_completion_with_timings_per_token():
224224

225225

226226
@pytest.mark.parametrize("template_name,n_predict,tool,expected_arguments", [
227-
("meetkai-functionary-medium-v3.1", 32, TEST_TOOL, {} ),
228-
("meetkai-functionary-medium-v3.1", 32, PYTHON_TOOL, {"code": " and played all day.\" exclasted her pare"} ),
229-
("meetkai-functionary-medium-v3.2", 128, TEST_TOOL, {} ),
230-
("meetkai-functionary-medium-v3.2", 128, PYTHON_TOOL, {"code": "Sure, I cannything,"} ),
231-
("NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use", 128, TEST_TOOL, {} ),
232-
("NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use", 128, PYTHON_TOOL, {"code": " out the owl cried. Jack said "} ),
233-
("NousResearch-Hermes-3-Llama-3.1-8B-tool_use", 128, TEST_TOOL, {} ),
234-
("NousResearch-Hermes-3-Llama-3.1-8B-tool_use", 128, PYTHON_TOOL, {"code": " out the owl cried. Jack said "} ),
235-
("meta-llama-Meta-Llama-3.1-8B-Instruct", 128, TEST_TOOL, {} ),
236-
("meta-llama-Meta-Llama-3.1-8B-Instruct", 128, PYTHON_TOOL, {"code": "Let's feel out cooking fun together,"} ),
237-
("meta-llama-Llama-3.2-3B-Instruct", 128, TEST_TOOL, {} ),
238-
("meta-llama-Llama-3.2-3B-Instruct", 128, PYTHON_TOOL, {"code": "Well you fight. Peopballs donto cheep and come again."} ),
239-
("mistralai-Mistral-Nemo-Instruct-2407", 128, TEST_TOOL, {} ),
240-
("mistralai-Mistral-Nemo-Instruct-2407", 128, PYTHON_TOOL, {"code": "I can cannot count."} ),
227+
("meetkai-functionary-medium-v3.1", 32, TEST_TOOL, {} ),
228+
("meetkai-functionary-medium-v3.1", 32, PYTHON_TOOL, {"code": ". She was so excited to go to the park and c"} ),
229+
("meetkai-functionary-medium-v3.2", 128, TEST_TOOL, {} ),
230+
("meetkai-functionary-medium-v3.2", 128, PYTHON_TOOL, {"code": "It's a spector."} ),
231+
("NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use", 128, TEST_TOOL, {} ),
232+
("NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use", 128, PYTHON_TOOL, {"code": "Yes, you can."} ),
233+
("NousResearch-Hermes-3-Llama-3.1-8B-tool_use", 128, TEST_TOOL, {} ),
234+
("NousResearch-Hermes-3-Llama-3.1-8B-tool_use", 128, PYTHON_TOOL, {"code": "Yes, you can."} ),
235+
("meta-llama-Meta-Llama-3.1-8B-Instruct", 128, TEST_TOOL, {} ),
236+
("meta-llama-Meta-Llama-3.1-8B-Instruct", 128, PYTHON_TOOL, {"code": "It's a spector."} ),
237+
("meta-llama-Llama-3.2-3B-Instruct", 128, TEST_TOOL, {} ),
238+
("meta-llama-Llama-3.2-3B-Instruct", 128, PYTHON_TOOL, {"code": "It's a spectork."} ),
239+
("mistralai-Mistral-Nemo-Instruct-2407", 128, TEST_TOOL, {} ),
240+
("mistralai-Mistral-Nemo-Instruct-2407", 128, PYTHON_TOOL, {"code": "It's a speciachy!"} ),
241241
])
242242
def test_completion_with_required_tool(template_name: str, n_predict: int, tool: dict, expected_arguments: dict):
243243
global server
@@ -254,6 +254,9 @@ def test_completion_with_required_tool(template_name: str, n_predict: int, tool:
254254
"tool_choice": "required",
255255
"tools": [tool],
256256
"parallel_tool_calls": False,
257+
"temperature": 0.0,
258+
"top_k": 1,
259+
"top_p": 1.0,
257260
})
258261
assert res.status_code == 200, f"Expected status code 200, got {res.status_code}"
259262
choice = res.body["choices"][0]
@@ -290,6 +293,9 @@ def test_completion_without_tool_call(template_name: str, n_predict: int, tools:
290293
],
291294
"tools": tools if tools else None,
292295
"tool_choice": tool_choice,
296+
"temperature": 0.0,
297+
"top_k": 1,
298+
"top_p": 1.0,
293299
})
294300
assert res.status_code == 200, f"Expected status code 200, got {res.status_code}"
295301
choice = res.body["choices"][0]
@@ -339,7 +345,6 @@ def test_hello_world_tool_call(tool: dict, expected_arguments: dict, hf_repo: st
339345
{"role": "user", "content": "say hello world with python"},
340346
],
341347
"tools": [tool],
342-
# Greedy sampling
343348
"temperature": 0.0,
344349
"top_k": 1,
345350
"top_p": 1.0,

0 commit comments

Comments
 (0)