mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(translator): unify model group references by introducing GetModelGroup helper function
This commit is contained in:
16
internal/cache/signature_cache.go
vendored
16
internal/cache/signature_cache.go
vendored
@@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -103,7 +104,7 @@ func CacheSignature(modelName, sessionID, text, signature string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sc := getOrCreateSession(fmt.Sprintf("%s#%s", modelName, sessionID))
|
sc := getOrCreateSession(fmt.Sprintf("%s#%s", GetModelGroup(modelName), sessionID))
|
||||||
textHash := hashText(text)
|
textHash := hashText(text)
|
||||||
|
|
||||||
sc.mu.Lock()
|
sc.mu.Lock()
|
||||||
@@ -122,7 +123,7 @@ func GetCachedSignature(modelName, sessionID, text string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
val, ok := signatureCache.Load(fmt.Sprintf("%s#%s", modelName, sessionID))
|
val, ok := signatureCache.Load(fmt.Sprintf("%s#%s", GetModelGroup(modelName), sessionID))
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -168,3 +169,14 @@ func ClearSignatureCache(sessionID string) {
|
|||||||
func HasValidSignature(signature string) bool {
|
func HasValidSignature(signature string) bool {
|
||||||
return signature != "" && len(signature) >= MinValidSignatureLen
|
return signature != "" && len(signature) >= MinValidSignatureLen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetModelGroup(modelName string) string {
|
||||||
|
if strings.Contains(modelName, "gpt") {
|
||||||
|
return "gpt"
|
||||||
|
} else if strings.Contains(modelName, "claude") {
|
||||||
|
return "claude"
|
||||||
|
} else if strings.Contains(modelName, "gemini") {
|
||||||
|
return "gemini"
|
||||||
|
}
|
||||||
|
return modelName
|
||||||
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func ConvertAntigravityResponseToClaude(_ context.Context, _ string, originalReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
output = output + "event: content_block_delta\n"
|
output = output + "event: content_block_delta\n"
|
||||||
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"signature_delta","signature":""}}`, params.ResponseIndex), "delta.signature", fmt.Sprintf("%s#%s", modelName, thoughtSignature.String()))
|
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"signature_delta","signature":""}}`, params.ResponseIndex), "delta.signature", fmt.Sprintf("%s#%s", cache.GetModelGroup(modelName), thoughtSignature.String()))
|
||||||
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
||||||
params.HasContent = true
|
params.HasContent = true
|
||||||
} else if params.ResponseType == 2 { // Continue existing thinking block if already in thinking state
|
} else if params.ResponseType == 2 { // Continue existing thinking block if already in thinking state
|
||||||
@@ -438,7 +438,7 @@ func ConvertAntigravityResponseToClaudeNonStream(_ context.Context, _ string, or
|
|||||||
block := `{"type":"thinking","thinking":""}`
|
block := `{"type":"thinking","thinking":""}`
|
||||||
block, _ = sjson.Set(block, "thinking", thinkingBuilder.String())
|
block, _ = sjson.Set(block, "thinking", thinkingBuilder.String())
|
||||||
if thinkingSignature != "" {
|
if thinkingSignature != "" {
|
||||||
block, _ = sjson.Set(block, "signature", fmt.Sprintf("%s#%s", modelName, thinkingSignature))
|
block, _ = sjson.Set(block, "signature", fmt.Sprintf("%s#%s", cache.GetModelGroup(modelName), thinkingSignature))
|
||||||
}
|
}
|
||||||
responseJSON, _ = sjson.SetRaw(responseJSON, "content.-1", block)
|
responseJSON, _ = sjson.SetRaw(responseJSON, "content.-1", block)
|
||||||
thinkingBuilder.Reset()
|
thinkingBuilder.Reset()
|
||||||
|
|||||||
Reference in New Issue
Block a user