fix(streaming_handler.py): respect is_finished = False in hidden params

internal logic for preventing ending stream early
This commit is contained in:
Krrish Dholakia 2025-06-09 18:20:19 -07:00
parent 03d6546b44
commit 3a8c4dabd9
2 changed files with 5 additions and 5 deletions

View file

@ -442,9 +442,10 @@ class CustomStreamWrapper:
is_finished = (
True # check if str_line._hidden_params["is_finished"] is True
)
if hasattr(
str_line, "_hidden_params"
) and str_line._hidden_params.get("is_finished"):
if (
hasattr(str_line, "_hidden_params")
and str_line._hidden_params.get("is_finished") is not None
):
is_finished = str_line._hidden_params.get("is_finished")
finish_reason = str_line.choices[0].finish_reason
@ -1194,7 +1195,6 @@ class CustomStreamWrapper:
if response_obj is None:
return
completion_obj["content"] = response_obj["text"]
print_verbose(f"completion obj content: {completion_obj['content']}")
if response_obj["is_finished"]:
if response_obj["finish_reason"] == "error":
raise Exception(

View file

@ -3946,7 +3946,7 @@ def test_vertex_ai_streaming_response_id():
def test_vertex_ai_gemini_2_5_pro_streaming():
load_vertex_ai_credentials()
litellm._turn_on_debug()
# litellm._turn_on_debug()
response = completion(
model="vertex_ai/gemini-2.5-pro-preview-06-05",
messages=[{"role": "user", "content": "Hi!"}],