Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

add o1 reasoning tests

Ishaan Jafff5e9e9fc9ae4
diff --git a/litellm/llms/OpenAI/o1_reasoning.py b/litellm/llms/OpenAI/o1_reasoning.py
index c2c48456f63..03038b7ce67 100644
--- a/litellm/llms/OpenAI/o1_reasoning.py
+++ b/litellm/llms/OpenAI/o1_reasoning.py
@@ -5,7 +5,7 @@ https://platform.openai.com/docs/guides/reasoning
Translations handled by LiteLLM:
- modalities: image => drop param (if user opts in to dropping param)
-- role: system ==> translate to role assistant
+- role: system ==> translate to role 'user'
- streaming => faked by LiteLLM
- Tools, response_format => drop param (if user opts in to dropping param)
- Logprobs => drop param (if user opts in to dropping param)
diff --git a/litellm/tests/test_openai_o1.py b/litellm/tests/test_openai_o1.py
new file mode 100644
index 00000000000..f08c71ca98a
--- /dev/null
+++ b/litellm/tests/test_openai_o1.py
@@ -0,0 +1,56 @@
+import json
+from datetime import datetime
+from unittest.mock import AsyncMock
+
+import httpx
+import pytest
+from respx import MockRouter
+
+import litellm
+from litellm import Choices, Message, ModelResponse
+
+
+async def test_o1_handle_system_role(respx_mock: MockRouter):
+ """
+ Tests that:
+ - max_tokens is translated to 'max_completion_tokens'
+ - role 'system' is translated to 'user'
+ """
+ litellm.set_verbose = True
+
+ mock_response = ModelResponse(
+ id="cmpl-mock",
+ choices=[Choices(message=Message(content="Mocked response", role="assistant"))],
+ created=int(datetime.now().timestamp()),
+ model="o1-preview",
+ )
+
+ mock_request = respx_mock.post("https://api.openai.com/v1/chat/completions").mock(
+ return_value=httpx.Response(200, json=mock_response.dict())
+ )
+
+ response = await litellm.acompletion(
+ model="o1-preview",
+ max_tokens=10,
+ messages=[{"role": "system", "content": "Hello!"}],
+ )
+
+ assert mock_request.called
+ request_body = json.loads(mock_request.calls[0].request.content)
+
+ print("request_body: ", request_body)
+
+ assert request_body == {
+ "model": "o1-preview",
+ "max_completion_tokens": 10,
+ "messages": [{"role": "user", "content": "Hello!"}],
+ }
+
+ print(f"response: {response}")
+ assert isinstance(response, ModelResponse)
+ assert response.choices[0].message.content == "Mocked response"
+
+
+# ... existing code ...