mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(lint) : resolve LIT006 violations
This commit is contained in:
parent
2d75d24c34
commit
30ed0c14b5
3 changed files with 32 additions and 8 deletions
|
|
@ -178,10 +178,9 @@ class GigaChatPassthroughConfig(BasePassthroughConfig):
|
|||
)
|
||||
translated_chunk = gigachat_iterator.chunk_parser(chunk=message)
|
||||
|
||||
if isinstance(translated_chunk, dict) and generic_chunk_has_all_required_fields(
|
||||
cast(dict, translated_chunk)
|
||||
):
|
||||
if isinstance(translated_chunk, dict) and generic_chunk_has_all_required_fields(translated_chunk):
|
||||
chunk_obj = convert_generic_chunk_to_model_response_stream(
|
||||
# cast-ok: validated TypedDict
|
||||
cast(GenericStreamingChunk, translated_chunk)
|
||||
)
|
||||
elif isinstance(translated_chunk, ModelResponseStream):
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@ from functools import partial
|
|||
from typing import (
|
||||
Any,
|
||||
AsyncGenerator,
|
||||
AsyncIterator,
|
||||
Coroutine,
|
||||
Generator,
|
||||
Iterator,
|
||||
List,
|
||||
cast,
|
||||
)
|
||||
|
|
@ -32,6 +34,16 @@ base_llm_http_handler = BaseLLMHTTPHandler()
|
|||
from .utils import BasePassthroughUtils
|
||||
|
||||
|
||||
async def _as_async_generator(iterable: AsyncIterator[bytes]) -> AsyncGenerator[bytes, Any]:
|
||||
async for chunk in iterable:
|
||||
yield chunk
|
||||
|
||||
|
||||
def _as_generator(iterable: Iterator[bytes]) -> Generator[bytes, Any, Any]:
|
||||
for chunk in iterable:
|
||||
yield chunk
|
||||
|
||||
|
||||
class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -80,7 +92,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):
|
|||
self._initialized = True
|
||||
try:
|
||||
self._response.raise_for_status()
|
||||
self._iterator = cast(AsyncGenerator[bytes, Any], self._response.aiter_bytes())
|
||||
self._iterator = _as_async_generator(self._response.aiter_bytes())
|
||||
except Exception: # noqa: BLE001
|
||||
try:
|
||||
await self._response.aclose()
|
||||
|
|
@ -123,7 +135,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):
|
|||
if not self._initialized:
|
||||
await self
|
||||
try:
|
||||
chunk = await self._iterator.__anext__()
|
||||
chunk = await anext(self._iterator)
|
||||
self._raw_bytes.append(chunk)
|
||||
return chunk
|
||||
except Exception: # noqa: BLE001
|
||||
|
|
@ -148,6 +160,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):
|
|||
self._start_flush()
|
||||
try:
|
||||
if self._initialized:
|
||||
await self._iterator.aclose()
|
||||
await self._response.aclose()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
|
|
@ -165,7 +178,7 @@ class PassthroughStreamingResponse(Generator[Any, Any, Any]):
|
|||
self.status_code = response.status_code
|
||||
self._litellm_logging_obj = litellm_logging_obj
|
||||
self._provider_config = provider_config
|
||||
self._iterator: Generator[bytes, Any, Any] = cast(Generator[bytes, Any, Any], response.iter_bytes())
|
||||
self._iterator: Generator[bytes, Any, Any] = _as_generator(response.iter_bytes())
|
||||
self._raw_bytes: List[bytes] = []
|
||||
self._flush_scheduled = False
|
||||
|
||||
|
|
@ -383,7 +396,13 @@ def llm_passthrough_route(
|
|||
|
||||
_is_async = bool(kwargs.get("allm_passthrough_route", False))
|
||||
|
||||
litellm_logging_obj = cast(LiteLLMLoggingObj, kwargs.get("litellm_logging_obj"))
|
||||
_raw_logging_obj = kwargs.get("litellm_logging_obj")
|
||||
if not isinstance(_raw_logging_obj, LiteLLMLoggingObj):
|
||||
raise TypeError(
|
||||
"litellm_logging_obj is required and must be a LiteLLMLoggingObj instance; "
|
||||
f"got {type(_raw_logging_obj).__name__}"
|
||||
)
|
||||
litellm_logging_obj: LiteLLMLoggingObj = _raw_logging_obj
|
||||
|
||||
model, custom_llm_provider, api_key, api_base = get_llm_provider(
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -455,7 +455,13 @@ async def milvus_proxy_route(
|
|||
request_body = await get_request_body(request)
|
||||
|
||||
# check collectionName
|
||||
collection_name = cast(str | None, request_body.get("collectionName"))
|
||||
_raw_collection_name = request_body.get("collectionName")
|
||||
if _raw_collection_name is not None and not isinstance(_raw_collection_name, str):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"collectionName must be a string. Got {type(_raw_collection_name).__name__}",
|
||||
)
|
||||
collection_name: str | None = _raw_collection_name
|
||||
extra_headers = {}
|
||||
base_target_url: str | None = None
|
||||
if not collection_name:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue