mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix: remove over-strict stream logging validator, restore base seam behavior
This commit is contained in:
parent
e5ac4e0068
commit
262d1b4ca0
9 changed files with 26 additions and 42 deletions
|
|
@ -3,13 +3,13 @@
|
|||
"limit": 25153
|
||||
},
|
||||
"reportArgumentType": {
|
||||
"limit": 2596
|
||||
"limit": 2597
|
||||
},
|
||||
"reportAssignmentType": {
|
||||
"limit": 327
|
||||
"limit": 325
|
||||
},
|
||||
"reportAttributeAccessIssue": {
|
||||
"limit": 510
|
||||
"limit": 501
|
||||
},
|
||||
"reportCallIssue": {
|
||||
"limit": 114
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
"limit": 0
|
||||
},
|
||||
"reportMissingParameterType": {
|
||||
"limit": 5770
|
||||
"limit": 5772
|
||||
},
|
||||
"reportMissingTypeArgument": {
|
||||
"limit": 15676
|
||||
|
|
@ -99,16 +99,16 @@
|
|||
"limit": 0
|
||||
},
|
||||
"reportUnknownArgumentType": {
|
||||
"limit": 44911
|
||||
"limit": 44914
|
||||
},
|
||||
"reportUnknownLambdaType": {
|
||||
"limit": 113
|
||||
},
|
||||
"reportUnknownMemberType": {
|
||||
"limit": 39464
|
||||
"limit": 39456
|
||||
},
|
||||
"reportUnknownParameterType": {
|
||||
"limit": 20058
|
||||
"limit": 20060
|
||||
},
|
||||
"reportUnknownVariableType": {
|
||||
"limit": 31038
|
||||
|
|
@ -129,7 +129,7 @@
|
|||
"limit": 0
|
||||
},
|
||||
"reportUntypedFunctionDecorator": {
|
||||
"limit": 33
|
||||
"limit": 30
|
||||
},
|
||||
"reportUnusedClass": {
|
||||
"limit": 23
|
||||
|
|
|
|||
|
|
@ -155,14 +155,6 @@ class _TextCompletionChoiceLike(Protocol):
|
|||
finish_reason: str | None
|
||||
|
||||
|
||||
def validated_stream_logging_obj(candidate: object) -> LiteLLMLoggingObject:
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging
|
||||
|
||||
if isinstance(candidate, Logging):
|
||||
return candidate
|
||||
raise TypeError("CustomStreamWrapper requires a LiteLLMLoggingObject")
|
||||
|
||||
|
||||
class CustomStreamWrapper:
|
||||
def __init__(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import (
|
|||
from litellm.litellm_core_utils.request_timeout_resolver import (
|
||||
get_configured_request_timeout,
|
||||
)
|
||||
from litellm.litellm_core_utils.streaming_handler import validated_stream_logging_obj
|
||||
from litellm.llms.base_llm import BaseConfig, BaseImageGenerationConfig
|
||||
from litellm.llms.base_llm.base_model_iterator import (
|
||||
convert_model_response_to_streaming,
|
||||
|
|
@ -597,7 +596,7 @@ async def acompletion(
|
|||
_, custom_llm_provider, _, _ = get_llm_provider(
|
||||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
api_base=completion_kwargs.get("base_url", None),
|
||||
api_base=base_url,
|
||||
)
|
||||
|
||||
fallbacks = fallbacks or litellm.model_fallbacks
|
||||
|
|
@ -827,7 +826,7 @@ def mock_completion(
|
|||
mock_response: MOCK_RESPONSE_TYPE | None = "This is a mock request",
|
||||
mock_tool_calls: list | None = None,
|
||||
mock_timeout: bool | None = False,
|
||||
logging: LiteLLMLoggingObj | None = None,
|
||||
logging=None,
|
||||
custom_llm_provider=None,
|
||||
timeout: float | str | httpx.Timeout | None = None,
|
||||
**kwargs,
|
||||
|
|
@ -911,7 +910,7 @@ def mock_completion(
|
|||
),
|
||||
model=model,
|
||||
custom_llm_provider="openai",
|
||||
logging_obj=validated_stream_logging_obj(logging),
|
||||
logging_obj=logging,
|
||||
)
|
||||
return CustomStreamWrapper(
|
||||
completion_stream=mock_completion_streaming_obj(
|
||||
|
|
@ -919,7 +918,7 @@ def mock_completion(
|
|||
),
|
||||
model=model,
|
||||
custom_llm_provider="openai",
|
||||
logging_obj=validated_stream_logging_obj(logging),
|
||||
logging_obj=logging,
|
||||
)
|
||||
if isinstance(mock_response, litellm.MockException):
|
||||
raise mock_response
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import asyncio
|
||||
import io
|
||||
import traceback
|
||||
from typing import Final
|
||||
|
||||
import orjson
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Response, status
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, Request, Response, UploadFile, status
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
||||
import litellm
|
||||
|
|
@ -18,11 +20,6 @@ from litellm.types.llms.openai import ChatCompletionUserMessage
|
|||
|
||||
router: Final = APIRouter()
|
||||
|
||||
import io
|
||||
from typing import Final
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
|
||||
async def uploadfile_to_bytesio(upload: UploadFile) -> io.BytesIO:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -259,7 +259,6 @@ from litellm.litellm_core_utils.sensitive_data_masker import (
|
|||
SensitiveDataMasker,
|
||||
mask_sensitive_keys,
|
||||
)
|
||||
from litellm.litellm_core_utils.streaming_handler import validated_stream_logging_obj
|
||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler
|
||||
from litellm.llms.vertex_ai.vertex_llm_base import VertexBase
|
||||
from litellm.proxy._lazy_features import attach_lazy_features
|
||||
|
|
@ -9749,7 +9748,7 @@ async def chat_completion(
|
|||
completion_stream=_iterator,
|
||||
model=e.model,
|
||||
custom_llm_provider="cached_response",
|
||||
logging_obj=validated_stream_logging_obj(_logging_obj),
|
||||
logging_obj=_logging_obj,
|
||||
)
|
||||
selected_data_generator = select_data_generator(
|
||||
response=_streaming_response,
|
||||
|
|
@ -9766,7 +9765,6 @@ async def chat_completion(
|
|||
return _chat_response
|
||||
except RejectedRequestError as e:
|
||||
_data = e.request_data
|
||||
_rejected_request_data: Final[dict[str, object]] = e.request_data
|
||||
await proxy_logging_obj.post_call_failure_hook(
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
original_exception=e,
|
||||
|
|
@ -9781,7 +9779,7 @@ async def chat_completion(
|
|||
completion_stream=_iterator,
|
||||
model=data.get("model", ""),
|
||||
custom_llm_provider="cached_response",
|
||||
logging_obj=validated_stream_logging_obj(_rejected_request_data.get("litellm_logging_obj")),
|
||||
logging_obj=_data.get("litellm_logging_obj", None),
|
||||
)
|
||||
selected_data_generator = select_data_generator(
|
||||
response=_streaming_response,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#### Rerank Endpoints #####
|
||||
|
||||
import asyncio
|
||||
from typing import Final
|
||||
|
||||
import orjson
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
|
@ -10,8 +13,6 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
|||
from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
|
||||
|
||||
router: Final = APIRouter()
|
||||
import asyncio
|
||||
from typing import Final
|
||||
|
||||
|
||||
@router.post(
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ def _normalize_tool_dialect(
|
|||
|
||||
def _is_chat_completions_body(data: Mapping[str, Any]) -> bool:
|
||||
messages: Final = data.get("messages")
|
||||
if isinstance(messages, list) and len(messages) > 0:
|
||||
if isinstance(messages, list) and messages:
|
||||
return True
|
||||
return "messages" in data and "input" not in data
|
||||
|
||||
|
|
@ -497,10 +497,7 @@ async def cursor_chat_completions(
|
|||
from litellm.completion_extras.litellm_responses_transformation.handler import (
|
||||
responses_api_bridge,
|
||||
)
|
||||
from litellm.litellm_core_utils.streaming_handler import (
|
||||
CustomStreamWrapper,
|
||||
validated_stream_logging_obj,
|
||||
)
|
||||
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
|
||||
from litellm.proxy.proxy_server import (
|
||||
async_data_generator,
|
||||
chat_completion,
|
||||
|
|
@ -548,7 +545,7 @@ async def cursor_chat_completions(
|
|||
|
||||
processor: Final = ProxyBaseLLMRequestProcessing(data=data)
|
||||
|
||||
def cursor_data_generator(response, user_api_key_dict, request_data: dict[str, object], request=None):
|
||||
def cursor_data_generator(response, user_api_key_dict, request_data, request=None):
|
||||
"""
|
||||
Custom generator that transforms Responses API streaming chunks to chat completion chunks.
|
||||
|
||||
|
|
@ -582,7 +579,7 @@ async def cursor_chat_completions(
|
|||
completion_stream=completion_stream,
|
||||
model=request_data.get("model", ""),
|
||||
custom_llm_provider=None,
|
||||
logging_obj=validated_stream_logging_obj(logging_obj),
|
||||
logging_obj=logging_obj,
|
||||
)
|
||||
# Use async_data_generator to format as SSE
|
||||
return async_data_generator(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"ANN001": {
|
||||
"limit": 3056
|
||||
"limit": 3058
|
||||
},
|
||||
"ANN002": {
|
||||
"limit": 71
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"LIT001": {
|
||||
"limit": 23023
|
||||
"limit": 23021
|
||||
},
|
||||
"LIT002": {
|
||||
"limit": 27148
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue