Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/video_endpoints/utils.py: 39%
44 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 12:01 +0000
1from typing import Any, Final
3import orjson
5from litellm.types.videos.utils import encode_character_id_with_provider
8def extract_model_from_target_model_names(target_model_names: Any) -> str | None:
9 if isinstance(target_model_names, str): 9 ↛ 10line 9 didn't jump to line 10 because the condition on line 9 was never true
10 target_model_names = [m.strip() for m in target_model_names.split(",") if m.strip()]
11 elif not isinstance(target_model_names, list): 11 ↛ 13line 11 didn't jump to line 13 because the condition on line 11 was always true
12 return None
13 return target_model_names[0] if target_model_names else None
16def video_reference_to_id(video_ref: object) -> str:
17 if isinstance(video_ref, dict): 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true
18 return video_ref.get("id", "")
19 if not isinstance(video_ref, str): 19 ↛ 21line 19 didn't jump to line 21 because the condition on line 19 was always true
20 return ""
21 try:
22 parsed_ref: Final = orjson.loads(video_ref)
23 except orjson.JSONDecodeError:
24 return video_ref
25 return parsed_ref.get("id", "") if isinstance(parsed_ref, dict) else video_ref
28def get_custom_provider_from_data(data: dict[str, Any]) -> str | None:
29 custom_llm_provider: Final = data.get("custom_llm_provider")
30 if custom_llm_provider: 30 ↛ 31line 30 didn't jump to line 31 because the condition on line 30 was never true
31 return custom_llm_provider
33 extra_body = data.get("extra_body")
34 if isinstance(extra_body, str): 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true
35 try:
36 parsed_extra_body: Final = orjson.loads(extra_body)
37 if isinstance(parsed_extra_body, dict):
38 extra_body = parsed_extra_body
39 except Exception:
40 extra_body = None
42 if isinstance(extra_body, dict): 42 ↛ 43line 42 didn't jump to line 43 because the condition on line 42 was never true
43 extra_body_custom_llm_provider: Final = extra_body.get("custom_llm_provider")
44 if isinstance(extra_body_custom_llm_provider, str):
45 return extra_body_custom_llm_provider
47 return None
50def encode_character_id_in_response(response: Any, custom_llm_provider: str, model_id: str | None) -> Any:
51 if isinstance(response, dict) and response.get("id"):
52 response["id"] = encode_character_id_with_provider(
53 character_id=response["id"],
54 provider=custom_llm_provider,
55 model_id=model_id,
56 )
57 return response
59 character_id: Final = getattr(response, "id", None)
60 if isinstance(character_id, str) and character_id:
61 response.id = encode_character_id_with_provider(
62 character_id=character_id,
63 provider=custom_llm_provider,
64 model_id=model_id,
65 )
66 return response