Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/llm_translation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import importlib

import pytest
from openai.types.chat import ChatCompletion


import litellm # noqa: E402
Expand All @@ -29,6 +30,26 @@
from tests.fake_openai_endpoint import ensure_fake_openai_endpoint # noqa: E402


@pytest.fixture
def chat_completion_response() -> ChatCompletion:
return ChatCompletion.model_validate(
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello there"},
"finish_reason": "stop",
}
],
"usage": {"prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21},
}
)


@pytest.fixture(scope="session", autouse=True)
def fake_openai_endpoint():
ensure_fake_openai_endpoint()
Expand Down
5 changes: 4 additions & 1 deletion tests/llm_translation/test_azure_o_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ def test_azure_o_series_routing():


@patch("litellm.main.azure_o1_chat_completions._get_openai_client")
def test_openai_o_series_max_retries_0(mock_get_openai_client):
def test_openai_o_series_max_retries_0(mock_get_openai_client, chat_completion_response):
import litellm

litellm.set_verbose = True
mock_get_openai_client.return_value.chat.completions.with_raw_response.create.return_value.parse.return_value = (
chat_completion_response
)
response = litellm.completion(
model="azure/o1-preview",
messages=[{"role": "user", "content": "hi"}],
Expand Down
3 changes: 2 additions & 1 deletion tests/llm_translation/test_azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class ResponseFormat(BaseModel):
# "2024-02-15-preview",
],
)
def test_azure_gpt_4o_with_tool_call_and_response_format(api_version):
def test_azure_gpt_4o_with_tool_call_and_response_format(api_version, chat_completion_response):
from litellm import completion
from typing import Optional
from pydantic import BaseModel
Expand Down Expand Up @@ -335,6 +335,7 @@ class InvestigationOutput(BaseModel):
]

with patch.object(client.chat.completions.with_raw_response, "create") as mock_post:
mock_post.return_value.parse.return_value = chat_completion_response
response = litellm.completion(
model="azure/gpt-4.1-mini",
messages=[
Expand Down
5 changes: 4 additions & 1 deletion tests/llm_translation/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ def test_prompt_caching(self):


@patch("litellm.main.openai_chat_completions._get_openai_client")
def test_openai_max_retries_0(mock_get_openai_client):
def test_openai_max_retries_0(mock_get_openai_client, chat_completion_response):
import litellm

litellm.set_verbose = True
mock_get_openai_client.return_value.chat.completions.with_raw_response.create.return_value.parse.return_value = (
chat_completion_response
)
response = litellm.completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "hi"}],
Expand Down
2 changes: 1 addition & 1 deletion tests/local_testing/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3999,7 +3999,7 @@ def test_completion_novita_ai():
openai_client = OpenAI(api_key="fake-key")

with patch.object(
openai_client.chat.completions, "create", new=MagicMock()
openai_client.chat.completions, "create", new=MagicMock(return_value=_openai_mock_response())
) as mock_call:
try:
completion(
Expand Down
Loading