From 46d47dd53077ea6ae007ed647dd835207143f77c Mon Sep 17 00:00:00 2001 From: gevorg Date: Thu, 15 Oct 2026 16:13:51 +0400 Subject: [PATCH] Update OpenAI models to the GPT-6 lineup - Offer current models in Settings (gpt-6-luna, gpt-6-astra, gpt-6.1-sol, gpt-6-sol, gpt-5.6-sol/terra/luna) and drop deprecated or shut-down ones (gpt-4o, gpt-4.1*, gpt-5/-mini/-nano, gpt-5-chat-latest). - Default to gpt-6-luna, OpenAI's recommended replacement for gpt-4o. - Treat every GPT model from GPT-5 onward as a reasoning model so GPT-6 requests send max_completion_tokens and no temperature instead of failing with HTTP 400. - Switch saved retired models to gpt-6-luna once, tracked by a new SettingsVersion registry value so a later explicit choice is kept. - Move the model checks into ModelParams and cover them with unit tests. Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 1 + LLMAssistant.vcxproj | 2 ++ src/LLMService.cpp | 46 ++++++++++++++++++++++++------------------ src/ModelParams.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ src/ModelParams.h | 16 +++++++++++++++ src/SettingsDialog.cpp | 21 +++++++++---------- tests/CoreTests.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 31 deletions(-) create mode 100644 src/ModelParams.cpp create mode 100644 src/ModelParams.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 177230a..4dae92e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ FetchContent_Declare( FetchContent_MakeAvailable(Catch2) add_executable(LLMAssistantTests + src/ModelParams.cpp src/RequestTarget.cpp src/SimpleJson.cpp src/TextCodec.cpp diff --git a/LLMAssistant.vcxproj b/LLMAssistant.vcxproj index 45b7a7a..1cdf169 100644 --- a/LLMAssistant.vcxproj +++ b/LLMAssistant.vcxproj @@ -99,6 +99,7 @@ + @@ -109,6 +110,7 @@ + diff --git a/src/LLMService.cpp b/src/LLMService.cpp index 5772016..8d0e019 100644 --- a/src/LLMService.cpp +++ b/src/LLMService.cpp @@ -1,9 +1,8 @@ #include "LLMService.h" +#include "ModelParams.h" #include "SimpleJson.h" #include "TextCodec.h" -#include -#include #include #include @@ -12,34 +11,24 @@ namespace { constexpr DWORD kRequestTimeoutMilliseconds = 60000; +// Version of the saved settings. Bump it, and update isRetiredModel, to switch +// saved retired models to the default again. +// 1: retired models (gpt-4o, gpt-4.1, gpt-5, ...) switched to gpt-6-luna. +constexpr DWORD kSettingsVersion = 1; + std::wstring lastErrorMessage(const wchar_t* operation) { const DWORD error = GetLastError(); return std::wstring(operation) + L" failed (Win32 error " + std::to_wstring(error) + L")."; } - -// Reasoning models (GPT-5 family and the o-series) reject the classic -// "max_tokens" and any non-default "temperature". They require -// "max_completion_tokens" and no temperature override. The chat-tuned -// variant "gpt-5-chat*" behaves like gpt-4o and keeps the classic params. -bool isReasoningModel(const std::wstring& model) -{ - std::wstring name = model; - std::transform(name.begin(), name.end(), name.begin(), towlower); - const auto startsWith = [&](const wchar_t* prefix) { return name.rfind(prefix, 0) == 0; }; - - if (startsWith(L"gpt-5")) { - return !startsWith(L"gpt-5-chat"); - } - return startsWith(L"o1") || startsWith(L"o3") || startsWith(L"o4"); -} } LLMService* LLMService::instance = nullptr; const wchar_t* LLMService::defaultModel() { - return L"gpt-4o"; + // OpenAI's fast, low-cost model and its recommended replacement for gpt-4o. + return L"gpt-6-luna"; } LLMService::LLMService() @@ -127,7 +116,7 @@ LLMResult LLMService::callLLMWithApiKey( builder.addString("model", modelUtf8); if (isReasoningModel(model)) { // Reasoning tokens are billed against this budget too, so keep it - // generous to avoid empty responses from the GPT-5 family. + // generous to avoid empty responses from reasoning models. builder.addNumber("max_completion_tokens", 4000); } else { builder.addNumber("max_tokens", 1000); @@ -304,7 +293,22 @@ void LLMService::loadSettings() modelBuffer[modelSize / sizeof(wchar_t)] = L'\0'; setModel(modelBuffer); } + + DWORD settingsVersion = 0; + DWORD versionSize = sizeof(settingsVersion); + DWORD versionType = REG_DWORD; + if (RegQueryValueEx(key, L"SettingsVersion", nullptr, &versionType, + reinterpret_cast(&settingsVersion), &versionSize) != ERROR_SUCCESS + || versionType != REG_DWORD) { + settingsVersion = 0; + } RegCloseKey(key); + + // Switch a retired model to the default once. saveSettings records the + // version, so a retired model the user picks again afterwards is kept. + if (settingsVersion < kSettingsVersion && isRetiredModel(getModel())) { + setModel(defaultModel()); + } } void LLMService::saveSettings() @@ -322,5 +326,7 @@ void LLMService::saveSettings() const std::wstring currentModel = getModel(); const DWORD modelSize = static_cast((currentModel.length() + 1) * sizeof(wchar_t)); RegSetValueEx(key, L"Model", 0, REG_SZ, reinterpret_cast(currentModel.c_str()), modelSize); + RegSetValueEx(key, L"SettingsVersion", 0, REG_DWORD, reinterpret_cast(&kSettingsVersion), + sizeof(kSettingsVersion)); RegCloseKey(key); } diff --git a/src/ModelParams.cpp b/src/ModelParams.cpp new file mode 100644 index 0000000..b804214 --- /dev/null +++ b/src/ModelParams.cpp @@ -0,0 +1,44 @@ +#include "ModelParams.h" + +#include +#include + +namespace { +std::wstring toLower(const std::wstring& text) +{ + std::wstring lower = text; + std::transform(lower.begin(), lower.end(), lower.begin(), towlower); + return lower; +} + +bool startsWith(const std::wstring& text, const wchar_t* prefix) +{ + return text.rfind(prefix, 0) == 0; +} +} + +bool isReasoningModel(const std::wstring& model) +{ + const std::wstring name = toLower(model); + + // Only the legacy GPT-3.5/GPT-4 families (gpt-4o, gpt-4.1, ...) and the + // chat-tuned "*-chat-latest" variants keep the classic params. Any other + // GPT model is treated as reasoning so new releases (gpt-6-luna, ...) + // work without a plugin update. + if (startsWith(name, L"gpt-3") || startsWith(name, L"gpt-4") || name.find(L"-chat") != std::wstring::npos) { + return false; + } + return startsWith(name, L"gpt-") || startsWith(name, L"o1") || startsWith(name, L"o3") + || startsWith(name, L"o4"); +} + +bool isRetiredModel(const std::wstring& model) +{ + const std::wstring name = toLower(model); + + // See https://developers.openai.com/api/docs/deprecations. + return startsWith(name, L"gpt-3") || startsWith(name, L"gpt-4") + || name == L"gpt-5" || startsWith(name, L"gpt-5-") + || name == L"gpt-5.1" || startsWith(name, L"gpt-5.1-") + || name.find(L"-chat-latest") != std::wstring::npos; +} diff --git a/src/ModelParams.h b/src/ModelParams.h new file mode 100644 index 0000000..f4b5856 --- /dev/null +++ b/src/ModelParams.h @@ -0,0 +1,16 @@ +#ifndef MODELPARAMS_H +#define MODELPARAMS_H + +#include + +// Reasoning models (every GPT model from GPT-5 onward and the o-series) reject +// the classic "max_tokens" and any non-default "temperature". They require +// "max_completion_tokens" and no temperature override. +bool isReasoningModel(const std::wstring& model); + +// Models OpenAI has deprecated or already shut down: the GPT-3.5/GPT-4 +// families, the original GPT-5 generation, GPT-5.1 and the "*-chat-latest" +// variants. Saved settings using one are switched to the default model. +bool isRetiredModel(const std::wstring& model); + +#endif diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 305bf9f..222f016 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -147,19 +147,18 @@ void SettingsDialog::onInitDialog() std::wstring currentKey = LLMService::getInstance().getApiKey(); SetDlgItemText(hDlg, IDC_API_KEY, currentKey.c_str()); - // Populate the model selector with newer OpenAI models (gpt-4o and above). - // The combo is editable, so a brand-new model name can also be typed in - // without needing a plugin rebuild. + // Populate the model selector with OpenAI's current (non-deprecated) + // models. The combo is editable, so a brand-new or older model name can + // also be typed in without needing a plugin rebuild. HWND combo = GetDlgItem(hDlg, IDC_MODEL_COMBO); static const wchar_t* const kModels[] = { - L"gpt-5", - L"gpt-5-mini", - L"gpt-5-nano", - L"gpt-5-chat-latest", - L"gpt-4.1", - L"gpt-4.1-mini", - L"gpt-4.1-nano", - L"gpt-4o" + L"gpt-6-luna", + L"gpt-6-astra", + L"gpt-6.1-sol", + L"gpt-6-sol", + L"gpt-5.6-sol", + L"gpt-5.6-terra", + L"gpt-5.6-luna" }; for (const wchar_t* model : kModels) { SendMessage(combo, CB_ADDSTRING, 0, reinterpret_cast(model)); diff --git a/tests/CoreTests.cpp b/tests/CoreTests.cpp index b50cd21..22681e5 100644 --- a/tests/CoreTests.cpp +++ b/tests/CoreTests.cpp @@ -1,3 +1,4 @@ +#include "ModelParams.h" #include "RequestTarget.h" #include "SimpleJson.h" #include "TextCodec.h" @@ -42,6 +43,48 @@ TEST_CASE("OpenAI errors are recognized separately from content") REQUIRE(parser.extractContent().empty()); } +TEST_CASE("GPT-5 and newer models use reasoning parameters") +{ + REQUIRE(isReasoningModel(L"gpt-6-luna")); + REQUIRE(isReasoningModel(L"gpt-6-astra")); + REQUIRE(isReasoningModel(L"gpt-6.1-sol")); + REQUIRE(isReasoningModel(L"gpt-5.6-terra")); + REQUIRE(isReasoningModel(L"GPT-5-mini")); + REQUIRE(isReasoningModel(L"o4-mini")); +} + +TEST_CASE("Legacy and chat-tuned models keep classic parameters") +{ + REQUIRE_FALSE(isReasoningModel(L"gpt-4o")); + REQUIRE_FALSE(isReasoningModel(L"gpt-4.1-mini")); + REQUIRE_FALSE(isReasoningModel(L"gpt-3.5-turbo")); + REQUIRE_FALSE(isReasoningModel(L"gpt-5-chat-latest")); + REQUIRE_FALSE(isReasoningModel(L"chatgpt-4o-latest")); +} + +TEST_CASE("Deprecated and shut-down models are retired") +{ + REQUIRE(isRetiredModel(L"gpt-4o")); + REQUIRE(isRetiredModel(L"GPT-4o-mini")); + REQUIRE(isRetiredModel(L"gpt-4.1-nano")); + REQUIRE(isRetiredModel(L"gpt-3.5-turbo")); + REQUIRE(isRetiredModel(L"gpt-5")); + REQUIRE(isRetiredModel(L"gpt-5-mini")); + REQUIRE(isRetiredModel(L"gpt-5-chat-latest")); + REQUIRE(isRetiredModel(L"gpt-5.1")); + REQUIRE(isRetiredModel(L"gpt-5.2-chat-latest")); +} + +TEST_CASE("Current models are not retired") +{ + REQUIRE_FALSE(isRetiredModel(L"gpt-6-luna")); + REQUIRE_FALSE(isRetiredModel(L"gpt-6.1-sol")); + REQUIRE_FALSE(isRetiredModel(L"gpt-5.6-terra")); + REQUIRE_FALSE(isRetiredModel(L"gpt-5.5")); + REQUIRE_FALSE(isRetiredModel(L"gpt-5.2")); + REQUIRE_FALSE(isRetiredModel(L"o4-mini")); +} + TEST_CASE("Selection fallback captures the complete document range") { const TextRange range = resolveTextRange(12, 12, 100);