ai chat: make it work with online models

This commit is contained in:
end-4
2025-05-05 23:47:34 +02:00
parent e3cf6b37e8
commit 8d93f44509
6 changed files with 238 additions and 41 deletions
@@ -228,7 +228,7 @@ Singleton {
property int barCenterSideModuleWidth: 360
property int barPreferredSideSectionWidth: 400
property int sidebarWidth: 450
property int sidebarWidthExtended: 700
property int sidebarWidthExtended: 750
property int notificationPopupWidth: 410
property int searchWidthCollapsed: 260
property int searchWidth: 450
@@ -8,3 +8,10 @@ function getDomain(url) {
const match = url.match(/^(?:https?:\/\/)?(?:www\.)?([^\/]+)/);
return match ? match[1] : null;
}
function shellSingleQuoteEscape(str) {
// First escape backslashes, then escape single quotes
return String(str)
.replace(/\\/g, '\\\\')
.replace(/'/g, "'\\''");
}
@@ -64,11 +64,22 @@ Item {
Ai.clearMessages();
}
},
{
name: "key",
description: qsTr("Set API key"),
execute: (args) => {
if (args[0] == "get") {
Ai.printApiKey()
} else {
Ai.setApiKey(args[0]);
}
}
},
{
name: "test",
description: qsTr("Markdown test message"),
execute: () => {
Ai.addMessage("## ✏️ Markdown test\n- **Bold**, *Italic*, `Monospace`, [Link](https://example.com)\n", "interface");
Ai.addMessage("## ✏️ Markdown test\n- **Bold**, *Italic*, `Monospace`, [Link](https://example.com)\n", Ai.interfaceRole);
}
},
]
@@ -82,7 +93,7 @@ Item {
if (commandObj) {
commandObj.execute(args);
} else {
Ai.addMessage(qsTr("Unknown command: ") + command, "interface");
Ai.addMessage(qsTr("Unknown command: ") + command, Ai.interfaceRole);
}
}
else {
@@ -218,14 +229,6 @@ Item {
commandButton.down ? Appearance.colors.colLayer2Active :
commandButton.hovered ? Appearance.colors.colLayer2Hover :
Appearance.colors.colLayer2
Behavior on color {
ColorAnimation {
duration: Appearance.animation.elementMove.duration
easing.type: Appearance.animation.elementMove.type
easing.bezierCurve: Appearance.animation.elementMove.bezierCurve
}
}
}
contentItem: RowLayout {
spacing: 5
@@ -93,8 +93,8 @@ Rectangle {
font.weight: Font.DemiBold
color: Appearance.m3colors.m3onSecondaryContainer
text: messageData.role == 'assistant' ? Ai.models[messageData.model].name :
messageData.role == 'user' ? (SystemInfo.username ?? "User") :
"System"
(messageData.role == 'user' && SystemInfo.username) ? SystemInfo.username :
Ai.models[messageData.role].name
}
}
}