Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor: extract _flatten_and_detect_file_refs helper, warn on ModuleNotFoundError

Chesarsb038c0714c6e
diff --git a/litellm/litellm_core_utils/get_model_cost_map.py b/litellm/litellm_core_utils/get_model_cost_map.py
index 244aaf08191..b24ffa8678a 100644
--- a/litellm/litellm_core_utils/get_model_cost_map.py
+++ b/litellm/litellm_core_utils/get_model_cost_map.py
@@ -50,8 +50,13 @@ class GetModelCostMap:
.read_text(encoding="utf-8")
)
return content
- except (FileNotFoundError, ModuleNotFoundError):
+ except FileNotFoundError:
pass
+ except ModuleNotFoundError:
+ verbose_logger.warning(
+ "LiteLLM: Could not load model cost map from package resources. "
+ "Falling back to project root."
+ )
current_dir = Path(__file__).parent.parent.parent
model_cost_map_path = current_dir / "model_prices_and_context_window.json"
diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
index 75923fb38e8..2a88789c31f 100644
--- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
+++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
@@ -3,7 +3,7 @@ Google AI Studio /batchEmbedContents Embeddings Endpoint
"""
import json
-from typing import Any, Dict, Literal, Optional, Union
+from typing import Any, Dict, List, Literal, Optional, Tuple, Union
import httpx
@@ -32,6 +32,21 @@ from .batch_embed_content_transformation import (
class GoogleBatchEmbeddings(VertexLLM):
+ @staticmethod
+ def _flatten_and_detect_file_refs(
+ input: EmbeddingInput,
+ ) -> Tuple[List[str], bool]:
+ """Flatten nested input lists and detect file references."""
+ input_list = [input] if isinstance(input, str) else input
+ flat_elements = [
+ e
+ for item in input_list
+ for e in (item if isinstance(item, list) else [item])
+ if isinstance(e, str)
+ ]
+ has_file_refs = any(_is_file_reference(e) for e in flat_elements)
+ return flat_elements, has_file_refs
+
def _resolve_file_references(
self,
input: EmbeddingInput,
@@ -214,14 +229,7 @@ class GoogleBatchEmbeddings(VertexLLM):
resolved_files=resolved_files,
)
else:
- input_list = [input] if isinstance(input, str) else input
- flat_elements = [
- e
- for item in input_list
- for e in (item if isinstance(item, list) else [item])
- if isinstance(e, str)
- ]
- has_file_refs = any(_is_file_reference(e) for e in flat_elements)
+ flat_elements, has_file_refs = self._flatten_and_detect_file_refs(input)
if has_file_refs and not api_key:
raise ValueError(
"An API key is required to resolve Gemini file references (files/...). "
@@ -323,14 +331,7 @@ class GoogleBatchEmbeddings(VertexLLM):
resolved_files=resolved_files,
)
else:
- input_list = [input] if isinstance(input, str) else input
- flat_elements = [
- e
- for item in input_list
- for e in (item if isinstance(item, list) else [item])
- if isinstance(e, str)
- ]
- has_file_refs = any(_is_file_reference(e) for e in flat_elements)
+ flat_elements, has_file_refs = self._flatten_and_detect_file_refs(input)
if has_file_refs and not api_key:
raise ValueError(
"An API key is required to resolve Gemini file references (files/...). "