test(test_streaming.py): fix openai streaming function calling test

This commit is contained in:
Krrish Dholakia 2024-02-22 21:50:14 -08:00
parent 01e6c7ed89
commit ca03c57277

View file

@ -1613,18 +1613,21 @@ def streaming_and_function_calling_format_tests(idx, chunk):
def test_openai_streaming_and_function_calling(): def test_openai_streaming_and_function_calling():
tools = [ tools = [
{ {
"name": "get_current_weather", "type": "function",
"description": "Get the current weather in a given location", "function": {
"parameters": { "name": "get_current_weather",
"type": "object", "description": "Get the current weather in a given location",
"properties": { "parameters": {
"location": { "type": "object",
"type": "string", "properties": {
"description": "The city and state, e.g. San Francisco, CA", "location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
}, },
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, "required": ["location"],
}, },
"required": ["location"],
}, },
} }
] ]
@ -1638,7 +1641,13 @@ def test_openai_streaming_and_function_calling():
) )
# Add any assertions here to check the response # Add any assertions here to check the response
for idx, chunk in enumerate(response): for idx, chunk in enumerate(response):
streaming_and_function_calling_format_tests(idx=idx, chunk=chunk) if idx == 0:
assert (
chunk.choices[0].delta.tool_calls[0].function.arguments is not None
)
assert isinstance(
chunk.choices[0].delta.tool_calls[0].function.arguments, str
)
except Exception as e: except Exception as e:
pytest.fail(f"Error occurred: {e}") pytest.fail(f"Error occurred: {e}")
raise e raise e