Skip to content

Commit

Permalink
feat: Add Show information about a model including details, modelfile…
Browse files Browse the repository at this point in the history
…, template, parameters, license, system prompt.
  • Loading branch information
imoize committed Nov 10, 2024
1 parent caefe43 commit 1a20f75
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
73 changes: 73 additions & 0 deletions package/contents/ui/InfoPage.qml
Original file line number Diff line number Diff line change
@@ -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);
}
}
47 changes: 47 additions & 0 deletions package/contents/ui/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1a20f75

Please sign in to comment.