mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-23 05:34:41 +00:00
Merge 69148759b9 into c58fc0c996
This commit is contained in:
commit
48d99b3a39
2 changed files with 22 additions and 5 deletions
|
|
@ -158,7 +158,6 @@ class HuggingFaceRerankConfig(BaseRerankConfig):
|
|||
# HuggingFace API expects return_text parameter, corresponding to our return_documents parameter
|
||||
request_body: Final = {
|
||||
"raw_scores": False,
|
||||
"truncate": False,
|
||||
"truncation_direction": "Right",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Based on the test patterns from other rerank providers and the current HuggingFa
|
|||
|
||||
import asyncio
|
||||
import json
|
||||
from typing import Final
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
|
@ -275,10 +276,29 @@ def test_request_transformation():
|
|||
assert request_body["top_n"] == 2
|
||||
assert request_body["return_text"] is True
|
||||
assert request_body["raw_scores"] is False
|
||||
assert request_body["truncate"] is False
|
||||
assert "truncate" not in request_body
|
||||
assert request_body["truncation_direction"] == "Right"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("truncate", [True, False, None])
|
||||
def test_request_transformation_preserves_explicit_truncation(truncate: bool | None) -> None:
|
||||
from litellm.llms.huggingface.rerank.transformation import HuggingFaceRerankConfig
|
||||
|
||||
request_body: Final = HuggingFaceRerankConfig().transform_rerank_request(
|
||||
model="test",
|
||||
optional_rerank_params={"query": "hello", "texts": ["world"], "truncate": truncate},
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert request_body == {
|
||||
"query": "hello",
|
||||
"texts": ["world"],
|
||||
"raw_scores": False,
|
||||
"truncate": truncate,
|
||||
"truncation_direction": "Right",
|
||||
}
|
||||
|
||||
|
||||
def test_response_transformation():
|
||||
"""Test response transformation logic."""
|
||||
from litellm.llms.huggingface.rerank.transformation import HuggingFaceRerankConfig
|
||||
|
|
@ -385,13 +405,11 @@ def test_huggingface_rerank_request_payload(mock_post):
|
|||
"texts": ["hello", "world"],
|
||||
"raw_scores": False,
|
||||
"return_text": True,
|
||||
"truncate": False,
|
||||
"truncation_direction": "Right",
|
||||
"top_n": 2,
|
||||
}
|
||||
|
||||
for key, value in expected_request.items():
|
||||
assert request_data[key] == value
|
||||
assert request_data == expected_request
|
||||
|
||||
assert response.results is not None
|
||||
assert len(response.results) == 2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue