mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix: preserve case-insensitive Perplexity header overrides
This commit is contained in:
parent
9cc14a6c49
commit
9dbb06ca29
2 changed files with 7 additions and 7 deletions
|
|
@ -37,7 +37,8 @@ class PerplexityChatConfig(OpenAIGPTConfig):
|
|||
api_key: str | None = None,
|
||||
api_base: str | None = None,
|
||||
) -> dict: # mutable-ok: matches the base chat transform signature
|
||||
headers.setdefault("X-Pplx-Integration", "litellm")
|
||||
if not any(name.lower() == "x-pplx-integration" for name in headers):
|
||||
headers["X-Pplx-Integration"] = "litellm"
|
||||
return super().validate_environment(
|
||||
headers, model, messages, optional_params, litellm_params, api_key, api_base
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ Tests the response transformation to extract citation tokens and search queries
|
|||
from Perplexity API responses.
|
||||
"""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
# Add the project root to Python path
|
||||
|
||||
from litellm import ModelResponse
|
||||
from litellm.llms.perplexity.chat.transformation import PerplexityChatConfig
|
||||
from litellm.types.utils import Usage
|
||||
|
|
@ -21,18 +19,19 @@ class TestPerplexityChatTransformation:
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
("headers", "expected"),
|
||||
[({}, "litellm"), ({"X-Pplx-Integration": "custom"}, "custom")],
|
||||
[({}, "litellm"), ({"x-pplx-integration": "custom"}, "custom")],
|
||||
)
|
||||
def test_integration_header_default_is_caller_overridable(self, headers, expected):
|
||||
result = PerplexityChatConfig().validate_environment(
|
||||
headers = PerplexityChatConfig().validate_environment(
|
||||
headers=headers,
|
||||
model="sonar",
|
||||
messages=[],
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
request = httpx.Request("POST", "https://api.perplexity.ai/chat/completions", headers=headers)
|
||||
|
||||
assert result["X-Pplx-Integration"] == expected
|
||||
assert request.headers.get_list("x-pplx-integration") == [expected]
|
||||
|
||||
def test_enhance_usage_with_citation_tokens(self):
|
||||
"""Test extraction of citation tokens from API response."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue