mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
litellm_fix(mypy): fix type errors across multiple files
Fixes 23 mypy errors: - opentelemetry.py: Fix callback_name str|None to str - files/main.py: Replace wildcard import to avoid uuid redefinition - responses transformation: Fix Dict type annotations - gemini/files: Fix validate_environment signature, status Literal type - experimental_mcp_client: Add type:ignore for conditional import - completion_extras transformation: Add type:ignore for tools append - common_request_processing: Add type:ignore for route_type Literal - search endpoints: Add type:ignore for TypedDict key access - files_endpoints: Convert FormData to dict for form_data param - mcp_server_manager: Add type:ignore for conditional function variant - mcp_management_endpoints: Same conditional function fix - key_management_endpoints: Add type:ignore for prisma_client arg - vector_stores endpoints: Add missing team_id and user_id args - cache_coordinator: Add type:ignore for func-returns-value
This commit is contained in:
parent
14a5706131
commit
3b9c095bd4
14 changed files with 21 additions and 18 deletions
|
|
@ -282,6 +282,8 @@ async def get_vector_store_info(
|
|||
updated_at=vector_store.get("updated_at") or None,
|
||||
litellm_credential_name=vector_store.get("litellm_credential_name"),
|
||||
litellm_params=vector_store.get("litellm_params") or None,
|
||||
team_id=vector_store.get("team_id"),
|
||||
user_id=vector_store.get("user_id"),
|
||||
)
|
||||
return {"vector_store": vector_store_pydantic_obj}
|
||||
|
||||
|
|
|
|||
|
|
@ -748,7 +748,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
|
|||
if isinstance(web_search_options, dict):
|
||||
web_search_tool.update(web_search_options)
|
||||
|
||||
responses_api_request["tools"].append(web_search_tool)
|
||||
responses_api_request["tools"].append(web_search_tool) # type: ignore[union-attr, arg-type]
|
||||
|
||||
def _transform_response_format_to_text_format(
|
||||
self, response_format: Union[Dict[str, Any], Any]
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from mcp.client.stdio import stdio_client
|
|||
try:
|
||||
from mcp.client.streamable_http import streamable_http_client # type: ignore
|
||||
except ImportError:
|
||||
streamable_http_client = None
|
||||
streamable_http_client = None # type: ignore[assignment]
|
||||
from mcp.types import CallToolRequestParams as MCPCallToolRequestParams
|
||||
from mcp.types import CallToolResult as MCPCallToolResult
|
||||
from mcp.types import (
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ from litellm.types.llms.openai import (
|
|||
HttpxBinaryResponseContent,
|
||||
OpenAIFileObject,
|
||||
)
|
||||
from litellm.types.router import *
|
||||
import litellm.types.router # noqa: F401 - side effects needed
|
||||
from litellm.types.utils import (
|
||||
OPENAI_COMPATIBLE_BATCH_AND_FILES_PROVIDERS,
|
||||
LlmProviders,
|
||||
|
|
|
|||
|
|
@ -1631,7 +1631,7 @@ class OpenTelemetry(CustomLogger):
|
|||
)
|
||||
|
||||
except Exception as e:
|
||||
self.handle_callback_failure(callback_name= self.callback_name)
|
||||
self.handle_callback_failure(callback_name=self.callback_name or "opentelemetry")
|
||||
verbose_logger.exception(
|
||||
"OpenTelemetry logging error in set_attributes %s", str(e)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Supports writing files to Google AI Studio Files API.
|
|||
For vertex ai, check out the vertex_ai/files/handler.py file.
|
||||
"""
|
||||
import time
|
||||
from typing import List, Optional
|
||||
from typing import List, Literal, Optional, cast
|
||||
|
||||
import httpx
|
||||
from openai.types.file_deleted import FileDeleted
|
||||
|
|
@ -37,12 +37,13 @@ class GoogleAIStudioFilesHandler(GeminiModelInfo, BaseFilesConfig):
|
|||
|
||||
def validate_environment(
|
||||
self,
|
||||
api_key: Optional[str],
|
||||
headers: dict,
|
||||
model: str,
|
||||
messages: list,
|
||||
optional_params: dict,
|
||||
litellm_params: dict,
|
||||
api_key: Optional[str] = None,
|
||||
api_base: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""
|
||||
Validate environment and add Gemini API key to headers.
|
||||
|
|
@ -236,7 +237,7 @@ class GoogleAIStudioFilesHandler(GeminiModelInfo, BaseFilesConfig):
|
|||
|
||||
# Map Gemini state to OpenAI status
|
||||
gemini_state = response_json.get("state", "STATE_UNSPECIFIED")
|
||||
status = "uploaded" # Default
|
||||
status: Literal["uploaded", "processed", "error"] = "uploaded" # Default
|
||||
if gemini_state == "ACTIVE":
|
||||
status = "processed"
|
||||
elif gemini_state == "FAILED":
|
||||
|
|
@ -301,7 +302,7 @@ class GoogleAIStudioFilesHandler(GeminiModelInfo, BaseFilesConfig):
|
|||
url = f"{api_base}/v1beta/{file_name}"
|
||||
|
||||
# Add API key as header (Google AI Studio uses x-goog-api-key header)
|
||||
params = {}
|
||||
params: dict = {}
|
||||
|
||||
return url, params
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ try:
|
|||
except ImportError:
|
||||
SEP_986_URL = "https://github.com/modelcontextprotocol/protocol/blob/main/proposals/0001-tool-name-validation.md"
|
||||
|
||||
def validate_tool_name(name: str):
|
||||
def validate_tool_name(name: str): # type: ignore[misc]
|
||||
from pydantic import BaseModel
|
||||
|
||||
class MockResult(BaseModel):
|
||||
|
|
|
|||
|
|
@ -751,7 +751,7 @@ class ProxyBaseLLMRequestProcessing:
|
|||
# Do not change this - it should be a constant time fetch - ALWAYS
|
||||
llm_call = await route_request(
|
||||
data=self.data,
|
||||
route_type=route_type,
|
||||
route_type=route_type, # type: ignore[arg-type]
|
||||
llm_router=llm_router,
|
||||
user_model=user_model,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class EventDrivenCacheCoordinator:
|
|||
Returns the value from cache or from load_fn, or None if load failed or
|
||||
cache was still empty after waiting.
|
||||
"""
|
||||
value = await self._get_cached(cache_key, cache)
|
||||
value = await self._get_cached(cache_key, cache) # type: ignore[func-returns-value]
|
||||
if value is not None:
|
||||
self._log_cache_hit(value)
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -1544,7 +1544,7 @@ async def _process_single_key_update(
|
|||
await TeamMemberPermissionChecks.can_team_member_execute_key_management_endpoint(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
route=KeyManagementRoutes.KEY_UPDATE,
|
||||
prisma_client=prisma_client,
|
||||
prisma_client=prisma_client, # type: ignore[arg-type]
|
||||
existing_key_row=existing_key_row,
|
||||
user_api_key_cache=user_api_key_cache,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ if MCP_AVAILABLE:
|
|||
from mcp.shared.tool_name_validation import validate_tool_name # type: ignore
|
||||
except ImportError:
|
||||
|
||||
def validate_tool_name(name: str):
|
||||
def validate_tool_name(name: str): # type: ignore[misc]
|
||||
from pydantic import BaseModel
|
||||
|
||||
class MockResult(BaseModel):
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ async def create_file( # noqa: PLR0915
|
|||
expires_after = None
|
||||
form_data = await request.form()
|
||||
litellm_metadata = extract_nested_form_metadata(
|
||||
form_data=form_data,
|
||||
form_data=dict(form_data),
|
||||
prefix="litellm_metadata["
|
||||
)
|
||||
expires_after_anchor = form_data.get("expires_after[anchor]")
|
||||
|
|
|
|||
|
|
@ -245,8 +245,8 @@ async def list_search_tools(
|
|||
}
|
||||
|
||||
# Add description if available
|
||||
if "search_tool_info" in tool and tool["search_tool_info"]:
|
||||
description = tool["search_tool_info"].get("description")
|
||||
if "search_tool_info" in tool and tool["search_tool_info"]: # type: ignore[typeddict-item]
|
||||
description = tool["search_tool_info"].get("description") # type: ignore[typeddict-item]
|
||||
if description:
|
||||
tool_info["description"] = description
|
||||
|
||||
|
|
|
|||
|
|
@ -1743,7 +1743,7 @@ class LiteLLMCompletionResponsesConfig:
|
|||
and usage.prompt_tokens_details is not None
|
||||
):
|
||||
prompt_details = usage.prompt_tokens_details
|
||||
input_details_dict: Dict[str, Optional[int]] = {}
|
||||
input_details_dict: Dict[str, int] = {}
|
||||
|
||||
if (
|
||||
hasattr(prompt_details, "cached_tokens")
|
||||
|
|
@ -1776,7 +1776,7 @@ class LiteLLMCompletionResponsesConfig:
|
|||
and usage.completion_tokens_details is not None
|
||||
):
|
||||
completion_details = usage.completion_tokens_details
|
||||
output_details_dict: Dict[str, Optional[int]] = {}
|
||||
output_details_dict: Dict[str, int] = {}
|
||||
if (
|
||||
hasattr(completion_details, "reasoning_tokens")
|
||||
and completion_details.reasoning_tokens is not None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue