refactor: Update token usage api (#347)

* refactor: Improve token usage api
* refactor: Image recognition to tokens
This commit is contained in:
Petr Mironychev
2026-05-14 21:19:12 +02:00
committed by GitHub
parent 86f4635080
commit 3b421f60af
20 changed files with 518 additions and 60 deletions

View File

@@ -29,14 +29,6 @@ ChatAssistantSettings::ChatAssistantSettings()
setDisplayName(Tr::tr("Chat Assistant"));
// Chat Settings
chatTokensThreshold.setSettingsKey(Constants::CA_TOKENS_THRESHOLD);
chatTokensThreshold.setLabelText(Tr::tr("Chat history token limit:"));
chatTokensThreshold.setToolTip(Tr::tr("Maximum number of tokens in chat history. When "
"exceeded, oldest messages will be removed."));
chatTokensThreshold.setRange(1, 99999999);
chatTokensThreshold.setDefaultValue(20000);
linkOpenFiles.setSettingsKey(Constants::CA_LINK_OPEN_FILES);
linkOpenFiles.setLabelText(Tr::tr("Sync open files with assistant by default"));
linkOpenFiles.setDefaultValue(false);
@@ -58,6 +50,18 @@ ChatAssistantSettings::ChatAssistantSettings()
enableChatTools.setToolTip(Tr::tr("When enabled, AI can use tools to read files, search project, and build code"));
enableChatTools.setDefaultValue(false);
autoCompress.setSettingsKey(Constants::CA_AUTO_COMPRESS);
autoCompress.setLabelText(Tr::tr("Auto-compress chat when session tokens exceed:"));
autoCompress.setToolTip(Tr::tr(
"After each assistant response, if the running session token total exceeds the "
"threshold, the chat is summarized and a new compressed chat is started "
"automatically. The original chat is preserved on disk."));
autoCompress.setDefaultValue(false);
autoCompressThreshold.setSettingsKey(Constants::CA_AUTO_COMPRESS_THRESHOLD);
autoCompressThreshold.setRange(1000, 99999999);
autoCompressThreshold.setDefaultValue(40000);
// General Parameters Settings
temperature.setSettingsKey(Constants::CA_TEMPERATURE);
temperature.setLabelText(Tr::tr("Temperature:"));
@@ -292,11 +296,11 @@ ChatAssistantSettings::ChatAssistantSettings()
Group{
title(Tr::tr("Chat Settings")),
Column{
Row{chatTokensThreshold, Stretch{1}},
linkOpenFiles,
autosave,
enableChatInBottomToolBar,
enableChatInNavigationPanel}},
enableChatInNavigationPanel,
Row{autoCompress, autoCompressThreshold, Stretch{1}}}},
Space{8},
Group{
title(Tr::tr("Tools")),
@@ -348,7 +352,8 @@ void ChatAssistantSettings::resetSettingsToDefaults()
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
resetAspect(chatTokensThreshold);
resetAspect(autoCompress);
resetAspect(autoCompressThreshold);
resetAspect(temperature);
resetAspect(maxTokens);
resetAspect(useTopP);

View File

@@ -18,12 +18,13 @@ public:
ButtonAspect resetToDefaults{this};
// Chat settings
Utils::IntegerAspect chatTokensThreshold{this};
Utils::BoolAspect linkOpenFiles{this};
Utils::BoolAspect autosave{this};
Utils::BoolAspect enableChatInBottomToolBar{this};
Utils::BoolAspect enableChatInNavigationPanel{this};
Utils::BoolAspect enableChatTools{this};
Utils::BoolAspect autoCompress{this};
Utils::IntegerAspect autoCompressThreshold{this};
// General Parameters Settings
Utils::DoubleAspect temperature{this};

View File

@@ -78,7 +78,8 @@ const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion";
const char CC_MODEL_OUTPUT_HANDLER[] = "QodeAssist.ccModelOutputHandler";
const char CA_AUTO_APPLY_FILE_EDITS[] = "QodeAssist.caAutoApplyFileEdits";
const char CA_TOKENS_THRESHOLD[] = "QodeAssist.caTokensThreshold";
const char CA_AUTO_COMPRESS[] = "QodeAssist.caAutoCompress";
const char CA_AUTO_COMPRESS_THRESHOLD[] = "QodeAssist.caAutoCompressThreshold";
const char CA_LINK_OPEN_FILES[] = "QodeAssist.caLinkOpenFiles";
const char CA_AUTOSAVE[] = "QodeAssist.caAutosave";
const char CC_CUSTOM_LANGUAGES[] = "QodeAssist.ccCustomLanguages";