From 13b20c4785bcf2ac30b5267ee135cbd6330b79e2 Mon Sep 17 00:00:00 2001 From: Cosmic Snow Date: Tue, 30 Jul 2024 17:50:52 +0200 Subject: [PATCH 1/5] Don't allow zero as temperature in ModelSettings.qml A number lower than 0.000001 is set to that value instead. Signed-off-by: Cosmic Snow --- gpt4all-chat/qml/ModelSettings.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gpt4all-chat/qml/ModelSettings.qml b/gpt4all-chat/qml/ModelSettings.qml index 5e896eb17495..a8255f82e41a 100644 --- a/gpt4all-chat/qml/ModelSettings.qml +++ b/gpt4all-chat/qml/ModelSettings.qml @@ -419,6 +419,7 @@ MySettingsTab { MyTextField { id: temperatureField text: root.currentModelInfo.temperature + inputMethodHints: Qt.ImhPreferNumbers font.pixelSize: theme.fontSizeLarge color: theme.textColor ToolTip.text: qsTr("Temperature increases the chances of choosing less likely tokens.\nNOTE: Higher temperature gives more creative but less predictable outputs.") @@ -443,6 +444,9 @@ MySettingsTab { onEditingFinished: { var val = parseFloat(text) if (!isNaN(val)) { + if (val < 0.000001) { + val = 0.000001; + } MySettings.setModelTemperature(root.currentModelInfo, val) focus = false } else { From c7409cfed52ea6cf3424a4d697f56137ccc6d7b7 Mon Sep 17 00:00:00 2001 From: Cosmic Snow Date: Tue, 30 Jul 2024 20:00:34 +0200 Subject: [PATCH 2/5] Format with .toLocaleString() and always display corrected value - Using .toLocaleString() gets rid of the scientific notation display - Setting TextField's text when correcting the value fixes flakiness Signed-off-by: Cosmic Snow --- gpt4all-chat/qml/ModelSettings.qml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpt4all-chat/qml/ModelSettings.qml b/gpt4all-chat/qml/ModelSettings.qml index a8255f82e41a..eead8bf862c9 100644 --- a/gpt4all-chat/qml/ModelSettings.qml +++ b/gpt4all-chat/qml/ModelSettings.qml @@ -432,13 +432,15 @@ MySettingsTab { Connections { target: MySettings function onTemperatureChanged() { - temperatureField.text = root.currentModelInfo.temperature; + temperatureField.text = root.currentModelInfo.temperature.toLocaleString( + Qt.locale().name, { maximumSignificantDigits: 6 }); } } Connections { target: root function onCurrentModelInfoChanged() { - temperatureField.text = root.currentModelInfo.temperature; + temperatureField.text = root.currentModelInfo.temperature.toLocaleString( + Qt.locale().name, { maximumSignificantDigits: 6 }); } } onEditingFinished: { @@ -446,6 +448,8 @@ MySettingsTab { if (!isNaN(val)) { if (val < 0.000001) { val = 0.000001; + temperatureField.text = val.toLocaleString( + Qt.locale().name, { maximumSignificantDigits: 6 }); } MySettings.setModelTemperature(root.currentModelInfo, val) focus = false From bc7d46ea61494c866c82404db49ff308d2b79b02 Mon Sep 17 00:00:00 2001 From: Cosmic Snow Date: Thu, 1 Aug 2024 08:09:08 +0200 Subject: [PATCH 3/5] Make number parsing work with format of current locale Signed-off-by: Cosmic Snow --- gpt4all-chat/qml/ModelSettings.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gpt4all-chat/qml/ModelSettings.qml b/gpt4all-chat/qml/ModelSettings.qml index eead8bf862c9..a976e75d8da4 100644 --- a/gpt4all-chat/qml/ModelSettings.qml +++ b/gpt4all-chat/qml/ModelSettings.qml @@ -443,8 +443,15 @@ MySettingsTab { Qt.locale().name, { maximumSignificantDigits: 6 }); } } + function parseLocaleNumber(text) { + try { + return Number.fromLocaleString(Qt.locale(), text); + } catch (e) { + return Number.NaN; + } + } onEditingFinished: { - var val = parseFloat(text) + var val = parseLocaleNumber(text); if (!isNaN(val)) { if (val < 0.000001) { val = 0.000001; From a00654778e6699cbd3b3195457df441f6edd0dc0 Mon Sep 17 00:00:00 2001 From: Cosmic Snow Date: Thu, 1 Aug 2024 14:27:58 +0200 Subject: [PATCH 4/5] Fix the locale handling & work around the Qt bug - make validator locale-aware - do locale processing everywhere a conversion between double and string happens - Qt's `Number.toLocaleString()` with a string as locale is buggy; use its extension instead Signed-off-by: Cosmic Snow --- gpt4all-chat/qml/ModelSettings.qml | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gpt4all-chat/qml/ModelSettings.qml b/gpt4all-chat/qml/ModelSettings.qml index a976e75d8da4..c17139ae6422 100644 --- a/gpt4all-chat/qml/ModelSettings.qml +++ b/gpt4all-chat/qml/ModelSettings.qml @@ -418,7 +418,6 @@ MySettingsTab { MyTextField { id: temperatureField - text: root.currentModelInfo.temperature inputMethodHints: Qt.ImhPreferNumbers font.pixelSize: theme.fontSizeLarge color: theme.textColor @@ -427,27 +426,32 @@ MySettingsTab { Layout.row: 1 Layout.column: 3 validator: DoubleValidator { - locale: "C" + locale: Qt.locale().name + } + function toLocaleString(number) { + console.assert(typeof number == 'number', "Number expected"); + let numberStr = number.toLocaleString(Qt.locale(), 'f', 6); + const trailingZeroes = /0+$/; + return numberStr.replace(trailingZeroes, ''); + } + function parseLocaleNumber(text) { + console.assert(typeof text == 'string', "String expected"); + try { + return Number.fromLocaleString(Qt.locale(), text); + } catch (e) { + return Number.NaN; + } } Connections { target: MySettings function onTemperatureChanged() { - temperatureField.text = root.currentModelInfo.temperature.toLocaleString( - Qt.locale().name, { maximumSignificantDigits: 6 }); + temperatureField.text = temperatureField.toLocaleString(root.currentModelInfo.temperature); } } Connections { target: root function onCurrentModelInfoChanged() { - temperatureField.text = root.currentModelInfo.temperature.toLocaleString( - Qt.locale().name, { maximumSignificantDigits: 6 }); - } - } - function parseLocaleNumber(text) { - try { - return Number.fromLocaleString(Qt.locale(), text); - } catch (e) { - return Number.NaN; + temperatureField.text = temperatureField.toLocaleString(root.currentModelInfo.temperature); } } onEditingFinished: { @@ -455,13 +459,12 @@ MySettingsTab { if (!isNaN(val)) { if (val < 0.000001) { val = 0.000001; - temperatureField.text = val.toLocaleString( - Qt.locale().name, { maximumSignificantDigits: 6 }); + temperatureField.text = toLocaleString(val); } - MySettings.setModelTemperature(root.currentModelInfo, val) - focus = false + MySettings.setModelTemperature(root.currentModelInfo, val); + focus = false; } else { - text = root.currentModelInfo.temperature + text = toLocaleString(root.currentModelInfo.temperature); } } Accessible.role: Accessible.EditableText From 6f076b6f4af830932b0debeec348119abaf0e547 Mon Sep 17 00:00:00 2001 From: Cosmic Snow Date: Thu, 1 Aug 2024 14:34:20 +0200 Subject: [PATCH 5/5] Guard against invalid temperature values in ModelInfo, as well Signed-off-by: Cosmic Snow --- gpt4all-chat/modellist.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index 7d2d349a1cda..15735b86012d 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -178,11 +178,13 @@ void ModelInfo::setRecency(const QDateTime &r) double ModelInfo::temperature() const { - return MySettings::globalInstance()->modelTemperature(*this); + double t = MySettings::globalInstance()->modelTemperature(*this); + return t < 0.000001 ? 0.000001 : t; } void ModelInfo::setTemperature(double t) { + if (t < 0.000001) t = 0.000001; if (shouldSaveMetadata()) MySettings::globalInstance()->setModelTemperature(*this, t, true /*force*/); m_temperature = t; }