Merge pull request #2546 from nanobanana123/fix/anthropic-empty-thinking-sse
fix(apicompat): preserve empty streaming thinking blocks
This commit is contained in:
commit
6c8b6843fd
@ -744,6 +744,10 @@ func TestStreamingReasoning(t *testing.T) {
|
|||||||
assert.Equal(t, "content_block_start", events[0].Type)
|
assert.Equal(t, "content_block_start", events[0].Type)
|
||||||
assert.Equal(t, "thinking", events[0].ContentBlock.Type)
|
assert.Equal(t, "thinking", events[0].ContentBlock.Type)
|
||||||
|
|
||||||
|
sse, err := ResponsesAnthropicEventToSSE(events[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Contains(t, sse, `"content_block":{"thinking":"","type":"thinking"}`)
|
||||||
|
|
||||||
// reasoning text delta
|
// reasoning text delta
|
||||||
events = ResponsesEventToAnthropicEvents(&ResponsesStreamEvent{
|
events = ResponsesEventToAnthropicEvents(&ResponsesStreamEvent{
|
||||||
Type: "response.reasoning_summary_text.delta",
|
Type: "response.reasoning_summary_text.delta",
|
||||||
|
|||||||
@ -75,6 +75,28 @@ type AnthropicContentBlock struct {
|
|||||||
IsError bool `json:"is_error,omitempty"`
|
IsError bool `json:"is_error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b AnthropicContentBlock) MarshalJSON() ([]byte, error) {
|
||||||
|
type anthropicContentBlock AnthropicContentBlock
|
||||||
|
base := struct {
|
||||||
|
anthropicContentBlock
|
||||||
|
}{anthropicContentBlock: anthropicContentBlock(b)}
|
||||||
|
|
||||||
|
switch b.Type {
|
||||||
|
case "text":
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
anthropicContentBlock
|
||||||
|
}{Text: b.Text, anthropicContentBlock: anthropicContentBlock(b)})
|
||||||
|
case "thinking":
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Thinking string `json:"thinking"`
|
||||||
|
anthropicContentBlock
|
||||||
|
}{Thinking: b.Thinking, anthropicContentBlock: anthropicContentBlock(b)})
|
||||||
|
default:
|
||||||
|
return json.Marshal(base)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AnthropicImageSource describes the source data for an image content block.
|
// AnthropicImageSource describes the source data for an image content block.
|
||||||
type AnthropicImageSource struct {
|
type AnthropicImageSource struct {
|
||||||
Type string `json:"type"` // "base64"
|
Type string `json:"type"` // "base64"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user