mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-12 17:04:30 +00:00
* Handle azure deepseek reasoning response (#8288) * Handle deepseek reasoning response * Add helper method + unit test * Fix: Follow infinity api url format (#8346) * Follow infinity api url format * Update test_infinity.py * fix(infinity/transformation.py): fix linting error --------- Co-authored-by: vibhavbhat <vibhavb00@gmail.com> Co-authored-by: Hao Shan <53949959+haoshan98@users.noreply.github.com>
This commit is contained in:
@@ -864,6 +864,18 @@ def test_convert_model_response_object():
|
||||
== '{"type":"error","error":{"type":"invalid_request_error","message":"Output blocked by content filtering policy"}}'
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"content, expected_reasoning, expected_content",
|
||||
[
|
||||
(None, None, None),
|
||||
("<think>I am thinking here</think>The sky is a canvas of blue", "I am thinking here", "The sky is a canvas of blue"),
|
||||
("I am a regular response", None, "I am a regular response"),
|
||||
|
||||
]
|
||||
)
|
||||
def test_parse_content_for_reasoning(content, expected_reasoning, expected_content):
|
||||
assert(litellm.utils._parse_content_for_reasoning(content) == (expected_reasoning, expected_content))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model, expected_bool",
|
||||
|
||||
@@ -13,7 +13,7 @@ import litellm.types.utils
|
||||
from litellm.llms.anthropic.chat import ModelResponseIterator
|
||||
import httpx
|
||||
import json
|
||||
from respx import MockRouter
|
||||
from litellm.llms.custom_httpx.http_handler import HTTPHandler
|
||||
|
||||
load_dotenv()
|
||||
import io
|
||||
@@ -184,3 +184,45 @@ def test_completion_azure_ai_command_r():
|
||||
pass
|
||||
except Exception as e:
|
||||
pytest.fail(f"Error occurred: {e}")
|
||||
|
||||
def test_azure_deepseek_reasoning_content():
|
||||
import json
|
||||
|
||||
client = HTTPHandler()
|
||||
|
||||
with patch.object(client, "post") as mock_post:
|
||||
mock_response = MagicMock()
|
||||
|
||||
mock_response.text = json.dumps(
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"finish_reason": "stop",
|
||||
"index": 0,
|
||||
"message": {
|
||||
"content": "<think>I am thinking here</think>\n\nThe sky is a canvas of blue",
|
||||
"role": "assistant",
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
mock_response.status_code = 200
|
||||
# Add required response attributes
|
||||
mock_response.headers = {"Content-Type": "application/json"}
|
||||
mock_response.json = lambda: json.loads(mock_response.text)
|
||||
mock_post.return_value = mock_response
|
||||
|
||||
|
||||
response = litellm.completion(
|
||||
model='azure_ai/deepseek-r1',
|
||||
messages=[{"role": "user", "content": "Hello, world!"}],
|
||||
api_base="https://litellm8397336933.services.ai.azure.com/models/chat/completions",
|
||||
api_key="my-fake-api-key",
|
||||
client=client
|
||||
)
|
||||
|
||||
print(response)
|
||||
assert(response.choices[0].message.reasoning_content == "I am thinking here")
|
||||
assert(response.choices[0].message.content == "\n\nThe sky is a canvas of blue")
|
||||
|
||||
@@ -69,7 +69,7 @@ async def test_infinity_rerank():
|
||||
_url = mock_post.call_args.kwargs["url"]
|
||||
print("Arguments passed to API=", args_to_api)
|
||||
print("url = ", _url)
|
||||
assert _url == "https://api.infinity.ai/v1/rerank"
|
||||
assert _url == "https://api.infinity.ai/rerank"
|
||||
|
||||
request_data = json.loads(args_to_api)
|
||||
assert request_data["query"] == expected_payload["query"]
|
||||
@@ -133,7 +133,7 @@ async def test_infinity_rerank_with_env(monkeypatch):
|
||||
_url = mock_post.call_args.kwargs["url"]
|
||||
print("Arguments passed to API=", args_to_api)
|
||||
print("url = ", _url)
|
||||
assert _url == "https://env.infinity.ai/v1/rerank"
|
||||
assert _url == "https://env.infinity.ai/rerank"
|
||||
|
||||
request_data = json.loads(args_to_api)
|
||||
assert request_data["query"] == expected_payload["query"]
|
||||
|
||||
Reference in New Issue
Block a user