mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 11:08:37 +00:00
Merge pull request #2558 from seefs001/fix/gemini-tool-call
fix: gemini request -> openai tool call
This commit is contained in:
@@ -126,7 +126,7 @@ func (r *GeminiChatRequest) SetModelName(modelName string) {
|
|||||||
|
|
||||||
func (r *GeminiChatRequest) GetTools() []GeminiChatTool {
|
func (r *GeminiChatRequest) GetTools() []GeminiChatTool {
|
||||||
var tools []GeminiChatTool
|
var tools []GeminiChatTool
|
||||||
if strings.HasSuffix(string(r.Tools), "[") {
|
if strings.HasPrefix(string(r.Tools), "[") {
|
||||||
// is array
|
// is array
|
||||||
if err := common.Unmarshal(r.Tools, &tools); err != nil {
|
if err := common.Unmarshal(r.Tools, &tools); err != nil {
|
||||||
logger.LogError(nil, "error_unmarshalling_tools: "+err.Error())
|
logger.LogError(nil, "error_unmarshalling_tools: "+err.Error())
|
||||||
|
|||||||
@@ -674,20 +674,21 @@ func GeminiToOpenAIRequest(geminiRequest *dto.GeminiChatRequest, info *relaycomm
|
|||||||
var tools []dto.ToolCallRequest
|
var tools []dto.ToolCallRequest
|
||||||
for _, tool := range geminiRequest.GetTools() {
|
for _, tool := range geminiRequest.GetTools() {
|
||||||
if tool.FunctionDeclarations != nil {
|
if tool.FunctionDeclarations != nil {
|
||||||
// 将 Gemini 的 FunctionDeclarations 转换为 OpenAI 的 ToolCallRequest
|
functionDeclarations, err := common.Any2Type[[]dto.FunctionRequest](tool.FunctionDeclarations)
|
||||||
functionDeclarations, ok := tool.FunctionDeclarations.([]dto.FunctionRequest)
|
if err != nil {
|
||||||
if ok {
|
common.SysError(fmt.Sprintf("failed to parse gemini function declarations: %v (type=%T)", err, tool.FunctionDeclarations))
|
||||||
for _, function := range functionDeclarations {
|
continue
|
||||||
openAITool := dto.ToolCallRequest{
|
}
|
||||||
Type: "function",
|
for _, function := range functionDeclarations {
|
||||||
Function: dto.FunctionRequest{
|
openAITool := dto.ToolCallRequest{
|
||||||
Name: function.Name,
|
Type: "function",
|
||||||
Description: function.Description,
|
Function: dto.FunctionRequest{
|
||||||
Parameters: function.Parameters,
|
Name: function.Name,
|
||||||
},
|
Description: function.Description,
|
||||||
}
|
Parameters: function.Parameters,
|
||||||
tools = append(tools, openAITool)
|
},
|
||||||
}
|
}
|
||||||
|
tools = append(tools, openAITool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user