mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
26 lines
1.3 KiB
Go
26 lines
1.3 KiB
Go
// Package gemini provides request translation functionality for Claude API.
|
|
// It handles parsing and transforming Claude API requests into the internal client format,
|
|
// extracting model information, system instructions, message contents, and tool declarations.
|
|
// The package also performs JSON data cleaning and transformation to ensure compatibility
|
|
// between Claude API format and the internal client's expected format.
|
|
package geminiCLI
|
|
|
|
import (
|
|
"github.com/tidwall/gjson"
|
|
"github.com/tidwall/sjson"
|
|
)
|
|
|
|
// PrepareClaudeRequest parses and transforms a Claude API request into internal client format.
|
|
// It extracts the model name, system instruction, message contents, and tool declarations
|
|
// from the raw JSON request and returns them in the format expected by the internal client.
|
|
func ConvertGeminiCLIRequestToGemini(_ string, rawJSON []byte, _ bool) []byte {
|
|
modelResult := gjson.GetBytes(rawJSON, "model")
|
|
rawJSON = []byte(gjson.GetBytes(rawJSON, "request").Raw)
|
|
rawJSON, _ = sjson.SetBytes(rawJSON, "model", modelResult.String())
|
|
if gjson.GetBytes(rawJSON, "systemInstruction").Exists() {
|
|
rawJSON, _ = sjson.SetRawBytes(rawJSON, "system_instruction", []byte(gjson.GetBytes(rawJSON, "systemInstruction").Raw))
|
|
rawJSON, _ = sjson.DeleteBytes(rawJSON, "systemInstruction")
|
|
}
|
|
return rawJSON
|
|
}
|