mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
feat(perplexity): add integration attribution header
This commit is contained in:
parent
de53283356
commit
dbb0a5f97c
2 changed files with 30 additions and 0 deletions
|
|
@ -27,6 +27,21 @@ class PerplexityChatConfig(OpenAIGPTConfig):
|
|||
dynamic_api_key = api_key or get_secret_str("PERPLEXITYAI_API_KEY") or get_secret_str("PERPLEXITY_API_KEY")
|
||||
return api_base, dynamic_api_key
|
||||
|
||||
def validate_environment(
|
||||
self,
|
||||
headers: dict,
|
||||
model: str,
|
||||
messages: list[AllMessageValues],
|
||||
optional_params: dict,
|
||||
litellm_params: dict,
|
||||
api_key: str | None = None,
|
||||
api_base: str | None = None,
|
||||
) -> dict:
|
||||
headers.setdefault("X-Pplx-Integration", "litellm")
|
||||
return super().validate_environment(
|
||||
headers, model, messages, optional_params, litellm_params, api_key, api_base
|
||||
)
|
||||
|
||||
def get_supported_openai_params(self, model: str) -> list:
|
||||
"""
|
||||
Perplexity supports a subset of OpenAI params
|
||||
|
|
|
|||
|
|
@ -19,6 +19,21 @@ from litellm.types.utils import Usage
|
|||
class TestPerplexityChatTransformation:
|
||||
"""Test suite for Perplexity chat transformation functionality."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("headers", "expected"),
|
||||
[({}, "litellm"), ({"X-Pplx-Integration": "custom"}, "custom")],
|
||||
)
|
||||
def test_integration_header_default_is_caller_overridable(self, headers, expected):
|
||||
result = PerplexityChatConfig().validate_environment(
|
||||
headers=headers,
|
||||
model="sonar",
|
||||
messages=[],
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
|
||||
assert result["X-Pplx-Integration"] == expected
|
||||
|
||||
def test_enhance_usage_with_citation_tokens(self):
|
||||
"""Test extraction of citation tokens from API response."""
|
||||
config = PerplexityChatConfig()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue