Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
56
backend/internal/translator/common/claude_system.go
Normal file
56
backend/internal/translator/common/claude_system.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/util"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const (
|
||||
claudeSystemReminderStart = "<system-reminder>"
|
||||
claudeSystemReminderEnd = "</system-reminder>"
|
||||
)
|
||||
|
||||
// ClaudeMessageSystemReminderText converts a Claude message-level system value
|
||||
// into ordinary user-visible reminder text for non-Claude upstream formats.
|
||||
func ClaudeMessageSystemReminderText(content gjson.Result) (string, bool) {
|
||||
parts := claudeSystemTextParts(content)
|
||||
if len(parts) == 0 {
|
||||
return "", false
|
||||
}
|
||||
text := strings.Join(parts, "\n")
|
||||
if strings.TrimSpace(text) == "" {
|
||||
return "", false
|
||||
}
|
||||
return claudeSystemReminderStart + "\n" + text + "\n" + claudeSystemReminderEnd, true
|
||||
}
|
||||
|
||||
func claudeSystemTextParts(content gjson.Result) []string {
|
||||
if !content.Exists() {
|
||||
return nil
|
||||
}
|
||||
if content.Type == gjson.String {
|
||||
text := content.String()
|
||||
if text == "" || util.IsClaudeCodeAttributionSystemText(text) {
|
||||
return nil
|
||||
}
|
||||
return []string{text}
|
||||
}
|
||||
if !content.IsArray() {
|
||||
return nil
|
||||
}
|
||||
parts := make([]string, 0)
|
||||
content.ForEach(func(_, item gjson.Result) bool {
|
||||
if item.Get("type").String() != "text" {
|
||||
return true
|
||||
}
|
||||
text := item.Get("text").String()
|
||||
if text == "" || util.IsClaudeCodeAttributionSystemText(text) {
|
||||
return true
|
||||
}
|
||||
parts = append(parts, text)
|
||||
return true
|
||||
})
|
||||
return parts
|
||||
}
|
||||
Loading…
Reference in a new issue