Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow zero as temperature in ModelSettings.qml #2777

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gpt4all-chat/modellist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
34 changes: 26 additions & 8 deletions gpt4all-chat/qml/ModelSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -418,35 +418,53 @@ 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.")
ToolTip.visible: hovered
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;
temperatureField.text = temperatureField.toLocaleString(root.currentModelInfo.temperature);
}
}
Connections {
target: root
function onCurrentModelInfoChanged() {
temperatureField.text = root.currentModelInfo.temperature;
temperatureField.text = temperatureField.toLocaleString(root.currentModelInfo.temperature);
}
}
onEditingFinished: {
var val = parseFloat(text)
var val = parseLocaleNumber(text);
if (!isNaN(val)) {
MySettings.setModelTemperature(root.currentModelInfo, val)
focus = false
if (val < 0.000001) {
val = 0.000001;
temperatureField.text = toLocaleString(val);
}
MySettings.setModelTemperature(root.currentModelInfo, val);
focus = false;
} else {
text = root.currentModelInfo.temperature
text = toLocaleString(root.currentModelInfo.temperature);
}
}
Accessible.role: Accessible.EditableText
Expand Down