forked from phoenix/litellm-mirror
test: fix test
This commit is contained in:
parent
17b97cd930
commit
e90ff0f350
1 changed files with 43 additions and 68 deletions
|
@ -45,51 +45,26 @@ def test_map_azure_model_group(model_group_header, expected_model):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.respx
|
async def test_azure_ai_with_image_url():
|
||||||
async def test_azure_ai_with_image_url(respx_mock: MockRouter):
|
|
||||||
"""
|
"""
|
||||||
Important test:
|
Important test:
|
||||||
|
|
||||||
Test that Azure AI studio can handle image_url passed when content is a list containing both text and image_url
|
Test that Azure AI studio can handle image_url passed when content is a list containing both text and image_url
|
||||||
"""
|
"""
|
||||||
|
from openai import AsyncOpenAI
|
||||||
|
|
||||||
litellm.set_verbose = True
|
litellm.set_verbose = True
|
||||||
|
|
||||||
# Mock response based on the actual API response
|
client = AsyncOpenAI(
|
||||||
mock_response = {
|
api_key="fake-api-key",
|
||||||
"id": "cmpl-53860ea1efa24d2883555bfec13d2254",
|
base_url="https://Phi-3-5-vision-instruct-dcvov.eastus2.models.ai.azure.com",
|
||||||
"choices": [
|
)
|
||||||
{
|
|
||||||
"finish_reason": "stop",
|
|
||||||
"index": 0,
|
|
||||||
"logprobs": None,
|
|
||||||
"message": {
|
|
||||||
"content": "The image displays a graphic with the text 'LiteLLM' in black",
|
|
||||||
"role": "assistant",
|
|
||||||
"refusal": None,
|
|
||||||
"audio": None,
|
|
||||||
"function_call": None,
|
|
||||||
"tool_calls": None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"created": 1731801937,
|
|
||||||
"model": "phi35-vision-instruct",
|
|
||||||
"object": "chat.completion",
|
|
||||||
"usage": {
|
|
||||||
"completion_tokens": 69,
|
|
||||||
"prompt_tokens": 617,
|
|
||||||
"total_tokens": 686,
|
|
||||||
"completion_tokens_details": None,
|
|
||||||
"prompt_tokens_details": None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# Mock the API request
|
with patch.object(
|
||||||
mock_request = respx_mock.post(
|
client.chat.completions.with_raw_response, "create"
|
||||||
"https://Phi-3-5-vision-instruct-dcvov.eastus2.models.ai.azure.com"
|
) as mock_client:
|
||||||
).mock(return_value=httpx.Response(200, json=mock_response))
|
try:
|
||||||
|
await litellm.acompletion(
|
||||||
response = await litellm.acompletion(
|
|
||||||
model="azure_ai/Phi-3-5-vision-instruct-dcvov",
|
model="azure_ai/Phi-3-5-vision-instruct-dcvov",
|
||||||
api_base="https://Phi-3-5-vision-instruct-dcvov.eastus2.models.ai.azure.com",
|
api_base="https://Phi-3-5-vision-instruct-dcvov.eastus2.models.ai.azure.com",
|
||||||
messages=[
|
messages=[
|
||||||
|
@ -110,16 +85,19 @@ async def test_azure_ai_with_image_url(respx_mock: MockRouter):
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
api_key="fake-api-key",
|
api_key="fake-api-key",
|
||||||
|
client=client,
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
print(f"Error: {e}")
|
||||||
|
|
||||||
# Verify the request was made
|
# Verify the request was made
|
||||||
assert mock_request.called
|
mock_client.assert_called_once()
|
||||||
|
|
||||||
# Check the request body
|
# Check the request body
|
||||||
request_body = json.loads(mock_request.calls[0].request.content)
|
request_body = mock_client.call_args.kwargs
|
||||||
assert request_body == {
|
assert request_body["model"] == "Phi-3-5-vision-instruct-dcvov"
|
||||||
"model": "Phi-3-5-vision-instruct-dcvov",
|
assert request_body["messages"] == [
|
||||||
"messages": [
|
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": [
|
"content": [
|
||||||
|
@ -132,7 +110,4 @@ async def test_azure_ai_with_image_url(respx_mock: MockRouter):
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
}
|
|
||||||
|
|
||||||
print(f"response: {response}")
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue