mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
Add OpenAI Responses support
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
. "github.com/luispater/CLIProxyAPI/internal/translator/gemini-cli/gemini"
|
||||
. "github.com/luispater/CLIProxyAPI/internal/translator/gemini/openai/responses"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
func ConvertOpenAIResponsesRequestToGeminiCLI(modelName string, rawJSON []byte, stream 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 ConvertOpenAIResponsesRequestToGemini(modelName, rawJSON, stream)
|
||||
func ConvertOpenAIResponsesRequestToGeminiCLI(modelName string, inputRawJSON []byte, stream bool) []byte {
|
||||
rawJSON := bytes.Clone(inputRawJSON)
|
||||
rawJSON = ConvertOpenAIResponsesRequestToGemini(modelName, rawJSON, stream)
|
||||
return ConvertGeminiRequestToGeminiCLI(modelName, rawJSON, stream)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
package responses
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func ConvertGeminiCLIResponseToOpenAIResponses(_ context.Context, modelName string, rawJSON []byte, param *any) []string {
|
||||
return nil
|
||||
. "github.com/luispater/CLIProxyAPI/internal/translator/gemini/openai/responses"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func ConvertGeminiCLIResponseToOpenAIResponses(ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string {
|
||||
responseResult := gjson.GetBytes(rawJSON, "response")
|
||||
if responseResult.Exists() {
|
||||
rawJSON = []byte(responseResult.Raw)
|
||||
}
|
||||
return ConvertGeminiResponseToOpenAIResponses(ctx, modelName, originalRequestRawJSON, requestRawJSON, rawJSON, param)
|
||||
}
|
||||
|
||||
func ConvertGeminiCLIResponseToOpenAIResponsesNonStream(_ context.Context, _ string, rawJSON []byte, _ *any) string {
|
||||
return ""
|
||||
func ConvertGeminiCLIResponseToOpenAIResponsesNonStream(ctx context.Context, modelName string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) string {
|
||||
responseResult := gjson.GetBytes(rawJSON, "response")
|
||||
if responseResult.Exists() {
|
||||
rawJSON = []byte(responseResult.Raw)
|
||||
}
|
||||
|
||||
requestResult := gjson.GetBytes(originalRequestRawJSON, "request")
|
||||
if responseResult.Exists() {
|
||||
originalRequestRawJSON = []byte(requestResult.Raw)
|
||||
}
|
||||
|
||||
requestResult = gjson.GetBytes(requestRawJSON, "request")
|
||||
if responseResult.Exists() {
|
||||
requestRawJSON = []byte(requestResult.Raw)
|
||||
}
|
||||
|
||||
return ConvertGeminiResponseToOpenAIResponsesNonStream(ctx, modelName, originalRequestRawJSON, requestRawJSON, rawJSON, param)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user