mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix(lint): resolve UP007 violations
This commit is contained in:
parent
8bf1f21c38
commit
c4af986f9c
4 changed files with 31 additions and 28 deletions
|
|
@ -4,10 +4,12 @@ GigaChat Chat Transformation
|
|||
Transforms OpenAI-format requests to GigaChat format and back.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING, Any, AsyncIterator, Iterator, Union
|
||||
from typing import TYPE_CHECKING, Any, AsyncIterator, Iterator
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -212,7 +214,7 @@ class GigaChatConfig(BaseConfig):
|
|||
)
|
||||
return functions
|
||||
|
||||
def _map_tool_choice(self, tool_choice: Union[str, dict]) -> Union[str, dict] | None:
|
||||
def _map_tool_choice(self, tool_choice: str | dict) -> str | dict | None:
|
||||
"""
|
||||
Map OpenAI tool_choice to GigaChat function_call format.
|
||||
|
||||
|
|
@ -488,7 +490,7 @@ class GigaChatConfig(BaseConfig):
|
|||
self,
|
||||
error_message: str,
|
||||
status_code: int,
|
||||
headers: Union[dict, httpx.Headers],
|
||||
headers: dict | httpx.Headers,
|
||||
) -> BaseLLMException:
|
||||
"""Return GigaChat error class."""
|
||||
return GigaChatError(
|
||||
|
|
@ -499,7 +501,7 @@ class GigaChatConfig(BaseConfig):
|
|||
|
||||
def get_model_response_iterator(
|
||||
self,
|
||||
streaming_response: Union[Iterator[str], AsyncIterator[str], ModelResponse],
|
||||
streaming_response: Iterator[str] | AsyncIterator[str] | ModelResponse,
|
||||
sync_stream: bool,
|
||||
json_mode: bool | None = False,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ Transforms OpenAI /v1/embeddings format to GigaChat format.
|
|||
API Documentation: https://developers.sber.ru/docs/ru/gigachat/api/reference/rest/post-embeddings
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import types
|
||||
from typing import Union
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -200,9 +201,7 @@ class GigaChatEmbeddingConfig(BaseEmbeddingConfig):
|
|||
}
|
||||
return {**default_headers, **headers}
|
||||
|
||||
def get_error_class(
|
||||
self, error_message: str, status_code: int, headers: Union[dict, httpx.Headers]
|
||||
) -> BaseLLMException:
|
||||
def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:
|
||||
"""Return GigaChat-specific error class."""
|
||||
return GigaChatEmbeddingError(
|
||||
status_code=status_code,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
This module is used to pass through requests to the LLM APIs.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextvars
|
||||
from functools import partial
|
||||
|
|
@ -12,8 +14,6 @@ from typing import (
|
|||
Coroutine,
|
||||
Generator,
|
||||
List,
|
||||
Optional,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
|
||||
|
|
@ -239,9 +239,9 @@ async def allm_passthrough_route(
|
|||
json: Any | None = None,
|
||||
params: QueryParamTypes | None = None,
|
||||
cookies: CookieTypes | None = None,
|
||||
client: Optional[Union[HTTPHandler, AsyncHTTPHandler]] = None,
|
||||
client: HTTPHandler | AsyncHTTPHandler | None = None,
|
||||
**kwargs,
|
||||
) -> Union[httpx.Response, AsyncGenerator[Any, Any]]:
|
||||
) -> httpx.Response | AsyncGenerator[Any, Any]:
|
||||
"""
|
||||
Async: Reranks a list of documents based on their relevance to the query
|
||||
"""
|
||||
|
|
@ -260,7 +260,7 @@ async def allm_passthrough_route(
|
|||
from litellm.utils import ProviderConfigManager
|
||||
|
||||
provider_config = cast(
|
||||
Optional["BasePassthroughConfig"], kwargs.get("provider_config")
|
||||
"BasePassthroughConfig" | None, kwargs.get("provider_config")
|
||||
) or ProviderConfigManager.get_provider_passthrough_config(
|
||||
provider=LlmProviders(custom_llm_provider),
|
||||
model=model,
|
||||
|
|
@ -328,7 +328,7 @@ async def allm_passthrough_route(
|
|||
if resolved_custom_llm_provider:
|
||||
try:
|
||||
provider_config = cast(
|
||||
Optional["BasePassthroughConfig"], kwargs.get("provider_config")
|
||||
"BasePassthroughConfig" | None, kwargs.get("provider_config")
|
||||
) or ProviderConfigManager.get_provider_passthrough_config(
|
||||
provider=LlmProviders(resolved_custom_llm_provider),
|
||||
model=model,
|
||||
|
|
@ -365,15 +365,15 @@ def llm_passthrough_route(
|
|||
json: Any | None = None,
|
||||
params: QueryParamTypes | None = None,
|
||||
cookies: CookieTypes | None = None,
|
||||
client: Union[HTTPHandler, AsyncHTTPHandler] | None = None,
|
||||
client: HTTPHandler | AsyncHTTPHandler | None = None,
|
||||
**kwargs,
|
||||
) -> Union[
|
||||
httpx.Response,
|
||||
Coroutine[Any, Any, httpx.Response],
|
||||
Coroutine[Any, Any, Union[httpx.Response, AsyncGenerator[Any, Any]]],
|
||||
Generator[Any, Any, Any],
|
||||
AsyncGenerator[Any, Any],
|
||||
]:
|
||||
) -> (
|
||||
httpx.Response
|
||||
| Coroutine[Any, Any, httpx.Response]
|
||||
| Coroutine[Any, Any, httpx.Response | AsyncGenerator[Any, Any]]
|
||||
| Generator[Any, Any, Any]
|
||||
| AsyncGenerator[Any, Any]
|
||||
):
|
||||
"""
|
||||
Pass through requests to the LLM APIs.
|
||||
|
||||
|
|
@ -432,7 +432,7 @@ def llm_passthrough_route(
|
|||
)
|
||||
|
||||
provider_config = cast(
|
||||
Optional["BasePassthroughConfig"], kwargs.get("provider_config")
|
||||
"BasePassthroughConfig" | None, kwargs.get("provider_config")
|
||||
) or ProviderConfigManager.get_provider_passthrough_config(
|
||||
provider=LlmProviders(custom_llm_provider),
|
||||
model=model,
|
||||
|
|
@ -547,12 +547,12 @@ def llm_passthrough_route(
|
|||
|
||||
|
||||
async def _async_passthrough_request(
|
||||
client: Union[HTTPHandler, AsyncHTTPHandler],
|
||||
client: HTTPHandler | AsyncHTTPHandler,
|
||||
request: httpx.Request,
|
||||
is_streaming_request: bool,
|
||||
litellm_logging_obj: "LiteLLMLoggingObj",
|
||||
provider_config: "BasePassthroughConfig",
|
||||
) -> Union[httpx.Response, AsyncGenerator[Any, Any]]:
|
||||
) -> httpx.Response | AsyncGenerator[Any, Any]:
|
||||
"""
|
||||
Handle async passthrough requests.
|
||||
Uses async client to send request and properly handles streaming.
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@ Provider-specific Pass-Through Endpoints
|
|||
Use litellm with Anthropic SDK, Vertex AI SDK, Cohere SDK, etc.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import TYPE_CHECKING, Any, Callable, Union, cast
|
||||
from typing import TYPE_CHECKING, Any, Callable, cast
|
||||
|
||||
import httpx
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response, WebSocket
|
||||
|
|
@ -730,7 +732,7 @@ async def handle_bedrock_passthrough_router_model(
|
|||
user_max_tokens: int | None,
|
||||
user_api_base: str | None,
|
||||
version: str | None,
|
||||
) -> Union[Response, StreamingResponse]:
|
||||
) -> Response | StreamingResponse:
|
||||
"""
|
||||
Handle Bedrock passthrough for router models (models defined in config.yaml).
|
||||
|
||||
|
|
@ -2421,7 +2423,7 @@ async def handle_gigachat_passthrough_router_model(
|
|||
user_max_tokens: int | None,
|
||||
user_api_base: str | None,
|
||||
version: str | None,
|
||||
) -> Union[Response, StreamingResponse]:
|
||||
) -> Response | StreamingResponse:
|
||||
"""
|
||||
Handle Gigachat passthrough for router models (models defined in config.yaml).
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue