mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-20 00:23:47 +00:00
fix gemini web search requests count (#17921)
* fix gemini web search requests count * filter queries
This commit is contained in:
@@ -1553,9 +1553,9 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
|
||||
for grounding_metadata_item in grounding_metadata:
|
||||
web_search_queries = grounding_metadata_item.get("webSearchQueries")
|
||||
if web_search_queries and web_search_requests:
|
||||
web_search_requests += len(web_search_queries)
|
||||
web_search_requests += len([q for q in web_search_queries if q])
|
||||
elif web_search_queries:
|
||||
web_search_requests = len(grounding_metadata)
|
||||
web_search_requests = len([q for q in web_search_queries if q])
|
||||
return web_search_requests
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -806,7 +806,7 @@ def test_vertex_ai_streaming_usage_web_search_calculation():
|
||||
{
|
||||
"content": {"parts": [{"text": "Hello"}]},
|
||||
"groundingMetadata": [
|
||||
{"webSearchQueries": ["What is the capital of France?"]}
|
||||
{"webSearchQueries": ["", "What is the capital of France?", "Capital of France"]}
|
||||
],
|
||||
}
|
||||
],
|
||||
@@ -821,7 +821,7 @@ def test_vertex_ai_streaming_usage_web_search_calculation():
|
||||
|
||||
usage: Usage = completed_response.usage
|
||||
assert usage.prompt_tokens_details.web_search_requests is not None
|
||||
assert usage.prompt_tokens_details.web_search_requests == 1
|
||||
assert usage.prompt_tokens_details.web_search_requests == 2
|
||||
|
||||
|
||||
def test_vertex_ai_transform_parts():
|
||||
|
||||
Reference in New Issue
Block a user