Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(logging_utils.py): revert change

Krrish Dholakiaa5b497667cf2
diff --git a/litellm/litellm_core_utils/logging_utils.py b/litellm/litellm_core_utils/logging_utils.py
index c2d959b3c08..3c934a42761 100644
--- a/litellm/litellm_core_utils/logging_utils.py
+++ b/litellm/litellm_core_utils/logging_utils.py
@@ -77,7 +77,8 @@ def _assemble_complete_response_from_streaming_chunks(
complete_streaming_response: Optional[
Union[ModelResponse, TextCompletionResponse]
] = None
- if getattr(result, "usage", None) is not None: # if it's the last chunk
+
+ if result.choices[0].finish_reason is not None: # if it's the last chunk
streaming_chunks.append(result)
try:
complete_streaming_response = litellm.stream_chunk_builder(
diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py
index 4d81cddf666..15d94b31a99 100644
--- a/litellm/litellm_core_utils/streaming_handler.py
+++ b/litellm/litellm_core_utils/streaming_handler.py
@@ -1555,10 +1555,11 @@ class CustomStreamWrapper:
if response is None:
continue
## LOGGING
- threading.Thread(
- target=self.run_success_logging_and_cache_storage,
- args=(response, cache_hit),
- ).start() # log response
+ executor.submit(
+ self.run_success_logging_and_cache_storage,
+ response,
+ cache_hit,
+ ) # log response
choice = response.choices[0]
if isinstance(choice, StreamingChoices):
self.response_uptil_now += choice.delta.get("content", "") or ""
@@ -1628,10 +1629,11 @@ class CustomStreamWrapper:
usage = calculate_total_usage(chunks=self.chunks)
processed_chunk._hidden_params["usage"] = usage
## LOGGING
- threading.Thread(
- target=self.run_success_logging_and_cache_storage,
- args=(processed_chunk, cache_hit),
- ).start() # log response
+ executor.submit(
+ self.run_success_logging_and_cache_storage,
+ processed_chunk,
+ cache_hit,
+ ) # log response
return processed_chunk
except Exception as e:
traceback_exception = traceback.format_exc()
diff --git a/tests/logging_callback_tests/test_assemble_streaming_responses.py b/tests/logging_callback_tests/test_assemble_streaming_responses.py
index 7b28f69917e..1101350fa29 100644
--- a/tests/logging_callback_tests/test_assemble_streaming_responses.py
+++ b/tests/logging_callback_tests/test_assemble_streaming_responses.py
@@ -26,7 +26,7 @@ from respx import MockRouter
import litellm
from litellm import Choices, Message, ModelResponse, TextCompletionResponse, TextChoices
-from litellm.litellm_core_utils.litellm_logging import (
+from litellm.litellm_core_utils.logging_utils import (
_assemble_complete_response_from_streaming_chunks,
)