@@ -40,12 +40,12 @@ def test_convert_message_to_llamacpp_format():
40
40
message = ChatMessage .from_user ("I have a question" )
41
41
assert _convert_message_to_llamacpp_format (message ) == {"role" : "user" , "content" : "I have a question" }
42
42
43
- message = ChatMessage . from_function ( "Function call" , "function_name" )
44
- converted_message = _convert_message_to_llamacpp_format ( message )
45
-
46
- assert converted_message ["role" ] in ("function" , "tool" )
47
- assert converted_message ["name" ] == "function_name"
48
- assert converted_message ["content" ] == "Function call"
43
+ if hasattr ( ChatMessage , "from_function" ):
44
+ message = ChatMessage . from_function ( "Function call" , "function_name" )
45
+ converted_message = _convert_message_to_llamacpp_format ( message )
46
+ assert converted_message ["role" ] in ("function" , "tool" )
47
+ assert converted_message ["name" ] == "function_name"
48
+ assert converted_message ["content" ] == "Function call"
49
49
50
50
51
51
class TestLlamaCppChatGenerator :
@@ -420,19 +420,20 @@ def test_function_call_and_execute(self, generator):
420
420
assert "tool_calls" in first_reply .meta
421
421
tool_calls = first_reply .meta ["tool_calls" ]
422
422
423
- for tool_call in tool_calls :
424
- function_name = tool_call ["function" ]["name" ]
425
- function_args = json .loads (tool_call ["function" ]["arguments" ])
426
- assert function_name in available_functions
427
- function_response = available_functions [function_name ](** function_args )
428
- function_message = ChatMessage .from_function (function_response , function_name )
429
- messages .append (function_message )
430
-
431
- second_response = generator .run (messages = messages )
432
- assert "replies" in second_response
433
- assert len (second_response ["replies" ]) > 0
434
- assert any ("San Francisco" in reply .text for reply in second_response ["replies" ])
435
- assert any ("72" in reply .text for reply in second_response ["replies" ])
423
+ if hasattr (ChatMessage , "from_function" ):
424
+ for tool_call in tool_calls :
425
+ function_name = tool_call ["function" ]["name" ]
426
+ function_args = json .loads (tool_call ["function" ]["arguments" ])
427
+ assert function_name in available_functions
428
+ function_response = available_functions [function_name ](** function_args )
429
+ function_message = ChatMessage .from_function (function_response , function_name )
430
+ messages .append (function_message )
431
+
432
+ second_response = generator .run (messages = messages )
433
+ assert "replies" in second_response
434
+ assert len (second_response ["replies" ]) > 0
435
+ assert any ("San Francisco" in reply .text for reply in second_response ["replies" ])
436
+ assert any ("72" in reply .text for reply in second_response ["replies" ])
436
437
437
438
438
439
class TestLlamaCppChatGeneratorChatML :
0 commit comments