diff --git a/package/contents/ui/InfoPage.qml b/package/contents/ui/InfoPage.qml new file mode 100644 index 0000000..ccb2aef --- /dev/null +++ b/package/contents/ui/InfoPage.qml @@ -0,0 +1,73 @@ +import QtQuick +import QtQuick.Layouts +import org.kde.kirigami as Kirigami +import org.kde.plasma.extras as PlasmaExtras +import org.kde.plasma.components as PlasmaComponents +import "Utils.js" as Utils + +ColumnLayout { + id: infoPage + spacing: 0 + Layout.topMargin: 0 + Layout.bottomMargin: 0 + + property string modelName: "" + property alias modelInfoText: modelInfoText + + property PlasmaExtras.PlasmoidHeading header: PlasmaExtras.PlasmoidHeading { + background.visible: false + + RowLayout { + id: infoToolbar + spacing: 0 + anchors.fill: parent + + PlasmaComponents.Label { + id: modelNameLabel + leftPadding: Kirigami.Units.smallSpacing + text: "Model Name: " + modelName + Layout.fillWidth: true + font.bold: true + } + + PlasmaComponents.Button { + id: backButton + icon.name: "go-previous-view" + icon.width: 16 + icon.height: 16 + rightPadding: Kirigami.Units.smallSpacing * 3 + text: i18n("Back") + onClicked: { + if (modelInfoText.text !== "") { + modelInfoText.text = ""; + } + stack.pop(); + } + } + } + } + + PlasmaComponents.ScrollView { + id: infoScrollView + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.leftMargin: Kirigami.Units.smallSpacing + Layout.rightMargin: PlasmaComponents.ScrollBar.vertical.visible ? 0 : Kirigami.Units.smallSpacing + contentWidth: PlasmaComponents.ScrollBar.vertical.visible ? infoScrollView.width - Kirigami.Units.smallSpacing * 6 : infoScrollView.width + + PlasmaComponents.TextArea { + id: modelInfoText + background: null + width: infoScrollView.contentWidth + readOnly: true + wrapMode: TextEdit.Wrap + textFormat: TextEdit.PlainText + text: "" + } + } + + Component.onCompleted: { + Utils.showModelInfo(modelName); + } +} \ No newline at end of file diff --git a/package/contents/ui/Utils.js b/package/contents/ui/Utils.js index bf577ed..f35b03a 100644 --- a/package/contents/ui/Utils.js +++ b/package/contents/ui/Utils.js @@ -204,6 +204,49 @@ function deleteModelCallback(resCode, _, stdout) { } } +function showModelInfo(modelName) { + const url = cfg.ollamaUrl + "/api/show"; + const data = JSON.stringify({ + name: modelName, + }); + + const xhr = new XMLHttpRequest(); + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.onreadystatechange = function () { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + const response = JSON.parse(xhr.responseText); + + function processTexts(obj) { + for (let key in obj) { + if (typeof obj[key] === "string") { + obj[key] = obj[key] + .replace(/\n/g, " ") + .replace(/\s+/g, " ") + .trim(); + } else if ( + typeof obj[key] === "object" && + obj[key] !== null + ) { + processTexts(obj[key]); + } + } + } + + processTexts(response); + + const responseText = JSON.stringify(response, null, 2); + infoPage.modelInfoText.text = responseText; + } else { + console.error("No Response"); + } + } + }; + xhr.send(data); +} + class Command { constructor(cmd, txt, callback) { this.cmd = cmd; @@ -282,10 +325,14 @@ function checkStat() { xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { + const response = JSON.parse(xhr.responseText); + const version = response.version; + if (ollamaRunning === false) { getModels(); } ollamaRunning = true; + ollamaVersion = version; // console.log("Ollama Running: " + ollamaRunning + " | Ollama is running"); } else {