Improve missing toolcall exception (#614)

This commit is contained in:
Graham 2025-02-14 13:49:15 +00:00 committed by GitHub
parent 4730830780
commit d33bc2dd9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -132,6 +132,7 @@ def parse_json_if_needed(arguments: Union[str, dict]) -> Union[str, dict]:
def parse_tool_args_if_needed(message: ChatMessage) -> ChatMessage:
if message.tool_calls is not None:
for tool_call in message.tool_calls:
tool_call.function.arguments = parse_json_if_needed(tool_call.function.arguments)
return message

View File

@ -107,6 +107,11 @@ class ModelTests(unittest.TestCase):
output = model(messages, stop_sequences=["great"]).content
assert output == "Hello! How can"
def test_parse_tool_args_if_needed(self):
original_message = ChatMessage(role="user", content=[{"type": "text", "text": "Hello!"}])
parsed_message = models.parse_tool_args_if_needed(original_message)
assert parsed_message == original_message
def test_parse_json_if_needed(self):
args = "abc"
parsed_args = parse_json_if_needed(args)