Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ private static ChatResponse parseStreamEvent(RawMessageStreamEvent event, Instan
contentBlocks.add(
TextBlock.builder().text(textDelta.text()).build()));

deltaEvent
.delta()
.thinking()
.ifPresent(
thinkingDelta ->
contentBlocks.add(
ThinkingBlock.builder()
.thinking(thinkingDelta.thinking())
.build()));

// Input JSON delta (tool calling)
deltaEvent
.delta()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.anthropic.models.messages.ContentBlock;
import com.anthropic.models.messages.Message;
import com.anthropic.models.messages.RawContentBlockDeltaEvent;
import com.anthropic.models.messages.RawMessageStartEvent;
import com.anthropic.models.messages.RawMessageStreamEvent;
import com.anthropic.models.messages.Usage;
Expand Down Expand Up @@ -316,6 +317,26 @@ void testParseStreamEventMessageStart() throws Exception {
assertTrue(response.getContent().isEmpty()); // MessageStart has no content
}

@Test
void testParseStreamEventThinkingDelta() throws Exception {
RawContentBlockDeltaEvent deltaEvent =
RawContentBlockDeltaEvent.builder()
.index(0)
.thinkingDelta("Let me reason through this.")
.build();
RawMessageStreamEvent event = RawMessageStreamEvent.ofContentBlockDelta(deltaEvent);

Instant startTime = Instant.now();
ChatResponse response = invokeParseStreamEvent(event, startTime);

assertNotNull(response);
assertEquals(1, response.getContent().size());
ThinkingBlock parsedThinking =
assertInstanceOf(ThinkingBlock.class, response.getContent().get(0));
assertEquals("Let me reason through this.", parsedThinking.getThinking());
assertNull(response.getUsage());
}

@Test
void testParseStreamEventUnknownType() throws Exception {
// Test unknown event type - should return empty response
Expand Down
Loading