mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
Complete o3 model support (#8183)
* fix(o_series_transformation.py): add 'reasoning_effort' as o series model param Closes https://github.com/BerriAI/litellm/issues/8182 * fix(main.py): ensure `reasoning_effort` is a mapped openai param * refactor(azure/): rename o1_[x] files to o_series_[x] * refactor(base_llm_unit_tests.py): refactor testing for o series reasoning effort * test(test_azure_o_series.py): have azure o series tests correctly inherit from base o series model tests * feat(base_utils.py): support translating 'developer' role to 'system' role for non-openai providers Makes it easy to switch from openai to anthropic * fix: fix linting errors * fix(base_llm_unit_tests.py): fix test * fix(main.py): add missing param
This commit is contained in:
parent
e4566d7b1c
commit
1105e35538
15 changed files with 230 additions and 11 deletions
|
@ -18,9 +18,11 @@ from litellm.utils import (
|
|||
get_supported_openai_params,
|
||||
get_optional_params,
|
||||
)
|
||||
from typing import Union
|
||||
|
||||
# test_example.py
|
||||
from abc import ABC, abstractmethod
|
||||
from openai import OpenAI
|
||||
|
||||
|
||||
def _usage_format_tests(usage: litellm.Usage):
|
||||
|
@ -70,6 +72,34 @@ class BaseLLMChatTest(ABC):
|
|||
"""Must return the base completion call args"""
|
||||
pass
|
||||
|
||||
def test_developer_role_translation(self):
|
||||
"""
|
||||
Test that the developer role is translated correctly for non-OpenAI providers.
|
||||
|
||||
Translate `developer` role to `system` role for non-OpenAI providers.
|
||||
"""
|
||||
base_completion_call_args = self.get_base_completion_call_args()
|
||||
messages = [
|
||||
{
|
||||
"role": "developer",
|
||||
"content": "Be a good bot!",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [{"type": "text", "text": "Hello, how are you?"}],
|
||||
},
|
||||
]
|
||||
try:
|
||||
response = self.completion_function(
|
||||
**base_completion_call_args,
|
||||
messages=messages,
|
||||
)
|
||||
assert response is not None
|
||||
except litellm.InternalServerError:
|
||||
pytest.skip("Model is overloaded")
|
||||
|
||||
assert response.choices[0].message.content is not None
|
||||
|
||||
def test_content_list_handling(self):
|
||||
"""Check if content list is supported by LLM API"""
|
||||
base_completion_call_args = self.get_base_completion_call_args()
|
||||
|
@ -605,3 +635,72 @@ class BaseLLMChatTest(ABC):
|
|||
cost = completion_cost(response)
|
||||
|
||||
assert cost > 0
|
||||
|
||||
|
||||
class BaseOSeriesModelsTest(ABC): # test across azure/openai
|
||||
@abstractmethod
|
||||
def get_base_completion_call_args(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client(self) -> OpenAI:
|
||||
pass
|
||||
|
||||
def test_reasoning_effort(self):
|
||||
"""Test that reasoning_effort is passed correctly to the model"""
|
||||
|
||||
from litellm import completion
|
||||
|
||||
client = self.get_client()
|
||||
|
||||
completion_args = self.get_base_completion_call_args()
|
||||
|
||||
with patch.object(
|
||||
client.chat.completions.with_raw_response, "create"
|
||||
) as mock_client:
|
||||
try:
|
||||
completion(
|
||||
**completion_args,
|
||||
reasoning_effort="low",
|
||||
messages=[{"role": "user", "content": "Hello!"}],
|
||||
client=client,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
mock_client.assert_called_once()
|
||||
request_body = mock_client.call_args.kwargs
|
||||
print("request_body: ", request_body)
|
||||
assert request_body["reasoning_effort"] == "low"
|
||||
|
||||
def test_developer_role_translation(self):
|
||||
"""Test that developer role is translated correctly to system role for non-OpenAI providers"""
|
||||
from litellm import completion
|
||||
|
||||
client = self.get_client()
|
||||
|
||||
completion_args = self.get_base_completion_call_args()
|
||||
|
||||
with patch.object(
|
||||
client.chat.completions.with_raw_response, "create"
|
||||
) as mock_client:
|
||||
try:
|
||||
completion(
|
||||
**completion_args,
|
||||
reasoning_effort="low",
|
||||
messages=[
|
||||
{"role": "developer", "content": "Be a good bot!"},
|
||||
{"role": "user", "content": "Hello!"},
|
||||
],
|
||||
client=client,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
mock_client.assert_called_once()
|
||||
request_body = mock_client.call_args.kwargs
|
||||
print("request_body: ", request_body)
|
||||
assert (
|
||||
request_body["messages"][0]["role"] == "developer"
|
||||
), "Got={} instead of system".format(request_body["messages"][0]["role"])
|
||||
assert request_body["messages"][0]["content"] == "Be a good bot!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue