Changeset 0.22.1 (#95)
This commit is contained in:
@@ -130,10 +130,15 @@ func (p *AnthropicProvider) StreamCompletion(ctx context.Context, cfg ProviderCo
|
||||
},
|
||||
})
|
||||
}
|
||||
// thinking blocks (extended thinking, v0.22.1) — no action on start,
|
||||
// deltas arrive as thinking_delta in content_block_delta
|
||||
|
||||
case "content_block_delta":
|
||||
if event.Delta.Type == "text_delta" {
|
||||
ch <- StreamEvent{Delta: event.Delta.Text}
|
||||
} else if event.Delta.Type == "thinking_delta" && event.Delta.Thinking != "" {
|
||||
// Extended thinking content → Reasoning field
|
||||
ch <- StreamEvent{Reasoning: event.Delta.Thinking}
|
||||
} else if event.Delta.Type == "input_json_delta" && currentToolIdx >= 0 {
|
||||
toolCalls[currentToolIdx].Function.Arguments += event.Delta.PartialJSON
|
||||
}
|
||||
@@ -343,6 +348,15 @@ func (p *AnthropicProvider) doRequest(ctx context.Context, cfg ProviderConfig, r
|
||||
return nil, fmt.Errorf("marshal request: %w", err)
|
||||
}
|
||||
|
||||
// Merge hook-supplied extra fields into wire JSON (v0.22.1)
|
||||
// This is how extended thinking config gets injected.
|
||||
if len(req.ExtraBody) > 0 {
|
||||
body, err = mergeExtraBody(body, req.ExtraBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("merge extra body: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
httpReq, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -351,6 +365,13 @@ func (p *AnthropicProvider) doRequest(ctx context.Context, cfg ProviderConfig, r
|
||||
httpReq.Header.Set("x-api-key", cfg.APIKey)
|
||||
httpReq.Header.Set("anthropic-version", anthropicAPIVersion)
|
||||
|
||||
// Extended thinking requires the output-128k beta header
|
||||
if len(req.ExtraBody) > 0 {
|
||||
if _, hasThinking := req.ExtraBody["thinking"]; hasThinking {
|
||||
httpReq.Header.Set("anthropic-beta", "output-128k-2025-02-19")
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(httpReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("provider request: %w", err)
|
||||
@@ -458,6 +479,7 @@ type anthropicStreamEvent struct {
|
||||
Delta struct {
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Thinking string `json:"thinking"` // extended thinking delta (v0.22.1)
|
||||
StopReason string `json:"stop_reason"`
|
||||
PartialJSON string `json:"partial_json"`
|
||||
} `json:"delta"`
|
||||
|
||||
Reference in New Issue
Block a user