fix(anthropic): aux stream reader tolerates non-iterable get_final_message shims
_stream_final_message now iterates the SDK MessageStream only when it is iterable; a shim exposing just get_final_message() (the auxiliary client fake and any gateway wrapper of that shape) falls straight through to the snapshot instead of raising TypeError. Restores the pre-refusal-fix contract where the aux path never required event iteration.
This commit is contained in:
@@ -8,6 +8,7 @@ import logging
|
||||
import math
|
||||
import re
|
||||
import subprocess
|
||||
from collections.abc import Iterable
|
||||
from contextlib import suppress
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
@@ -663,8 +664,9 @@ def _stream_final_message(stream_fn, api_kwargs, log_prefix, on_stream_event, on
|
||||
# has given up, so abandon the stream (``with`` closes it) instead of streaming an answer
|
||||
# nobody reads.
|
||||
# Some SDK versions drop optional message_delta metadata from the final snapshot.
|
||||
# Non-iterable shims (get_final_message-only) skip straight to the snapshot.
|
||||
stop_details = None
|
||||
for event in stream:
|
||||
for event in (stream if isinstance(stream, Iterable) else ()):
|
||||
if getattr(event, "type", None) == "message_delta":
|
||||
details = getattr(getattr(event, "delta", None), "stop_details", None)
|
||||
if details is not None:
|
||||
|
||||
Reference in New Issue
Block a user