diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 74cbb511138..120e2205c59 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -89,7 +89,20 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl const modelId = this.options.openAiModelId ?? "" const enabledR1Format = this.options.openAiR1FormatEnabled ?? false const isAzureAiInference = this._isAzureAiInference(modelUrl) - const deepseekReasoner = modelId.includes("deepseek-reasoner") || enabledR1Format + // Auto-detect reasoning/thinking models that require R1 format: + // - DeepSeek Reasoner models + // - Models with "thinking" suffix (e.g., kimi-k2-thinking) + // - DeepSeek R1 models (deepseek-r1, deepseek/deepseek-r1) + // - QWQ models + // - Or when user explicitly enables R1 format + const modelIdLower = modelId.toLowerCase() + const useR1Format = + enabledR1Format || + modelIdLower.includes("deepseek-reasoner") || + modelIdLower.includes("-thinking") || + modelIdLower.includes("deepseek-r1") || + modelIdLower.includes("/deepseek-r1") || + modelIdLower.includes("qwq") if (modelId.includes("o1") || modelId.includes("o3") || modelId.includes("o4")) { yield* this.handleO3FamilyMessage(modelId, systemPrompt, messages, metadata) @@ -104,7 +117,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl if (this.options.openAiStreamingEnabled ?? true) { let convertedMessages - if (deepseekReasoner) { + if (useR1Format) { convertedMessages = convertToR1Format([{ role: "user", content: systemPrompt }, ...messages]) } else { if (modelInfo.supportsPromptCache) { @@ -154,7 +167,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = { model: modelId, - temperature: this.options.modelTemperature ?? (deepseekReasoner ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0), + temperature: this.options.modelTemperature ?? (useR1Format ? DEEP_SEEK_DEFAULT_TEMPERATURE : 0), messages: convertedMessages, stream: true as const, ...(isGrokXAI ? {} : { stream_options: { include_usage: true } }), @@ -223,7 +236,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } else { const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsNonStreaming = { model: modelId, - messages: deepseekReasoner + messages: useR1Format ? convertToR1Format([{ role: "user", content: systemPrompt }, ...messages]) : [systemMessage, ...convertToOpenAiMessages(messages)], // Tools are always present (minimum ALWAYS_AVAILABLE_TOOLS) diff --git a/webview-ui/src/i18n/locales/ca/settings.json b/webview-ui/src/i18n/locales/ca/settings.json index 1509137a902..8763d5d10c0 100644 --- a/webview-ui/src/i18n/locales/ca/settings.json +++ b/webview-ui/src/i18n/locales/ca/settings.json @@ -878,8 +878,8 @@ "cacheReadsPrice": "Preu de lectures de caché", "cacheWritesPrice": "Preu d'escriptures de caché", "enableStreaming": "Habilitar streaming", - "enableR1Format": "Activar els paràmetres del model R1", - "enableR1FormatTips": "S'ha d'activat quan s'utilitzen models R1 com el QWQ per evitar errors 400", + "enableR1Format": "Activar format de model de raonament", + "enableR1FormatTips": "Activeu per a models de raonament/pensament (DeepSeek R1, Kimi-K2, QWQ, etc.) per gestionar correctament el format de resposta. Requerit per a models a NVIDIA NIM i altres proveïdors compatibles amb OpenAI.", "useAzure": "Utilitzar Azure", "azureApiVersion": "Establir versió de l'API d'Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/de/settings.json b/webview-ui/src/i18n/locales/de/settings.json index bc275a64e50..3217f05c5ed 100644 --- a/webview-ui/src/i18n/locales/de/settings.json +++ b/webview-ui/src/i18n/locales/de/settings.json @@ -878,8 +878,8 @@ "cacheReadsPrice": "Cache-Lesepreis", "cacheWritesPrice": "Cache-Schreibpreis", "enableStreaming": "Streaming aktivieren", - "enableR1Format": "R1-Modellparameter aktivieren", - "enableR1FormatTips": "Muss bei Verwendung von R1-Modellen wie QWQ aktiviert werden, um 400er-Fehler zu vermeiden", + "enableR1Format": "Reasoning-Modell-Format aktivieren", + "enableR1FormatTips": "Aktivieren für Reasoning-/Denkmodelle (DeepSeek R1, Kimi-K2, QWQ, usw.), um das Antwortformat korrekt zu verarbeiten. Erforderlich für Modelle auf NVIDIA NIM und anderen OpenAI-kompatiblen Anbietern.", "useAzure": "Azure verwenden", "azureApiVersion": "Azure API-Version festlegen", "gemini": { diff --git a/webview-ui/src/i18n/locales/en/settings.json b/webview-ui/src/i18n/locales/en/settings.json index 7045ef07d19..d8c43ef5b3a 100644 --- a/webview-ui/src/i18n/locales/en/settings.json +++ b/webview-ui/src/i18n/locales/en/settings.json @@ -887,8 +887,8 @@ "cacheReadsPrice": "Cache reads price", "cacheWritesPrice": "Cache writes price", "enableStreaming": "Enable streaming", - "enableR1Format": "Enable R1 model parameters", - "enableR1FormatTips": "Must be enabled when using R1 models such as QWQ to prevent 400 errors", + "enableR1Format": "Enable reasoning model format", + "enableR1FormatTips": "Enable for reasoning/thinking models (DeepSeek R1, Kimi-K2, QWQ, etc.) to properly handle their response format. Required for models on NVIDIA NIM and other OpenAI-compatible providers.", "useAzure": "Use Azure", "azureApiVersion": "Set Azure API version", "gemini": { diff --git a/webview-ui/src/i18n/locales/es/settings.json b/webview-ui/src/i18n/locales/es/settings.json index 36243b99be0..d0a217298b0 100644 --- a/webview-ui/src/i18n/locales/es/settings.json +++ b/webview-ui/src/i18n/locales/es/settings.json @@ -878,8 +878,8 @@ "cacheReadsPrice": "Precio de lecturas de caché", "cacheWritesPrice": "Precio de escrituras de caché", "enableStreaming": "Habilitar streaming", - "enableR1Format": "Habilitar parámetros del modelo R1", - "enableR1FormatTips": "Debe habilitarse al utilizar modelos R1 como QWQ, para evitar el error 400", + "enableR1Format": "Habilitar formato de modelo de razonamiento", + "enableR1FormatTips": "Habilitar para modelos de razonamiento/pensamiento (DeepSeek R1, Kimi-K2, QWQ, etc.) para manejar correctamente el formato de respuesta. Requerido para modelos en NVIDIA NIM y otros proveedores compatibles con OpenAI.", "useAzure": "Usar Azure", "azureApiVersion": "Establecer versión de API de Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/fr/settings.json b/webview-ui/src/i18n/locales/fr/settings.json index 1c28b763077..2a152d023cc 100644 --- a/webview-ui/src/i18n/locales/fr/settings.json +++ b/webview-ui/src/i18n/locales/fr/settings.json @@ -878,8 +878,8 @@ "cacheReadsPrice": "Prix des lectures de cache", "cacheWritesPrice": "Prix des écritures de cache", "enableStreaming": "Activer le streaming", - "enableR1Format": "Activer les paramètres du modèle R1", - "enableR1FormatTips": "Doit être activé lors de l'utilisation de modèles R1 tels que QWQ, pour éviter l'erreur 400", + "enableR1Format": "Activer le format de modèle de raisonnement", + "enableR1FormatTips": "Activer pour les modèles de raisonnement/thinking (DeepSeek R1, Kimi-K2, QWQ, etc.) pour gérer correctement le format des réponses. Requis pour les modèles sur NVIDIA NIM et autres fournisseurs compatibles OpenAI.", "useAzure": "Utiliser Azure", "azureApiVersion": "Définir la version de l'API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/hi/settings.json b/webview-ui/src/i18n/locales/hi/settings.json index 4974ff706b4..09bc02d0397 100644 --- a/webview-ui/src/i18n/locales/hi/settings.json +++ b/webview-ui/src/i18n/locales/hi/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "कैश रीड्स मूल्य", "cacheWritesPrice": "कैश राइट्स मूल्य", "enableStreaming": "स्ट्रीमिंग सक्षम करें", - "enableR1Format": "R1 मॉडल पैरामीटर सक्षम करें", - "enableR1FormatTips": "QWQ जैसी R1 मॉडलों का उपयोग करते समय इसे सक्षम करना आवश्यक है, ताकि 400 त्रुटि से बचा जा सके", + "enableR1Format": "रीजनिंग मॉडल फॉर्मेट सक्षम करें", + "enableR1FormatTips": "रीजनिंग/थिंकिंग मॉडल (DeepSeek R1, Kimi-K2, QWQ, आदि) के लिए सक्षम करें ताकि उनके रिस्पॉन्स फॉर्मेट को सही ढंग से हैंडल किया जा सके। NVIDIA NIM और अन्य OpenAI-संगत प्रोवाइडर्स पर मॉडल के लिए आवश्यक।", "useAzure": "Azure का उपयोग करें", "azureApiVersion": "Azure API संस्करण सेट करें", "gemini": { diff --git a/webview-ui/src/i18n/locales/id/settings.json b/webview-ui/src/i18n/locales/id/settings.json index 908c975a5b8..d3cb9fca047 100644 --- a/webview-ui/src/i18n/locales/id/settings.json +++ b/webview-ui/src/i18n/locales/id/settings.json @@ -908,8 +908,8 @@ "cacheReadsPrice": "Harga cache reads", "cacheWritesPrice": "Harga cache writes", "enableStreaming": "Aktifkan streaming", - "enableR1Format": "Aktifkan parameter model R1", - "enableR1FormatTips": "Harus diaktifkan saat menggunakan model R1 seperti QWQ untuk mencegah error 400", + "enableR1Format": "Aktifkan format model reasoning", + "enableR1FormatTips": "Aktifkan untuk model reasoning/thinking (DeepSeek R1, Kimi-K2, QWQ, dll.) untuk menangani format respons dengan benar. Diperlukan untuk model di NVIDIA NIM dan penyedia lain yang kompatibel dengan OpenAI.", "useAzure": "Gunakan Azure", "azureApiVersion": "Atur versi API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/it/settings.json b/webview-ui/src/i18n/locales/it/settings.json index 1c3c7e494d7..a9c86a133ff 100644 --- a/webview-ui/src/i18n/locales/it/settings.json +++ b/webview-ui/src/i18n/locales/it/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Prezzo letture cache", "cacheWritesPrice": "Prezzo scritture cache", "enableStreaming": "Abilita streaming", - "enableR1Format": "Abilita i parametri del modello R1", - "enableR1FormatTips": "Deve essere abilitato quando si utilizzano modelli R1 come QWQ, per evitare l'errore 400", + "enableR1Format": "Abilita formato modello di ragionamento", + "enableR1FormatTips": "Abilita per modelli di ragionamento/thinking (DeepSeek R1, Kimi-K2, QWQ, ecc.) per gestire correttamente il formato delle risposte. Richiesto per modelli su NVIDIA NIM e altri provider compatibili con OpenAI.", "useAzure": "Usa Azure", "azureApiVersion": "Imposta versione API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/ja/settings.json b/webview-ui/src/i18n/locales/ja/settings.json index b4af9d4033e..c3c1b46a5bc 100644 --- a/webview-ui/src/i18n/locales/ja/settings.json +++ b/webview-ui/src/i18n/locales/ja/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "キャッシュ読み取り価格", "cacheWritesPrice": "キャッシュ書き込み価格", "enableStreaming": "ストリーミングを有効化", - "enableR1Format": "R1モデルパラメータを有効にする", - "enableR1FormatTips": "QWQなどのR1モデルを使用する際には、有効にする必要があります。400エラーを防ぐために", + "enableR1Format": "推論モデルフォーマットを有効にする", + "enableR1FormatTips": "推論/思考モデル(DeepSeek R1、Kimi-K2、QWQ など)のレスポンスフォーマットを正しく処理するために有効にしてください。NVIDIA NIM およびその他の OpenAI 互換プロバイダーのモデルに必要です。", "useAzure": "Azureを使用", "azureApiVersion": "Azure APIバージョンを設定", "gemini": { diff --git a/webview-ui/src/i18n/locales/ko/settings.json b/webview-ui/src/i18n/locales/ko/settings.json index 2888d75bb0b..c32f87b08b4 100644 --- a/webview-ui/src/i18n/locales/ko/settings.json +++ b/webview-ui/src/i18n/locales/ko/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "캐시 읽기 가격", "cacheWritesPrice": "캐시 쓰기 가격", "enableStreaming": "스트리밍 활성화", - "enableR1Format": "R1 모델 매개변수 활성화", - "enableR1FormatTips": "QWQ와 같은 R1 모델을 사용할 때 활성화해야 하며, 400 오류를 방지합니다", + "enableR1Format": "추론 모델 형식 활성화", + "enableR1FormatTips": "추론/사고 모델(DeepSeek R1, Kimi-K2, QWQ 등)의 응답 형식을 올바르게 처리하려면 활성화하세요. NVIDIA NIM 및 기타 OpenAI 호환 제공업체의 모델에 필요합니다.", "useAzure": "Azure 사용", "azureApiVersion": "Azure API 버전 설정", "gemini": { diff --git a/webview-ui/src/i18n/locales/nl/settings.json b/webview-ui/src/i18n/locales/nl/settings.json index 83e1f4b7ab3..480ac86c84f 100644 --- a/webview-ui/src/i18n/locales/nl/settings.json +++ b/webview-ui/src/i18n/locales/nl/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Cache-leesprijs", "cacheWritesPrice": "Cache-schrijfprijs", "enableStreaming": "Streaming inschakelen", - "enableR1Format": "R1-modelparameters inschakelen", - "enableR1FormatTips": "Moet ingeschakeld zijn bij gebruik van R1-modellen zoals QWQ om 400-fouten te voorkomen", + "enableR1Format": "Redeneermodel-formaat inschakelen", + "enableR1FormatTips": "Inschakelen voor redeneer-/denkmodellen (DeepSeek R1, Kimi-K2, QWQ, enz.) om het responsformaat correct te verwerken. Vereist voor modellen op NVIDIA NIM en andere OpenAI-compatibele providers.", "useAzure": "Azure gebruiken", "azureApiVersion": "Azure API-versie instellen", "gemini": { diff --git a/webview-ui/src/i18n/locales/pl/settings.json b/webview-ui/src/i18n/locales/pl/settings.json index 7c339f96a5b..11be7b67d79 100644 --- a/webview-ui/src/i18n/locales/pl/settings.json +++ b/webview-ui/src/i18n/locales/pl/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Cena odczytów bufora", "cacheWritesPrice": "Cena zapisów bufora", "enableStreaming": "Włącz strumieniowanie", - "enableR1Format": "Włącz parametry modelu R1", - "enableR1FormatTips": "Należy włączyć podczas korzystania z modeli R1, takich jak QWQ, aby uniknąć błędu 400", + "enableR1Format": "Włącz format modelu rozumowania", + "enableR1FormatTips": "Włącz dla modeli rozumowania/thinking (DeepSeek R1, Kimi-K2, QWQ, itp.) aby prawidłowo obsługiwać format odpowiedzi. Wymagane dla modeli na NVIDIA NIM i innych dostawcach zgodnych z OpenAI.", "useAzure": "Użyj Azure", "azureApiVersion": "Ustaw wersję API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/pt-BR/settings.json b/webview-ui/src/i18n/locales/pt-BR/settings.json index 04a786ab11e..917df02b4e6 100644 --- a/webview-ui/src/i18n/locales/pt-BR/settings.json +++ b/webview-ui/src/i18n/locales/pt-BR/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Preço de leituras de cache", "cacheWritesPrice": "Preço de escritas de cache", "enableStreaming": "Ativar streaming", - "enableR1Format": "Ativar parâmetros do modelo R1", - "enableR1FormatTips": "Deve ser ativado ao usar modelos R1 como QWQ, para evitar erro 400", + "enableR1Format": "Ativar formato de modelo de raciocínio", + "enableR1FormatTips": "Ative para modelos de raciocínio/pensamento (DeepSeek R1, Kimi-K2, QWQ, etc.) para tratar corretamente o formato de resposta. Necessário para modelos no NVIDIA NIM e outros provedores compatíveis com OpenAI.", "useAzure": "Usar Azure", "azureApiVersion": "Definir versão da API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/ru/settings.json b/webview-ui/src/i18n/locales/ru/settings.json index ebdbc01b931..33442934dae 100644 --- a/webview-ui/src/i18n/locales/ru/settings.json +++ b/webview-ui/src/i18n/locales/ru/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Цена чтения из кэша", "cacheWritesPrice": "Цена записи в кэш", "enableStreaming": "Включить потоковую передачу", - "enableR1Format": "Включить параметры модели R1", - "enableR1FormatTips": "Необходимо включить при использовании моделей R1 (например, QWQ), чтобы избежать ошибок 400", + "enableR1Format": "Включить формат модели рассуждения", + "enableR1FormatTips": "Включите для моделей рассуждения/мышления (DeepSeek R1, Kimi-K2, QWQ и др.) для правильной обработки формата ответа. Требуется для моделей на NVIDIA NIM и других провайдерах, совместимых с OpenAI.", "useAzure": "Использовать Azure", "azureApiVersion": "Установить версию API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/tr/settings.json b/webview-ui/src/i18n/locales/tr/settings.json index 5a7daeec1d7..07f70be30f3 100644 --- a/webview-ui/src/i18n/locales/tr/settings.json +++ b/webview-ui/src/i18n/locales/tr/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Önbellek okuma fiyatı", "cacheWritesPrice": "Önbellek yazma fiyatı", "enableStreaming": "Akışı etkinleştir", - "enableR1Format": "R1 model parametrelerini etkinleştir", - "enableR1FormatTips": "QWQ gibi R1 modelleri kullanıldığında etkinleştirilmelidir, 400 hatası alınmaması için", + "enableR1Format": "Akıl yürütme modeli formatını etkinleştir", + "enableR1FormatTips": "Yanıt formatını doğru şekilde işlemek için akıl yürütme/düşünme modelleri (DeepSeek R1, Kimi-K2, QWQ, vb.) için etkinleştirin. NVIDIA NIM ve diğer OpenAI uyumlu sağlayıcılardaki modeller için gereklidir.", "useAzure": "Azure kullan", "azureApiVersion": "Azure API sürümünü ayarla", "gemini": { diff --git a/webview-ui/src/i18n/locales/vi/settings.json b/webview-ui/src/i18n/locales/vi/settings.json index 3e8e22d8f0c..b5687d8796c 100644 --- a/webview-ui/src/i18n/locales/vi/settings.json +++ b/webview-ui/src/i18n/locales/vi/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "Giá đọc bộ nhớ đệm", "cacheWritesPrice": "Giá ghi bộ nhớ đệm", "enableStreaming": "Bật streaming", - "enableR1Format": "Kích hoạt tham số mô hình R1", - "enableR1FormatTips": "Cần kích hoạt khi sử dụng các mô hình R1 như QWQ, để tránh lỗi 400", + "enableR1Format": "Kích hoạt định dạng mô hình suy luận", + "enableR1FormatTips": "Kích hoạt cho các mô hình suy luận/thinking (DeepSeek R1, Kimi-K2, QWQ, v.v.) để xử lý đúng định dạng phản hồi. Cần thiết cho các mô hình trên NVIDIA NIM và các provider tương thích OpenAI khác.", "useAzure": "Sử dụng Azure", "azureApiVersion": "Đặt phiên bản API Azure", "gemini": { diff --git a/webview-ui/src/i18n/locales/zh-CN/settings.json b/webview-ui/src/i18n/locales/zh-CN/settings.json index 85bc9bd431b..8afb33b1042 100644 --- a/webview-ui/src/i18n/locales/zh-CN/settings.json +++ b/webview-ui/src/i18n/locales/zh-CN/settings.json @@ -879,8 +879,8 @@ "cacheReadsPrice": "缓存读取价格", "cacheWritesPrice": "缓存写入价格", "enableStreaming": "启用流式传输", - "enableR1Format": "启用 R1 模型参数", - "enableR1FormatTips": "使用 QWQ 等 R1 系列模型时必须启用,避免出现 400 错误", + "enableR1Format": "启用推理模型格式", + "enableR1FormatTips": "为推理/思考模型(DeepSeek R1、Kimi-K2、QWQ 等)启用,以正确处理响应格式。在 NVIDIA NIM 和其他 OpenAI 兼容提供商上使用模型时需要启用。", "useAzure": "使用 Azure 服务", "azureApiVersion": "设置 Azure API 版本", "gemini": { diff --git a/webview-ui/src/i18n/locales/zh-TW/settings.json b/webview-ui/src/i18n/locales/zh-TW/settings.json index 47f614932b9..bcb02482821 100644 --- a/webview-ui/src/i18n/locales/zh-TW/settings.json +++ b/webview-ui/src/i18n/locales/zh-TW/settings.json @@ -887,8 +887,8 @@ "cacheReadsPrice": "快取讀取價格", "cacheWritesPrice": "快取寫入價格", "enableStreaming": "啟用串流輸出", - "enableR1Format": "啟用 R1 模型參數", - "enableR1FormatTips": "使用 QWQ 等 R1 模型時必須啟用,以避免發生 400 錯誤", + "enableR1Format": "啟用推理模型格式", + "enableR1FormatTips": "為推理/思考模型(DeepSeek R1、Kimi-K2、QWQ 等)啟用,以正確處理回應格式。在 NVIDIA NIM 和其他 OpenAI 相容提供者上使用模型時需要啟用。", "useAzure": "使用 Azure", "azureApiVersion": "設定 Azure API 版本", "gemini": {