feat(chat): add Volcengine support and refactor thinking configuration

- Introduced Volcengine as a new provider in the chat provider specifications.
- Refactored the thinking configuration to a more generic format, applicable to both LKEAP and Volcengine.
- Updated request customizers to handle the new thinking configuration structure for both LKEAP and Volcengine providers.
This commit is contained in:
wizardchen
2026-03-24 13:19:35 +08:00
committed by lyingbug
parent 3e3ffa4b0b
commit e7c21c0733
+36 -8
View File
@@ -46,6 +46,11 @@ var chatProviderSpecs = []ProviderSpec{
Provider: provider.ProviderGeneric, Provider: provider.ProviderGeneric,
RequestCustomizer: genericRequestCustomizer, RequestCustomizer: genericRequestCustomizer,
}, },
// Volcengine (火山引擎 Ark)
{
Provider: provider.ProviderVolcengine,
RequestCustomizer: volcengineRequestCustomizer,
},
// NVIDIA // NVIDIA
{ {
Provider: provider.ProviderNvidia, Provider: provider.ProviderNvidia,
@@ -76,15 +81,16 @@ type QwenChatCompletionRequest struct {
EnableThinking *bool `json:"enable_thinking,omitempty"` EnableThinking *bool `json:"enable_thinking,omitempty"`
} }
// LKEAPThinkingConfig 思维链配置(LKEAP 特有格式) // ThinkingConfig 思维链配置(LKEAP / Volcengine 等通用格式)
type LKEAPThinkingConfig struct { type ThinkingConfig struct {
Type string `json:"type"` // "enabled" 或 "disabled" Type string `json:"type"` // "enabled" 或 "disabled"
} }
// LKEAPChatCompletionRequest LKEAP 自定义请求结构体 // ThinkingChatCompletionRequest 带 thinking 字段的自定义请求结构体
type LKEAPChatCompletionRequest struct { // 适用于 LKEAP、Volcengine 等使用 { "thinking": { "type": "enabled" } } 格式的 provider
type ThinkingChatCompletionRequest struct {
openai.ChatCompletionRequest openai.ChatCompletionRequest
Thinking *LKEAPThinkingConfig `json:"thinking,omitempty"` // 思维链开关(仅 V3.x 系列) Thinking *ThinkingConfig `json:"thinking,omitempty"`
} }
// --- Customizer functions --- // --- Customizer functions ---
@@ -116,7 +122,7 @@ func lkeapRequestCustomizer(
return nil, false return nil, false
} }
lkeapReq := LKEAPChatCompletionRequest{ lkeapReq := ThinkingChatCompletionRequest{
ChatCompletionRequest: *req, ChatCompletionRequest: *req,
} }
@@ -124,7 +130,7 @@ func lkeapRequestCustomizer(
if *opts.Thinking { if *opts.Thinking {
thinkingType = "enabled" thinkingType = "enabled"
} }
lkeapReq.Thinking = &LKEAPThinkingConfig{Type: thinkingType} lkeapReq.Thinking = &ThinkingConfig{Type: thinkingType}
return lkeapReq, true return lkeapReq, true
} }
@@ -153,7 +159,29 @@ func genericRequestCustomizer(
req.ChatTemplateKwargs = map[string]interface{}{ req.ChatTemplateKwargs = map[string]interface{}{
"enable_thinking": thinking, "enable_thinking": thinking,
} }
return nil, false return req, true
}
// volcengineRequestCustomizer 自定义火山引擎请求
// 火山引擎使用 thinking 参数控制深度思考,格式同 LKEAP: { "type": "enabled"/"disabled" }
func volcengineRequestCustomizer(
req *openai.ChatCompletionRequest, opts *ChatOptions, _ bool,
) (any, bool) {
if opts == nil || opts.Thinking == nil {
return nil, false
}
vcReq := ThinkingChatCompletionRequest{
ChatCompletionRequest: *req,
}
thinkingType := "disabled"
if *opts.Thinking {
thinkingType = "enabled"
}
vcReq.Thinking = &ThinkingConfig{Type: thinkingType}
return vcReq, true
} }
// nvidiaEndpointCustomizer 自定义 NVIDIA 请求地址 // nvidiaEndpointCustomizer 自定义 NVIDIA 请求地址