Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
|
|
@ -0,0 +1,39 @@
|
|||
package helps
|
||||
|
||||
import (
|
||||
translatorcommon "github.com/router-for-me/CLIProxyAPI/v7/internal/translator/common"
|
||||
"github.com/router-for-me/CLIProxyAPI/v7/internal/util"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
var emptyGeminiUserTurnJSON = []byte(`{"role":"user","parts":[{"text":""}]}`)
|
||||
|
||||
// EnsureGeminiLeadingUserContent ensures that the contents array at the given path
|
||||
// starts with a user turn when sending to Gemini/Antigravity upstreams.
|
||||
func EnsureGeminiLeadingUserContent(payload []byte, path string) []byte {
|
||||
firstRole := gjson.GetBytes(payload, path+".0.role")
|
||||
if firstRole.String() != "model" {
|
||||
return payload
|
||||
}
|
||||
contents := util.GetGJSONBytesNoCopy(payload, path)
|
||||
if !contents.IsArray() {
|
||||
return payload
|
||||
}
|
||||
contentArray := contents.Array()
|
||||
if len(contentArray) == 0 {
|
||||
return payload
|
||||
}
|
||||
|
||||
contentItems := make([][]byte, 0, len(contentArray)+1)
|
||||
contentItems = append(contentItems, emptyGeminiUserTurnJSON)
|
||||
for _, content := range contentArray {
|
||||
contentItems = append(contentItems, []byte(content.Raw))
|
||||
}
|
||||
|
||||
out, errSet := sjson.SetRawBytes(payload, path, translatorcommon.JoinRawArray(contentItems))
|
||||
if errSet != nil {
|
||||
return payload
|
||||
}
|
||||
return out
|
||||
}
|
||||
Loading…
Reference in a new issue