mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-13 07:40:56 +00:00
fix: preserve Qwen thinking_budget passthrough (#5836)
* fix: preserve qwen thinking budget * test: address qwen thinking budget review comments * chore: remove unreachable adaptor code * test: cover zero Qwen thinking budgets
This commit is contained in:
@@ -89,6 +89,7 @@ type GeneralOpenAIRequest struct {
|
||||
// Ali Qwen Params
|
||||
VlHighResolutionImages json.RawMessage `json:"vl_high_resolution_images,omitempty"`
|
||||
EnableThinking json.RawMessage `json:"enable_thinking,omitempty"`
|
||||
ThinkingBudget json.RawMessage `json:"thinking_budget,omitempty"`
|
||||
ChatTemplateKwargs json.RawMessage `json:"chat_template_kwargs,omitempty"`
|
||||
EnableSearch json.RawMessage `json:"enable_search,omitempty"`
|
||||
// ollama Params
|
||||
@@ -107,6 +108,14 @@ type GeneralOpenAIRequest struct {
|
||||
ReasoningSplit json.RawMessage `json:"reasoning_split,omitempty"`
|
||||
}
|
||||
|
||||
func (r GeneralOpenAIRequest) MarshalJSON() ([]byte, error) {
|
||||
type Alias GeneralOpenAIRequest
|
||||
if !IsQwenThinkingBudgetModel(r.Model) {
|
||||
r.ThinkingBudget = nil
|
||||
}
|
||||
return kitutil.Marshal((*Alias)(&r))
|
||||
}
|
||||
|
||||
func (r *GeneralOpenAIRequest) GetTokenCountMeta() *types.TokenCountMeta {
|
||||
var tokenCountMeta types.TokenCountMeta
|
||||
var texts = make([]string, 0)
|
||||
@@ -222,6 +231,14 @@ func IsOpenAIGPT5Model(modelName string) bool {
|
||||
return strings.HasPrefix(modelName, "gpt-5")
|
||||
}
|
||||
|
||||
func IsQwenThinkingBudgetModel(modelName string) bool {
|
||||
normalized := strings.ToLower(strings.TrimSpace(modelName))
|
||||
return strings.HasPrefix(normalized, "qwen") ||
|
||||
strings.Contains(normalized, "/qwen") ||
|
||||
strings.HasPrefix(normalized, "qwq") ||
|
||||
strings.Contains(normalized, "/qwq")
|
||||
}
|
||||
|
||||
func (r *GeneralOpenAIRequest) GetSystemRoleName() string {
|
||||
if IsOpenAIReasoningOModel(r.Model) {
|
||||
if !strings.HasPrefix(r.Model, "o1-mini") && !strings.HasPrefix(r.Model, "o1-preview") {
|
||||
@@ -880,10 +897,19 @@ type OpenAIResponsesRequest struct {
|
||||
ClientMetadata json.RawMessage `json:"client_metadata,omitempty"`
|
||||
// qwen
|
||||
EnableThinking json.RawMessage `json:"enable_thinking,omitempty"`
|
||||
ThinkingBudget json.RawMessage `json:"thinking_budget,omitempty"`
|
||||
// perplexity
|
||||
Preset json.RawMessage `json:"preset,omitempty"`
|
||||
}
|
||||
|
||||
func (r OpenAIResponsesRequest) MarshalJSON() ([]byte, error) {
|
||||
type Alias OpenAIResponsesRequest
|
||||
if !IsQwenThinkingBudgetModel(r.Model) {
|
||||
r.ThinkingBudget = nil
|
||||
}
|
||||
return kitutil.Marshal((*Alias)(&r))
|
||||
}
|
||||
|
||||
func (r *OpenAIResponsesRequest) GetTokenCountMeta() *types.TokenCountMeta {
|
||||
var fileMeta = make([]*types.FileMeta, 0)
|
||||
var texts = make([]string, 0)
|
||||
|
||||
Reference in New Issue
Block a user