fix: update OpenAI request fields to use json.RawMessage for dynamic data handling
This commit is contained in:
parent
9905599d27
commit
fb76abb329
@ -56,10 +56,10 @@ type GeneralOpenAIRequest struct {
|
|||||||
Tools []ToolCallRequest `json:"tools,omitempty"`
|
Tools []ToolCallRequest `json:"tools,omitempty"`
|
||||||
ToolChoice any `json:"tool_choice,omitempty"`
|
ToolChoice any `json:"tool_choice,omitempty"`
|
||||||
FunctionCall json.RawMessage `json:"function_call,omitempty"`
|
FunctionCall json.RawMessage `json:"function_call,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
User json.RawMessage `json:"user,omitempty"`
|
||||||
// ServiceTier specifies upstream service level and may affect billing.
|
// ServiceTier specifies upstream service level and may affect billing.
|
||||||
// This field is filtered by default and can be enabled via channel setting allow_service_tier.
|
// This field is filtered by default and can be enabled via channel setting allow_service_tier.
|
||||||
ServiceTier string `json:"service_tier,omitempty"`
|
ServiceTier json.RawMessage `json:"service_tier,omitempty"`
|
||||||
LogProbs *bool `json:"logprobs,omitempty"`
|
LogProbs *bool `json:"logprobs,omitempty"`
|
||||||
TopLogProbs *int `json:"top_logprobs,omitempty"`
|
TopLogProbs *int `json:"top_logprobs,omitempty"`
|
||||||
Dimensions *int `json:"dimensions,omitempty"`
|
Dimensions *int `json:"dimensions,omitempty"`
|
||||||
@ -67,7 +67,7 @@ type GeneralOpenAIRequest struct {
|
|||||||
Audio json.RawMessage `json:"audio,omitempty"`
|
Audio json.RawMessage `json:"audio,omitempty"`
|
||||||
// 安全标识符,用于帮助 OpenAI 检测可能违反使用政策的应用程序用户
|
// 安全标识符,用于帮助 OpenAI 检测可能违反使用政策的应用程序用户
|
||||||
// 注意:此字段会向 OpenAI 发送用户标识信息,默认过滤,可通过 allow_safety_identifier 开启
|
// 注意:此字段会向 OpenAI 发送用户标识信息,默认过滤,可通过 allow_safety_identifier 开启
|
||||||
SafetyIdentifier string `json:"safety_identifier,omitempty"`
|
SafetyIdentifier json.RawMessage `json:"safety_identifier,omitempty"`
|
||||||
// Whether or not to store the output of this chat completion request for use in our model distillation or evals products.
|
// Whether or not to store the output of this chat completion request for use in our model distillation or evals products.
|
||||||
// 是否存储此次请求数据供 OpenAI 用于评估和优化产品
|
// 是否存储此次请求数据供 OpenAI 用于评估和优化产品
|
||||||
// 注意:默认允许透传,可通过 disable_store 禁用;禁用后可能导致 Codex 无法正常使用
|
// 注意:默认允许透传,可通过 disable_store 禁用;禁用后可能导致 Codex 无法正常使用
|
||||||
@ -100,10 +100,10 @@ type GeneralOpenAIRequest struct {
|
|||||||
THINKING json.RawMessage `json:"thinking,omitempty"`
|
THINKING json.RawMessage `json:"thinking,omitempty"`
|
||||||
// pplx Params
|
// pplx Params
|
||||||
SearchDomainFilter json.RawMessage `json:"search_domain_filter,omitempty"`
|
SearchDomainFilter json.RawMessage `json:"search_domain_filter,omitempty"`
|
||||||
SearchRecencyFilter string `json:"search_recency_filter,omitempty"`
|
SearchRecencyFilter json.RawMessage `json:"search_recency_filter,omitempty"`
|
||||||
ReturnImages *bool `json:"return_images,omitempty"`
|
ReturnImages *bool `json:"return_images,omitempty"`
|
||||||
ReturnRelatedQuestions *bool `json:"return_related_questions,omitempty"`
|
ReturnRelatedQuestions *bool `json:"return_related_questions,omitempty"`
|
||||||
SearchMode string `json:"search_mode,omitempty"`
|
SearchMode json.RawMessage `json:"search_mode,omitempty"`
|
||||||
// Minimax
|
// Minimax
|
||||||
ReasoningSplit json.RawMessage `json:"reasoning_split,omitempty"`
|
ReasoningSplit json.RawMessage `json:"reasoning_split,omitempty"`
|
||||||
}
|
}
|
||||||
@ -836,7 +836,7 @@ type OpenAIResponsesRequest struct {
|
|||||||
PromptCacheRetention json.RawMessage `json:"prompt_cache_retention,omitempty"`
|
PromptCacheRetention json.RawMessage `json:"prompt_cache_retention,omitempty"`
|
||||||
// SafetyIdentifier carries client identity for policy abuse detection.
|
// SafetyIdentifier carries client identity for policy abuse detection.
|
||||||
// This field is filtered by default and can be enabled via channel setting allow_safety_identifier.
|
// This field is filtered by default and can be enabled via channel setting allow_safety_identifier.
|
||||||
SafetyIdentifier string `json:"safety_identifier,omitempty"`
|
SafetyIdentifier json.RawMessage `json:"safety_identifier,omitempty"`
|
||||||
Stream *bool `json:"stream,omitempty"`
|
Stream *bool `json:"stream,omitempty"`
|
||||||
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
|
||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
@ -844,8 +844,8 @@ type OpenAIResponsesRequest struct {
|
|||||||
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
|
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
|
||||||
Tools json.RawMessage `json:"tools,omitempty"` // 需要处理的参数很少,MCP 参数太多不确定,所以用 map
|
Tools json.RawMessage `json:"tools,omitempty"` // 需要处理的参数很少,MCP 参数太多不确定,所以用 map
|
||||||
TopP *float64 `json:"top_p,omitempty"`
|
TopP *float64 `json:"top_p,omitempty"`
|
||||||
Truncation string `json:"truncation,omitempty"`
|
Truncation json.RawMessage `json:"truncation,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
User json.RawMessage `json:"user,omitempty"`
|
||||||
MaxToolCalls *uint `json:"max_tool_calls,omitempty"`
|
MaxToolCalls *uint `json:"max_tool_calls,omitempty"`
|
||||||
Prompt json.RawMessage `json:"prompt,omitempty"`
|
Prompt json.RawMessage `json:"prompt,omitempty"`
|
||||||
// qwen
|
// qwen
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package baidu
|
package baidu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/QuantumNous/new-api/dto"
|
"github.com/QuantumNous/new-api/dto"
|
||||||
@ -12,16 +13,16 @@ type BaiduMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BaiduChatRequest struct {
|
type BaiduChatRequest struct {
|
||||||
Messages []BaiduMessage `json:"messages"`
|
Messages []BaiduMessage `json:"messages"`
|
||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
TopP float64 `json:"top_p,omitempty"`
|
TopP float64 `json:"top_p,omitempty"`
|
||||||
PenaltyScore float64 `json:"penalty_score,omitempty"`
|
PenaltyScore float64 `json:"penalty_score,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
System string `json:"system,omitempty"`
|
System string `json:"system,omitempty"`
|
||||||
DisableSearch bool `json:"disable_search,omitempty"`
|
DisableSearch bool `json:"disable_search,omitempty"`
|
||||||
EnableCitation bool `json:"enable_citation,omitempty"`
|
EnableCitation bool `json:"enable_citation,omitempty"`
|
||||||
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
|
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
|
||||||
UserId string `json:"user_id,omitempty"`
|
UserId json.RawMessage `json:"user_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ type CozeEnterMessage struct {
|
|||||||
|
|
||||||
type CozeChatRequest struct {
|
type CozeChatRequest struct {
|
||||||
BotId string `json:"bot_id"`
|
BotId string `json:"bot_id"`
|
||||||
UserId string `json:"user_id"`
|
UserId json.RawMessage `json:"user_id"`
|
||||||
AdditionalMessages []CozeEnterMessage `json:"additional_messages,omitempty"`
|
AdditionalMessages []CozeEnterMessage `json:"additional_messages,omitempty"`
|
||||||
Stream bool `json:"stream,omitempty"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
CustomVariables json.RawMessage `json:"custom_variables,omitempty"`
|
CustomVariables json.RawMessage `json:"custom_variables,omitempty"`
|
||||||
|
|||||||
@ -34,8 +34,8 @@ func convertCozeChatRequest(c *gin.Context, request dto.GeneralOpenAIRequest) *C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
user := request.User
|
user := request.User
|
||||||
if user == "" {
|
if len(user) == 0 {
|
||||||
user = helper.GetResponseID(c)
|
user = json.RawMessage(helper.GetResponseID(c))
|
||||||
}
|
}
|
||||||
cozeRequest := &CozeChatRequest{
|
cozeRequest := &CozeChatRequest{
|
||||||
BotId: c.GetString("bot_id"),
|
BotId: c.GetString("bot_id"),
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package dify
|
package dify
|
||||||
|
|
||||||
import "github.com/QuantumNous/new-api/dto"
|
import (
|
||||||
|
"github.com/QuantumNous/new-api/dto"
|
||||||
|
)
|
||||||
|
|
||||||
type DifyChatRequest struct {
|
type DifyChatRequest struct {
|
||||||
Inputs map[string]interface{} `json:"inputs"`
|
Inputs map[string]interface{} `json:"inputs"`
|
||||||
|
|||||||
@ -131,10 +131,16 @@ func requestOpenAI2Dify(c *gin.Context, info *relaycommon.RelayInfo, request dto
|
|||||||
}
|
}
|
||||||
|
|
||||||
user := request.User
|
user := request.User
|
||||||
if user == "" {
|
if len(user) == 0 {
|
||||||
user = helper.GetResponseID(c)
|
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)
|
files := make([]DifyFile, 0)
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user