22from openai import OpenAI
33from utils import *
44
5- server = ServerPreset . tinyllama2 ()
5+ server : ServerProcess
66
7-
8- @pytest .fixture (scope = "module" , autouse = True )
7+ @pytest .fixture (autouse = True )
98def create_server ():
109 global server
1110 server = ServerPreset .tinyllama2 ()
@@ -277,37 +276,41 @@ def test_completion_without_tool_call(template_name: str, n_predict: int, tools:
277276
278277@pytest .mark .slow
279278@pytest .mark .parametrize ("tool,expected_arguments,hf_repo,hf_file,template_override" , [
280- (PYTHON_TOOL , {"code" : "print('Hello, world!')" }, "bartowski/gemma-2-2b-it-GGUF" , "gemma-2-2b-it-Q4_K_M.gguf" , None ),
281- (PYTHON_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/Mistral-Nemo-Instruct-2407-GGUF" , "Mistral-Nemo-Instruct-2407-Q4_K_M.gguf" , None ),
282- (PYTHON_TOOL , {"code" : "print(\" Hello World\" )" }, "bartowski/Qwen2.5-7B-Instruct-GGUF" , "Qwen2.5-7B-Instruct-Q4_K_M.gguf" , None ),
283- (PYTHON_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/Phi-3.5-mini-instruct-GGUF" , "Phi-3.5-mini-instruct-Q4_K_M.gguf" , None ),
279+ (PYTHON_TOOL , {"code" : "print('Hello World!')" }, "bartowski/gemma-2-2b-it-GGUF" , "gemma-2-2b-it-Q4_K_M.gguf" , None ),
280+ (PYTHON_TOOL , {"code" : "print(\" Hello World!\" )" }, "bartowski/Qwen2.5-7B-Instruct-GGUF" , "Qwen2.5-7B-Instruct-Q4_K_M.gguf" , None ),
281+ (PYTHON_TOOL , {"code" : "print('Hello World')" }, "bartowski/Phi-3.5-mini-instruct-GGUF" , "Phi-3.5-mini-instruct-Q4_K_M.gguf" , None ),
284282 (PYTHON_TOOL , {"code" : "print('Hello, world!')" }, "NousResearch/Hermes-2-Pro-Llama-3-8B-GGUF" , "Hermes-2-Pro-Llama-3-8B-Q4_K_M.gguf" , ("NousResearch/Hermes-2-Pro-Llama-3-8B" , "tool_use" )),
285283 (PYTHON_TOOL , {"code" : "print('hello world')" }, "NousResearch/Hermes-3-Llama-3.1-8B-GGUF" , "Hermes-3-Llama-3.1-8B.Q4_K_M.gguf" , ("NousResearch-Hermes-3-Llama-3.1-8B" , "tool_use" )),
286- (PYTHON_TOOL , {"code" : "print('Hello, World !')" }, "bartowski/Llama-3.2-1B-Instruct-GGUF" , "Llama-3.2-1B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
284+ (PYTHON_TOOL , {"code" : "print('Hello, world !')" }, "bartowski/Llama-3.2-1B-Instruct-GGUF" , "Llama-3.2-1B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
287285 (PYTHON_TOOL , {"code" : "print(" }, "bartowski/Llama-3.2-3B-Instruct-GGUF" , "Llama-3.2-3B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
288286 (PYTHON_TOOL , {"code" : "print(" }, "lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF" , "Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf" , None ),
289- (PYTHON_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/functionary-small-v3.2-GGUF" , "functionary-small-v3.2-Q8_0.gguf" , ("meetkai-functionary-medium-v3.2" , None )),
290- (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, world!')" }, "bartowski/gemma-2-2b-it-GGUF" , "gemma-2-2b-it-Q4_K_M.gguf" , None ),
291- (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/Mistral-Nemo-Instruct-2407-GGUF" , "Mistral-Nemo-Instruct-2407-Q4_K_M.gguf" , ("mistralai-Mistral-Nemo-Instruct-2407" , None )),
292- (CODE_INTEPRETER_TOOL , {"code" : "print(\" Hello World\" )" }, "bartowski/Qwen2.5-7B-Instruct-GGUF" , "Qwen2.5-7B-Instruct-Q4_K_M.gguf" , None ),
293- (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/Phi-3.5-mini-instruct-GGUF" , "Phi-3.5-mini-instruct-Q4_K_M.gguf" , None ),
287+ (CODE_INTEPRETER_TOOL , {"code" : "print('Hello World!')" }, "bartowski/gemma-2-2b-it-GGUF" , "gemma-2-2b-it-Q4_K_M.gguf" , None ),
288+ (CODE_INTEPRETER_TOOL , {"code" : "print('Hello World!')" }, "bartowski/Qwen2.5-7B-Instruct-GGUF" , "Qwen2.5-7B-Instruct-Q4_K_M.gguf" , None ),
289+ (CODE_INTEPRETER_TOOL , {"code" : "print('Hello World')" }, "bartowski/Phi-3.5-mini-instruct-GGUF" , "Phi-3.5-mini-instruct-Q4_K_M.gguf" , None ),
294290 (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, world!')" }, "NousResearch/Hermes-2-Pro-Llama-3-8B-GGUF" , "Hermes-2-Pro-Llama-3-8B-Q4_K_M.gguf" , ("NousResearch-Hermes-2-Pro-Llama-3-8B" , "tool_use" )),
295291 (CODE_INTEPRETER_TOOL , {"code" : "print('hello world')" }, "NousResearch/Hermes-3-Llama-3.1-8B-GGUF" , "Hermes-3-Llama-3.1-8B.Q4_K_M.gguf" , ("NousResearch-Hermes-3-Llama-3.1-8B" , "tool_use" )),
296- (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, World! ')" }, "lmstudio-community/Llama-3.2-1B-Instruct-GGUF" , "Llama-3.2-1B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
292+ (CODE_INTEPRETER_TOOL , {"code" : "print('hello world ')" }, "lmstudio-community/Llama-3.2-1B-Instruct-GGUF" , "Llama-3.2-1B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
297293 (CODE_INTEPRETER_TOOL , {"code" : "print(" }, "lmstudio-community/Llama-3.2-3B-Instruct-GGUF" , "Llama-3.2-3B-Instruct-Q4_K_M.gguf" , ("meta-llama-Llama-3.2-3B-Instruct" , None )),
298294 (CODE_INTEPRETER_TOOL , {"code" : "print(" }, "lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF" , "Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf" , None ),
299- (CODE_INTEPRETER_TOOL , {"code" : "print('Hello, World!')" }, "bartowski/functionary-small-v3.2-GGUF" , "functionary-small-v3.2-Q8_0.gguf" , ("meetkai-functionary-medium-v3.2" , None )),
295+ # TODO: fix tool call handling of these models
296+ # (PYTHON_TOOL, {"code": "print('Hello, World!')"}, "bartowski/functionary-small-v3.2-GGUF", "functionary-small-v3.2-Q8_0.gguf", ("meetkai-functionary-medium-v3.2", None)),
297+ # (CODE_INTEPRETER_TOOL, {"code": "print('Hello, World!')"}, "bartowski/functionary-small-v3.2-GGUF", "functionary-small-v3.2-Q8_0.gguf", ("meetkai-functionary-medium-v3.2", None)),
298+ # (PYTHON_TOOL, {"code": "print('Hello, World!')"}, "bartowski/Mistral-Nemo-Instruct-2407-GGUF", "Mistral-Nemo-Instruct-2407-Q4_K_M.gguf", None),
299+ # (CODE_INTEPRETER_TOOL, {"code": "print('Hello, World!')"}, "bartowski/Mistral-Nemo-Instruct-2407-GGUF", "Mistral-Nemo-Instruct-2407-Q4_K_M.gguf", ("mistralai-Mistral-Nemo-Instruct-2407", None)),
300300])
301301def test_hello_world_tool_call (tool : dict , expected_arguments : dict , hf_repo : str , hf_file : str , template_override : Tuple [str , str | None ] | None ):
302302 global server
303303 server .use_jinja = True
304+ server .n_ctx = 8192
304305 server .n_predict = 128
305306 server .model_hf_repo = hf_repo
306307 server .model_hf_file = hf_file
307308 if template_override :
308309 (template_hf_repo , template_variant ) = template_override
309310 server .chat_template_file = f"../../../tests/chat/templates/{ template_hf_repo .replace ('/' , '' ) + ('-' + template_variant if template_variant else '' )} .jinja"
310- assert os .path .exists (server .chat_template_file ), f"Template file { server .chat_template_file } does not exist. Run `python scripts/fetch_server_test_models.py { template_hf_repo } { template_variant } ` to download the template."
311+ assert os .path .exists (server .chat_template_file ), f"Template file { server .chat_template_file } does not exist. Run `python scripts/get_hf_chat_template.py { template_hf_repo } { template_variant } > { server .chat_template_file } ` to download the template."
312+ # else:
313+ # server.chat_template_file = None
311314 server .start (timeout_seconds = 15 * 60 )
312315 res = server .make_request ("POST" , "/chat/completions" , data = {
313316 "max_tokens" : 256 ,
@@ -322,7 +325,10 @@ def test_hello_world_tool_call(tool: dict, expected_arguments: dict, hf_repo: st
322325 tool_calls = choice ["message" ].get ("tool_calls" )
323326 assert tool_calls and len (tool_calls ) == 1 , f'Expected 1 tool call in { choice ["message" ]} '
324327 tool_call = tool_calls [0 ]
325- assert tool ["function" ]["name" ] == tool_call ["function" ]["name" ]
328+ if tool ["type" ] == "function" :
329+ assert tool ["function" ]["name" ] == tool_call ["function" ]["name" ]
330+ elif tool ["type" ] == "code_interpreter" :
331+ assert tool_call ["function" ]["name" ] == "python"
326332 actual_arguments = json .loads (tool_call ["function" ]["arguments" ])
327333 assert json .dumps (expected_arguments ) == json .dumps (actual_arguments ), f"tool arguments: { json .dumps (actual_arguments )} , expected: { json .dumps (expected_arguments )} "
328334
0 commit comments