generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
699ad5c
commit ecb15c9
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
describe DiscourseAi::Completions::AnthropicMessageProcessor do | ||
it "correctly handles and combines partial thinking chunks into complete thinking objects" do | ||
processor = | ||
DiscourseAi::Completions::AnthropicMessageProcessor.new( | ||
streaming_mode: true, | ||
partial_tool_calls: false, | ||
output_thinking: true, | ||
) | ||
|
||
# Simulate streaming thinking output in multiple chunks | ||
result1 = | ||
processor.process_streamed_message( | ||
{ type: "content_block_start", content_block: { type: "thinking", thinking: "" } }, | ||
) | ||
|
||
result2 = | ||
processor.process_streamed_message( | ||
{ | ||
type: "content_block_delta", | ||
delta: { | ||
type: "thinking_delta", | ||
thinking: "First part of thinking", | ||
}, | ||
}, | ||
) | ||
|
||
result3 = | ||
processor.process_streamed_message( | ||
{ | ||
type: "content_block_delta", | ||
delta: { | ||
type: "thinking_delta", | ||
thinking: " and second part", | ||
}, | ||
}, | ||
) | ||
|
||
_result4 = | ||
processor.process_streamed_message( | ||
{ | ||
type: "content_block_delta", | ||
delta: { | ||
type: "signature_delta", | ||
signature: "thinking-sig-123", | ||
}, | ||
}, | ||
) | ||
|
||
# Finish the thinking block | ||
final_result = processor.process_streamed_message({ type: "content_block_stop" }) | ||
|
||
# Verify the partial thinking chunks | ||
expect(result1).to be_a(DiscourseAi::Completions::Thinking) | ||
expect(result1.message).to eq("") | ||
expect(result1.partial?).to eq(true) | ||
|
||
expect(result2).to be_a(DiscourseAi::Completions::Thinking) | ||
expect(result2.message).to eq("First part of thinking") | ||
expect(result2.partial?).to eq(true) | ||
|
||
expect(result3).to be_a(DiscourseAi::Completions::Thinking) | ||
expect(result3.message).to eq(" and second part") | ||
expect(result3.partial?).to eq(true) | ||
|
||
# Verify the final complete thinking object | ||
expect(final_result).to be_a(DiscourseAi::Completions::Thinking) | ||
expect(final_result.message).to eq("First part of thinking and second part") | ||
expect(final_result.signature).to eq("thinking-sig-123") | ||
expect(final_result.partial?).to eq(false) | ||
end | ||
end |