mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
make openai model O series conditional accept provider/model (#10591)
Registration and calls within the project are not consistent. This accepts either form. ref: #10566
This commit is contained in:
parent
500e6cddf5
commit
33953bd6c8
2 changed files with 52 additions and 8 deletions
|
|
@ -130,14 +130,9 @@ class OpenAIOSeriesConfig(OpenAIGPTConfig):
|
|||
)
|
||||
|
||||
def is_model_o_series_model(self, model: str) -> bool:
|
||||
if model in litellm.open_ai_chat_completion_models and (
|
||||
"o1" in model
|
||||
or "o3" in model
|
||||
or "o4"
|
||||
in model # [TODO] make this a more generic check (e.g. using `openai-o-series` as provider like gemini)
|
||||
):
|
||||
return True
|
||||
return False
|
||||
model = model.split("/")[-1] # could be "openai/o3" or "o3"
|
||||
return model in litellm.open_ai_chat_completion_models and any(
|
||||
model.startswith(pfx) for pfx in ("o1", "o3", "o4"))
|
||||
|
||||
def _transform_messages(
|
||||
self, messages: List[AllMessageValues], model: str
|
||||
|
|
|
|||
49
tests/litellm/llms/openai/test_o_series_transformation.py
Normal file
49
tests/litellm/llms/openai/test_o_series_transformation.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import pytest
|
||||
from litellm.llms.openai.chat.o_series_transformation import OpenAIOSeriesConfig
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model_name,expected",
|
||||
[
|
||||
# Valid O-series models
|
||||
("o1", True),
|
||||
("o3", True),
|
||||
("o4-mini", True),
|
||||
("o1-preview", True),
|
||||
("o3-mini", True),
|
||||
|
||||
# Valid O-series models with provider prefix
|
||||
("openai/o1", True),
|
||||
("openai/o3", True),
|
||||
("openai/o4-mini", True),
|
||||
("openai/o1-preview", True),
|
||||
("openai/o3-mini", True),
|
||||
|
||||
# Non-O-series models
|
||||
("gpt-4", False),
|
||||
("gpt-3.5-turbo", False),
|
||||
("claude-3-opus", False),
|
||||
|
||||
# Non-O-series models with provider prefix
|
||||
("openai/gpt-4", False),
|
||||
("openai/gpt-3.5-turbo", False),
|
||||
("anthropic/claude-3-opus", False),
|
||||
|
||||
# Edge cases
|
||||
("o", False), # Too short
|
||||
("o5", False), # Not a valid O-series model
|
||||
("o1-", False), # Invalid suffix
|
||||
("o3_", False), # Invalid suffix
|
||||
],
|
||||
)
|
||||
def test_is_model_o_series_model(model_name: str, expected: bool):
|
||||
"""
|
||||
Test that is_model_o_series_model correctly identifies O-series models.
|
||||
|
||||
Args:
|
||||
model_name: The model name to test
|
||||
expected: The expected result (True if it should be identified as an O-series model)
|
||||
"""
|
||||
config = OpenAIOSeriesConfig()
|
||||
assert config.is_model_o_series_model(model_name) == expected, \
|
||||
f"Expected {model_name} to be {'an O-series model' if expected else 'not an O-series model'}"
|
||||
Loading…
Add table
Reference in a new issue