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,6 +1613,8 @@ 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 = [
{ {
"type": "function",
"function": {
"name": "get_current_weather", "name": "get_current_weather",
"description": "Get the current weather in a given location", "description": "Get the current weather in a given location",
"parameters": { "parameters": {
@ -1626,6 +1628,7 @@ def test_openai_streaming_and_function_calling():
}, },
"required": ["location"], "required": ["location"],
}, },
},
} }
] ]
messages = [{"role": "user", "content": "What is the weather like in Boston?"}] messages = [{"role": "user", "content": "What is the weather like in Boston?"}]
@ -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