fix: update OpenAI request fields to use json.RawMessage for dynamic data handling

This commit is contained in:
CaIon
2026-03-06 19:10:37 +08:00
parent 4d421f525e
commit 782124510a
6 changed files with 34 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
package baidu
import (
"encoding/json"
"time"
"github.com/QuantumNous/new-api/dto"
@@ -12,16 +13,16 @@ type BaiduMessage struct {
}
type BaiduChatRequest struct {
Messages []BaiduMessage `json:"messages"`
Temperature *float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
PenaltyScore float64 `json:"penalty_score,omitempty"`
Stream bool `json:"stream,omitempty"`
System string `json:"system,omitempty"`
DisableSearch bool `json:"disable_search,omitempty"`
EnableCitation bool `json:"enable_citation,omitempty"`
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
UserId string `json:"user_id,omitempty"`
Messages []BaiduMessage `json:"messages"`
Temperature *float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
PenaltyScore float64 `json:"penalty_score,omitempty"`
Stream bool `json:"stream,omitempty"`
System string `json:"system,omitempty"`
DisableSearch bool `json:"disable_search,omitempty"`
EnableCitation bool `json:"enable_citation,omitempty"`
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
UserId json.RawMessage `json:"user_id,omitempty"`
}
type Error struct {

View File

@@ -17,7 +17,7 @@ type CozeEnterMessage struct {
type CozeChatRequest struct {
BotId string `json:"bot_id"`
UserId string `json:"user_id"`
UserId json.RawMessage `json:"user_id"`
AdditionalMessages []CozeEnterMessage `json:"additional_messages,omitempty"`
Stream bool `json:"stream,omitempty"`
CustomVariables json.RawMessage `json:"custom_variables,omitempty"`

View File

@@ -34,8 +34,8 @@ func convertCozeChatRequest(c *gin.Context, request dto.GeneralOpenAIRequest) *C
}
}
user := request.User
if user == "" {
user = helper.GetResponseID(c)
if len(user) == 0 {
user = json.RawMessage(helper.GetResponseID(c))
}
cozeRequest := &CozeChatRequest{
BotId: c.GetString("bot_id"),

View File

@@ -1,6 +1,8 @@
package dify
import "github.com/QuantumNous/new-api/dto"
import (
"github.com/QuantumNous/new-api/dto"
)
type DifyChatRequest struct {
Inputs map[string]interface{} `json:"inputs"`

View File

@@ -131,10 +131,16 @@ func requestOpenAI2Dify(c *gin.Context, info *relaycommon.RelayInfo, request dto
}
user := request.User
if user == "" {
user = helper.GetResponseID(c)
if len(user) == 0 {
user = json.RawMessage(helper.GetResponseID(c))
}
difyReq.User = user
var stringUser string
err := json.Unmarshal(user, &stringUser)
if err != nil {
common.SysLog("failed to unmarshal user: " + err.Error())
stringUser = helper.GetResponseID(c)
}
difyReq.User = stringUser
files := make([]DifyFile, 0)
var content strings.Builder