fix MYPY errors

This commit is contained in:
Ishaan Jaff 2025-09-06 13:57:38 -07:00
parent 1227b54fa6
commit 7dce6a81a8

View file

@ -29,7 +29,7 @@ from litellm.types.passthrough_endpoints.pass_through_endpoints import (
EndpointType,
PassthroughStandardLoggingPayload,
)
from litellm.types.utils import LlmProviders, PassthroughCallTypes
from litellm.types.utils import ImageResponse, LlmProviders, PassthroughCallTypes
from litellm.utils import ModelResponse, TextCompletionResponse
@ -42,8 +42,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
def llm_provider_name(self) -> LlmProviders:
return LlmProviders.OPENAI
@staticmethod
def get_provider_config(model: str) -> OpenAIConfigType:
def get_provider_config(self, model: str) -> OpenAIConfigType:
"""Get OpenAI provider configuration for the given model."""
return OpenAIConfig()
@ -92,8 +91,8 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
and "/v1/images/edits" in parsed_url.path
)
@staticmethod
def _get_user_from_metadata(
self,
passthrough_logging_payload: PassthroughStandardLoggingPayload,
) -> Optional[str]:
"""Extract user information from passthrough logging payload."""
@ -239,13 +238,12 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
try:
response_cost = 0.0
litellm_model_response = None
litellm_model_response: Optional[Union[ModelResponse, TextCompletionResponse, ImageResponse]] = None
handler_instance = OpenAIPassthroughLoggingHandler()
if is_chat_completions:
# Handle chat completions with existing logic
provider_config = OpenAIPassthroughLoggingHandler.get_provider_config(
model=model
)
provider_config = handler_instance.get_provider_config(model=model)
litellm_model_response = provider_config.transform_response(
raw_response=httpx_response,
model_response=litellm.ModelResponse(),
@ -284,8 +282,6 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
except Exception:
pass
# Create a simple response object for logging
from litellm.types.utils import ImageResponse
litellm_model_response = ImageResponse(
data=response_body.get("data", []),
model=model,
@ -311,8 +307,6 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
except Exception:
pass
# Create a simple response object for logging
from litellm.types.utils import ImageResponse
litellm_model_response = ImageResponse(
data=response_body.get("data", []),
model=model,
@ -332,7 +326,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
PassthroughStandardLoggingPayload
] = kwargs.get("passthrough_logging_payload")
if passthrough_logging_payload:
user = OpenAIPassthroughLoggingHandler._get_user_from_metadata(
user = handler_instance._get_user_from_metadata(
passthrough_logging_payload=passthrough_logging_payload,
)
if user:
@ -369,7 +363,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
)
return {
"result": litellm_model_response or response_body,
"result": litellm_model_response,
"kwargs": kwargs,
}
@ -480,6 +474,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
# Build complete response from chunks using our streaming handler
handler = OpenAIPassthroughLoggingHandler()
handler_instance = handler
complete_response = handler._build_complete_streaming_response(
all_chunks=all_chunks,
litellm_logging_obj=litellm_logging_obj,
@ -516,7 +511,7 @@ class OpenAIPassthroughLoggingHandler(BasePassthroughLoggingHandler):
"passthrough_logging_payload"
)
if passthrough_logging_payload:
user = OpenAIPassthroughLoggingHandler._get_user_from_metadata(
user = handler_instance._get_user_from_metadata(
passthrough_logging_payload=passthrough_logging_payload,
)
if user: