mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-04 01:48:57 +00:00
* refactor(types): prove runtime types at harness, search, rag and client boundaries Replace Any with adapter-validated types in the litellm.agent() harness, the search provider transformations, RAG ingestion and query, the vector store pre-call hook and registry, the galileo and opik logging integrations and the proxy client CLI. Each boundary gets unit tests for well-formed and malformed payloads. * chore(typing): prove types at more provider boundaries and restore search transformations Second pass over a2a, embedding, rerank, image, audio and small provider modules. Search transformations go back to their previous form because validating their response bodies would change the proxy status for malformed upstream bodies from 400 to 500. * refactor(types): prove types at logging, files, rerank, image, audio and management boundaries Replace Any with validated or annotation-only types in 37 more files: logging integrations, token counters, provider files/rerank/image generation/audio transcription transformations, pass-through logging handlers and management endpoints. No proxy HTTP status or error type changes. * refactor(types): prove types at repository, spend, files and router boundaries Replace Any with repository table accessors, validated mappings and annotation-only types in 33 more files: Prisma repositories, the enterprise batch and responses cost checkers, budget reservation, files endpoints, management endpoints, the policy registry, the adaptive and complexity routers and the secret managers. No proxy HTTP status or error type changes. * test(types): run the aiohttp transformation test in-process and cover repository row conversion The aiohttp chat transformation test no longer starts a server. It feeds the transformation a response whose json() returns the body under test. The proxy unit shards now exercise stored model rows whose params are JSON strings and the object permission create and update paths.
116 lines
3.5 KiB
Python
116 lines
3.5 KiB
Python
import pytest
|
|
|
|
from litellm.integrations.opik.opik_payload_builder.extractors import (
|
|
apply_proxy_header_overrides,
|
|
extract_opik_metadata,
|
|
)
|
|
|
|
|
|
def test_extract_opik_metadata_fills_missing_keys_from_auth_metadata():
|
|
litellm_metadata = {"opik": {"project_name": "my-proj"}}
|
|
standard_logging_metadata = {
|
|
"user_api_key_auth_metadata": {
|
|
"opik": {
|
|
"workspace": "auth-workspace",
|
|
"project_name": "auth-project",
|
|
}
|
|
}
|
|
}
|
|
|
|
result = extract_opik_metadata(
|
|
litellm_metadata=litellm_metadata,
|
|
standard_logging_metadata=standard_logging_metadata,
|
|
)
|
|
|
|
assert result == {
|
|
"project_name": "my-proj",
|
|
"workspace": "auth-workspace",
|
|
}
|
|
|
|
|
|
def test_extract_opik_metadata_request_metadata_overrides_auth_metadata():
|
|
litellm_metadata = {
|
|
"opik": {
|
|
"workspace": "request-workspace",
|
|
"thread_id": "request-thread",
|
|
}
|
|
}
|
|
standard_logging_metadata = {
|
|
"user_api_key_auth_metadata": {
|
|
"opik": {
|
|
"workspace": "auth-workspace",
|
|
"thread_id": "auth-thread",
|
|
"project_name": "auth-project",
|
|
}
|
|
}
|
|
}
|
|
|
|
result = extract_opik_metadata(
|
|
litellm_metadata=litellm_metadata,
|
|
standard_logging_metadata=standard_logging_metadata,
|
|
)
|
|
|
|
assert result == {
|
|
"workspace": "request-workspace",
|
|
"thread_id": "request-thread",
|
|
"project_name": "auth-project",
|
|
}
|
|
|
|
|
|
def test_extract_opik_metadata_requester_metadata_overrides_all_other_sources():
|
|
litellm_metadata = {"opik": {"project_name": "request-project"}}
|
|
standard_logging_metadata = {
|
|
"user_api_key_auth_metadata": {
|
|
"opik": {
|
|
"workspace": "auth-workspace",
|
|
"project_name": "auth-project",
|
|
}
|
|
},
|
|
"requester_metadata": {
|
|
"opik": {
|
|
"workspace": "requester-workspace",
|
|
"thread_id": "requester-thread",
|
|
"project_name": "requester-project",
|
|
}
|
|
},
|
|
}
|
|
|
|
result = extract_opik_metadata(
|
|
litellm_metadata=litellm_metadata,
|
|
standard_logging_metadata=standard_logging_metadata,
|
|
)
|
|
|
|
assert result == {
|
|
"project_name": "requester-project",
|
|
"workspace": "requester-workspace",
|
|
"thread_id": "requester-thread",
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("opik_tags_header", "expected_tags"),
|
|
[
|
|
('["from-header", "second"]', ["from-request", "from-header", "second"]),
|
|
('["text", 7, null, {"nested": [1]}]', ["from-request", "text", 7, None, {"nested": [1]}]),
|
|
("[]", ["from-request"]),
|
|
('{"not": "a list"}', ["from-request"]),
|
|
('"not-a-list"', ["from-request"]),
|
|
("null", ["from-request"]),
|
|
("not json", ["from-request"]),
|
|
],
|
|
)
|
|
def test_opik_tags_header_adds_tags_only_when_it_is_a_json_list(opik_tags_header: str, expected_tags: list[object]):
|
|
overrides = apply_proxy_header_overrides("project", ["from-request"], None, {"opik_tags": opik_tags_header})
|
|
|
|
assert overrides == ("project", expected_tags, None)
|
|
|
|
|
|
def test_opik_headers_override_the_project_name_and_thread_id():
|
|
overrides = apply_proxy_header_overrides(
|
|
"project",
|
|
["from-request"],
|
|
"thread-from-request",
|
|
{"opik_project_name": "header-project", "opik_thread_id": "header-thread", "opik_tags": "", "x-other": "1"},
|
|
)
|
|
|
|
assert overrides == ("header-project", ["from-request"], "header-thread")
|