File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -185,14 +185,28 @@ def can_normalize_chunk(self, chunk: Any) -> bool:
185185 # The actual MessageStreamEvent is a generic, so isinstance() can't
186186 # be used to check the type. Instead, we manually construct the relevant
187187 # union of relevant classes...
188- return (
188+ if (
189189 isinstance (chunk , RawContentBlockDeltaEvent )
190190 or isinstance (chunk , RawContentBlockStartEvent )
191191 or isinstance (chunk , RawContentBlockStopEvent )
192192 or isinstance (chunk , RawMessageDeltaEvent )
193193 or isinstance (chunk , RawMessageStartEvent )
194194 or isinstance (chunk , RawMessageStopEvent )
195+ ):
196+ return True
197+
198+ # Older versions of the anthropic library don't have the beta prompt caching
199+ # types, so we need to check for them separately. If this import fails or
200+ # errors, then we'll end up in the Exception handler and return False.
201+ from anthropic .types .beta .prompt_caching import (
202+ RawPromptCachingBetaMessageStartEvent ,
195203 )
204+
205+ if isinstance (chunk , RawPromptCachingBetaMessageStartEvent ):
206+ return True
207+
208+ return False
209+
196210 except Exception :
197211 return False
198212
You can’t perform that action at this time.
0 commit comments