Enhance OpenAI Provider Request Body with Thinking Parameter

- Added support for a new "thinking" parameter in the request body for models that support reasoning/thinking mode, improving functionality.
- Updated the request body construction to include debugging output for the full request body, aiding in troubleshooting and development.
- Ensured that the model and other settings are retrieved from the connector, maintaining consistency in configuration handling.
This commit is contained in:
Max 2026-01-25 11:50:09 +08:00
parent 042066e6b3
commit 994950f273

View file

@ -1039,13 +1039,19 @@ func (p *Provider) buildRequestBody(messages []context.Message, options *context
return nil, fmt.Errorf("options are required")
}
// Get model from connector settings
// Get model and other settings from connector
setting := p.Connector.Setting()
model, ok := setting["model"].(string)
if !ok || model == "" {
return nil, fmt.Errorf("model is not set in connector")
}
// Get thinking setting from connector (for models that support reasoning/thinking mode)
var thinkingSetting interface{}
if thinking, exists := setting["thinking"]; exists {
thinkingSetting = thinking
}
// Convert messages to API format
apiMessages := make([]map[string]interface{}, 0, len(messages))
for _, msg := range messages {
@ -1202,6 +1208,17 @@ func (p *Provider) buildRequestBody(messages []context.Message, options *context
body["audio"] = options.Audio
}
// Add thinking parameter for models that support reasoning/thinking mode
if thinkingSetting != nil {
body["thinking"] = thinkingSetting
fmt.Printf("[DEBUG] Adding thinking parameter to request: %+v\n", thinkingSetting)
}
// Debug: Print full request body
if bodyJSON, err := jsoniter.MarshalIndent(body, "", " "); err == nil {
fmt.Printf("[DEBUG] Request body:\n%s\n", string(bodyJSON))
}
return body, nil
}