From 3a6a19b3bb72a8f0c4285031ff375bd1b2dd81db Mon Sep 17 00:00:00 2001 From: Daniel Lenton Date: Thu, 7 Nov 2024 20:36:11 +0000 Subject: [PATCH] removed tool use unit test. --- tests/test_universal_api/test_tool_use.py | 77 ----------------------- 1 file changed, 77 deletions(-) delete mode 100644 tests/test_universal_api/test_tool_use.py diff --git a/tests/test_universal_api/test_tool_use.py b/tests/test_universal_api/test_tool_use.py deleted file mode 100644 index 28ba95d..0000000 --- a/tests/test_universal_api/test_tool_use.py +++ /dev/null @@ -1,77 +0,0 @@ -import json -import unittest - -from openai.types.chat.chat_completion_message import ChatCompletionMessage -from openai.types.chat.chat_completion_message_tool_call import ( - ChatCompletionMessageToolCall, - Function, -) -from unify import Unify - - -def test_openai_tool_use() -> None: - # adapted from: https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models # noqa - tools = [ - { - "type": "function", - "function": { - "name": "get_n_day_weather_forecast", - "description": "Get an N-day weather forecast", - "params": { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": ( - "The city and state, e.g. San Francisco, CA" - ), - }, - "format": { - "type": "string", - "enum": ["celsius", "fahrenheit"], - "description": ( - "The temperature unit to use. Infer this " - "from the users location." - ), - }, - "num_days": { - "type": "integer", - "description": "The number of days to forecast", - }, - }, - "required": ["location", "format", "num_days"], - }, - }, - }, - ] - - client = Unify(endpoint="gpt-4o@openai") - result = client.generate( - user_message=( - "What is the weather going to be like in Glasgow, Scotland over " - "the next 5 days?" - ), - tool_choice="required", - tools=tools, - return_full_completion=True, - ) - message = result.choices[0].message - assert isinstance(message, ChatCompletionMessage) - tool_calls = message.tool_calls - assert isinstance(tool_calls, list) - assert len(tool_calls) == 1 - tool_call = tool_calls[0] - assert isinstance(tool_call, ChatCompletionMessageToolCall) - function = tool_call.function - assert isinstance(function, Function) - arguments = function.arguments - assert isinstance(arguments, str) - arguments = json.loads(arguments) - assert isinstance(arguments, dict) - assert "location" in arguments - assert "format" in arguments - assert "num_days" in arguments - - -if __name__ == "__main__": - unittest.main()