mirror of
https://github.com/end-4/dots-hyprland.git
synced 2026-06-05 14:59:27 -05:00
ai: add temperature
This commit is contained in:
@@ -6,6 +6,7 @@ pragma ComponentBehavior: Bound
|
||||
Singleton {
|
||||
property QtObject ai: QtObject {
|
||||
property string model
|
||||
property real temperature: 0.5
|
||||
}
|
||||
|
||||
property QtObject sidebar: QtObject {
|
||||
|
||||
@@ -67,6 +67,19 @@ Item {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "temp",
|
||||
description: qsTr("Set temperature (randomness) of the model. Values range between 0 to 2 for Gemini, 0 to 1 for other models. Default is 0.5."),
|
||||
execute: (args) => {
|
||||
// console.log(args)
|
||||
if (args.length == 0 || args[0] == "get") {
|
||||
Ai.printTemperature()
|
||||
} else {
|
||||
const temp = parseFloat(args[0]);
|
||||
Ai.setTemperature(temp);
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "test",
|
||||
description: qsTr("Markdown test"),
|
||||
|
||||
@@ -25,6 +25,7 @@ Singleton {
|
||||
readonly property var apiKeys: KeyringStorage.keyringData?.apiKeys ?? {}
|
||||
readonly property var apiKeysLoaded: KeyringStorage.loaded
|
||||
property var postResponseHook
|
||||
property real temperature: PersistentStates?.ai?.temperature ?? 0.5
|
||||
|
||||
function idForMessage(message) {
|
||||
// Generate a unique ID using timestamp and random value
|
||||
@@ -311,6 +312,20 @@ Singleton {
|
||||
KeyringStorage.fetchKeyringData();
|
||||
}
|
||||
}
|
||||
|
||||
function getTemperature() {
|
||||
return root.temperature;
|
||||
}
|
||||
|
||||
function setTemperature(value) {
|
||||
if (value == NaN || value < 0 || value > 2) {
|
||||
root.addMessage(qsTr("Temperature must be between 0 and 2"), Ai.interfaceRole);
|
||||
return;
|
||||
}
|
||||
PersistentStateManager.setState("ai.temperature", value);
|
||||
root.temperature = value;
|
||||
root.addMessage(StringUtils.format(qsTr("Temperature set to {0}"), value), Ai.interfaceRole);
|
||||
}
|
||||
|
||||
function setApiKey(key) {
|
||||
const model = models[currentModelId];
|
||||
@@ -341,6 +356,10 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
function printTemperature() {
|
||||
root.addMessage(StringUtils.format(qsTr("Temperature: {0}"), root.temperature), Ai.interfaceRole);
|
||||
}
|
||||
|
||||
function clearMessages() {
|
||||
root.messageIDs = [];
|
||||
root.messageByID = ({});
|
||||
@@ -409,7 +428,11 @@ Singleton {
|
||||
],
|
||||
"system_instruction": {
|
||||
"parts": [{ text: root.systemPrompt }]
|
||||
}
|
||||
},
|
||||
"generationConfig": {
|
||||
"temperature": root.temperature,
|
||||
"responseMimeType": "text/plain",
|
||||
},
|
||||
};
|
||||
return model.extraParams ? Object.assign({}, baseData, model.extraParams) : baseData;
|
||||
}
|
||||
@@ -427,6 +450,7 @@ Singleton {
|
||||
}),
|
||||
],
|
||||
"stream": true,
|
||||
"temperature": root.temperature,
|
||||
};
|
||||
return model.extraParams ? Object.assign({}, baseData, model.extraParams) : baseData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user