File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 5454public class StreamHelper {
5555
5656 public boolean isToolUseStart (StreamEvent event ) {
57- if (event == null || event .type () == null || event .type () != EventType .CONTENT_BLOCK_START ) {
58- return false ;
59- }
60- return ContentBlock .Type .TOOL_USE .getValue ().equals (((ContentBlockStartEvent ) event ).contentBlock ().type ());
57+ if (isInvalidEvent (event , EventType .CONTENT_BLOCK_START )) {
58+ return false ;
59+ }
60+ ContentBlockStartEvent contentBlockStartEvent = (ContentBlockStartEvent ) event ;
61+ return ContentBlock .Type .TOOL_USE .getValue ().equals (contentBlockStartEvent .contentBlock ().type ());
6162 }
6263
6364 public boolean isToolUseFinish (StreamEvent event ) {
65+ return !isInvalidEvent (event , EventType .CONTENT_BLOCK_STOP );
66+ }
6467
65- if (event == null || event .type () == null || event .type () != EventType .CONTENT_BLOCK_STOP ) {
66- return false ;
67- }
68- return true ;
68+ private boolean isInvalidEvent (StreamEvent event , EventType expectedType ) {
69+ return event == null || event .type () == null || event .type () != expectedType ;
6970 }
7071
7172 public StreamEvent mergeToolUseEvents (StreamEvent previousEvent , StreamEvent event ) {
You can’t perform that action at this time.
0 commit comments