Download internal/translator/openai/gemini-cli/openai_gemini_request.go from shimen/API: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/shimen/API/resolve/main/internal/translator/openai/gemini-cli/openai_gemini_request.go
- Command line
-
hf download hf://spaces/shimen/API/internal/translator/openai/gemini-cli/openai_gemini_request.go
-
curl -L -o openai_gemini_request.go https://huggingface.co/spaces/shimen/API/resolve/main/internal/translator/openai/gemini-cli/openai_gemini_request.go
1.46 kB
| // Package geminiCLI provides request translation functionality for Gemini to OpenAI API. | |
| // It handles parsing and transforming Gemini API requests into OpenAI Chat Completions API format, | |
| // extracting model information, generation config, message contents, and tool declarations. | |
| // The package performs JSON data transformation to ensure compatibility | |
| // between Gemini API format and OpenAI API's expected format. | |
| package geminiCLI | |
| import ( | |
| "bytes" | |
| . "github.com/router-for-me/CLIProxyAPI/v6/internal/translator/openai/gemini" | |
| "github.com/tidwall/gjson" | |
| "github.com/tidwall/sjson" | |
| ) | |
| // ConvertGeminiCLIRequestToOpenAI parses and transforms a Gemini API request into OpenAI Chat Completions API format. | |
| // It extracts the model name, generation config, message contents, and tool declarations | |
| // from the raw JSON request and returns them in the format expected by the OpenAI API. | |
| func ConvertGeminiCLIRequestToOpenAI(modelName string, inputRawJSON []byte, stream bool) []byte { | |
| rawJSON := bytes.Clone(inputRawJSON) | |
| rawJSON = []byte(gjson.GetBytes(rawJSON, "request").Raw) | |
| rawJSON, _ = sjson.SetBytes(rawJSON, "model", modelName) | |
| if gjson.GetBytes(rawJSON, "systemInstruction").Exists() { | |
| rawJSON, _ = sjson.SetRawBytes(rawJSON, "system_instruction", []byte(gjson.GetBytes(rawJSON, "systemInstruction").Raw)) | |
| rawJSON, _ = sjson.DeleteBytes(rawJSON, "systemInstruction") | |
| } | |
| return ConvertGeminiRequestToOpenAI(modelName, rawJSON, stream) | |
| } | |