mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-17 03:27:02 +08:00
feat: gpt-5.6 support
This commit is contained in:
@@ -29,7 +29,7 @@ type openAIRequestBody struct {
|
||||
Tools []json.RawMessage `json:"tools,omitempty"`
|
||||
Messages []map[string]any `json:"messages"`
|
||||
Stream bool `json:"stream"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
MaxTokens int `json:"max_tokens,omitempty"`
|
||||
StreamOptions map[string]any `json:"stream_options"`
|
||||
ReasoningEffort string `json:"reasoning_effort,omitempty"`
|
||||
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
|
||||
@@ -41,7 +41,7 @@ type openAIResponsesRequestBody struct {
|
||||
Input []map[string]any `json:"input"`
|
||||
Tools []map[string]any `json:"tools,omitempty"`
|
||||
Stream bool `json:"stream"`
|
||||
MaxOutputTokens int `json:"max_output_tokens"`
|
||||
MaxOutputTokens int `json:"max_output_tokens,omitempty"`
|
||||
Reasoning *openAIResponsesReasoning `json:"reasoning,omitempty"`
|
||||
Include []string `json:"include,omitempty"`
|
||||
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
|
||||
@@ -455,9 +455,11 @@ func (adapter *OpenAIAdapter) streamChatCompletions(ctx context.Context, req Str
|
||||
Model: modelID,
|
||||
Messages: normalizedMessages,
|
||||
Stream: true,
|
||||
MaxTokens: req.MaxTokens,
|
||||
StreamOptions: map[string]any{"include_usage": true},
|
||||
}
|
||||
if shouldSendOpenAIMaxOutputTokens(modelID) {
|
||||
requestBody.MaxTokens = req.MaxTokens
|
||||
}
|
||||
if key := openAIPromptCacheKey(req, modelID); key != "" {
|
||||
requestBody.PromptCacheKey = key
|
||||
}
|
||||
@@ -914,12 +916,14 @@ func (adapter *OpenAIAdapter) streamResponses(ctx context.Context, req StreamReq
|
||||
return err
|
||||
}
|
||||
requestBody := openAIResponsesRequestBody{
|
||||
Model: modelID,
|
||||
Instructions: instructions,
|
||||
Input: input,
|
||||
Stream: true,
|
||||
MaxOutputTokens: req.MaxTokens,
|
||||
Store: false,
|
||||
Model: modelID,
|
||||
Instructions: instructions,
|
||||
Input: input,
|
||||
Stream: true,
|
||||
Store: false,
|
||||
}
|
||||
if shouldSendOpenAIMaxOutputTokens(modelID) {
|
||||
requestBody.MaxOutputTokens = req.MaxTokens
|
||||
}
|
||||
if key := openAIPromptCacheKey(req, modelID); key != "" {
|
||||
requestBody.PromptCacheKey = key
|
||||
@@ -1844,6 +1848,10 @@ func normalizeOpenAIProviderMessages(messages []Message, thinkingEnabled bool) (
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func shouldSendOpenAIMaxOutputTokens(modelID string) bool {
|
||||
return !strings.Contains(strings.ToLower(strings.TrimSpace(modelID)), "gpt")
|
||||
}
|
||||
|
||||
func shouldIncludeOpenAIReasoningContent(message Message, thinkingEnabled bool) bool {
|
||||
if strings.TrimSpace(message.ReasoningContent) != "" {
|
||||
return true
|
||||
|
||||
@@ -152,7 +152,7 @@ func NormalizeModelAdapterConfigs(input []ModelAdapterConfig) ([]ModelAdapterCon
|
||||
case next.ModelID == "":
|
||||
return nil, errors.New("模型适配器 modelID 不能为空")
|
||||
case next.Type == "openai" && next.ReasoningEffort == "":
|
||||
return nil, errors.New("模型适配器 reasoningEffort 仅支持 low、medium、high、xhigh")
|
||||
return nil, errors.New("模型适配器 reasoningEffort 仅支持 low、medium、high、xhigh、max")
|
||||
case next.Type == "openai" && next.OpenAIEndpoint == "":
|
||||
return nil, errors.New("模型适配器 openAIEndpoint 仅支持 /v1/responses、/v1/chat/completions 或 /custom(自定义路径)")
|
||||
case next.Type == "openai" && next.OpenAIExtraParamsEnabled:
|
||||
@@ -216,7 +216,7 @@ func normalizeReasoningEffort(value string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "", "medium":
|
||||
return "medium"
|
||||
case "low", "high", "xhigh":
|
||||
case "low", "high", "xhigh", "max":
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
default:
|
||||
return ""
|
||||
|
||||
@@ -746,7 +746,7 @@ func buildThinkingEffortVariantDisplayName(modelDisplayName string, effortValue
|
||||
|
||||
func thinkingEffortValuesForAdapter(adapterType string) []string {
|
||||
values := []string{"disabled", "low", "medium", "high", "xhigh"}
|
||||
if strings.EqualFold(strings.TrimSpace(adapterType), "anthropic") {
|
||||
if adapterType := strings.ToLower(strings.TrimSpace(adapterType)); adapterType == "openai" || adapterType == "anthropic" {
|
||||
values = append(values, "max")
|
||||
}
|
||||
return values
|
||||
@@ -773,7 +773,7 @@ func defaultThinkingEffortForAdapter(adapter legacyruntime.ModelAdapterConfig) s
|
||||
if strings.EqualFold(strings.TrimSpace(adapter.Type), "anthropic") {
|
||||
return normalizeAvailableModelThinkingEffort(adapter.AnthropicThinkingEffort, true, "xhigh")
|
||||
}
|
||||
return normalizeAvailableModelThinkingEffort(adapter.ReasoningEffort, false, "medium")
|
||||
return normalizeAvailableModelThinkingEffort(adapter.ReasoningEffort, true, "medium")
|
||||
}
|
||||
|
||||
func normalizeAvailableModelThinkingEffort(raw string, allowMax bool, fallback string) string {
|
||||
|
||||
@@ -668,7 +668,7 @@ func normalizeModelAdapterTestType(value string) string {
|
||||
|
||||
func normalizeModelAdapterTestReasoning(value string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "low", "medium", "high", "xhigh":
|
||||
case "low", "medium", "high", "xhigh", "max":
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
default:
|
||||
return "medium"
|
||||
|
||||
@@ -138,7 +138,7 @@ func NormalizeModelAdapterConfigs(input []ModelAdapterConfig) ([]ModelAdapterCon
|
||||
case next.ModelID == "":
|
||||
return nil, errors.New("模型适配器 modelID 不能为空")
|
||||
case next.Type == "openai" && next.ReasoningEffort == "":
|
||||
return nil, errors.New("模型适配器 reasoningEffort 仅支持 low、medium、high、xhigh")
|
||||
return nil, errors.New("模型适配器 reasoningEffort 仅支持 low、medium、high、xhigh、max")
|
||||
case next.Type == "openai" && next.OpenAIEndpoint == "":
|
||||
return nil, errors.New("模型适配器 openAIEndpoint 仅支持 /v1/responses 或 /v1/chat/completions")
|
||||
case next.Type == "openai" && next.OpenAIExtraParamsEnabled:
|
||||
@@ -202,7 +202,7 @@ func normalizeReasoningEffort(value string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "", "medium":
|
||||
return "medium"
|
||||
case "low", "high", "xhigh":
|
||||
case "low", "high", "xhigh", "max":
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
default:
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user