mirror of
https://github.com/githubhjs/CLIProxyAPIPlus.git
synced 2026-07-12 01:25:13 +00:00
fix: add signature field to thinking blocks for non-streaming mode
- Add generateThinkingSignature() function in kiro_claude_response.go
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
package claude
|
package claude
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -14,6 +16,18 @@ import (
|
|||||||
kirocommon "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/kiro/common"
|
kirocommon "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/kiro/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// generateThinkingSignature generates a signature for thinking content.
|
||||||
|
// This is required by Claude API for thinking blocks in non-streaming responses.
|
||||||
|
// The signature is a base64-encoded hash of the thinking content.
|
||||||
|
func generateThinkingSignature(thinkingContent string) string {
|
||||||
|
if thinkingContent == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// Generate a deterministic signature based on content hash
|
||||||
|
hash := sha256.Sum256([]byte(thinkingContent))
|
||||||
|
return base64.StdEncoding.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
|
|
||||||
// Local references to kirocommon constants for thinking block parsing
|
// Local references to kirocommon constants for thinking block parsing
|
||||||
var (
|
var (
|
||||||
thinkingStartTag = kirocommon.ThinkingStartTag
|
thinkingStartTag = kirocommon.ThinkingStartTag
|
||||||
@@ -149,9 +163,12 @@ func ExtractThinkingFromContent(content string) []map[string]interface{} {
|
|||||||
if endIdx == -1 {
|
if endIdx == -1 {
|
||||||
// No closing tag found, treat rest as thinking content (incomplete response)
|
// No closing tag found, treat rest as thinking content (incomplete response)
|
||||||
if strings.TrimSpace(remaining) != "" {
|
if strings.TrimSpace(remaining) != "" {
|
||||||
|
// Generate signature for thinking content (required by Claude API)
|
||||||
|
signature := generateThinkingSignature(remaining)
|
||||||
blocks = append(blocks, map[string]interface{}{
|
blocks = append(blocks, map[string]interface{}{
|
||||||
"type": "thinking",
|
"type": "thinking",
|
||||||
"thinking": remaining,
|
"thinking": remaining,
|
||||||
|
"signature": signature,
|
||||||
})
|
})
|
||||||
log.Warnf("kiro: extractThinkingFromContent - missing closing </thinking> tag")
|
log.Warnf("kiro: extractThinkingFromContent - missing closing </thinking> tag")
|
||||||
}
|
}
|
||||||
@@ -161,9 +178,12 @@ func ExtractThinkingFromContent(content string) []map[string]interface{} {
|
|||||||
// Extract thinking content between tags
|
// Extract thinking content between tags
|
||||||
thinkContent := remaining[:endIdx]
|
thinkContent := remaining[:endIdx]
|
||||||
if strings.TrimSpace(thinkContent) != "" {
|
if strings.TrimSpace(thinkContent) != "" {
|
||||||
|
// Generate signature for thinking content (required by Claude API)
|
||||||
|
signature := generateThinkingSignature(thinkContent)
|
||||||
blocks = append(blocks, map[string]interface{}{
|
blocks = append(blocks, map[string]interface{}{
|
||||||
"type": "thinking",
|
"type": "thinking",
|
||||||
"thinking": thinkContent,
|
"thinking": thinkContent,
|
||||||
|
"signature": signature,
|
||||||
})
|
})
|
||||||
log.Debugf("kiro: extractThinkingFromContent - extracted thinking block (len: %d)", len(thinkContent))
|
log.Debugf("kiro: extractThinkingFromContent - extracted thinking block (len: %d)", len(thinkContent))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user