Skip to content

Commit

Permalink
ollama-integration: fix JS error if ollama API was not reachable
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
  • Loading branch information
pbek committed Jun 18, 2024
1 parent 93735c6 commit 185df5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ollama-integration/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Ollama AI backend integration",
"identifier": "ollama-integration",
"script": "ollama-integration.qml",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "24.6.3",
"authors": ["@pbek"],
"description" : "This script provides integration for a local <a href=\"https://github.com/ollama/ollama\">Ollama</a> AI backend. If the Ollama service is up, the installed models will be fetched automatically every time the scripting engine is reloaded."
Expand Down
10 changes: 8 additions & 2 deletions ollama-integration/ollama-integration.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ Script {
];

function init() {
const data = JSON.parse(script.downloadUrlToString(this.apiBaseUrl + '/api/tags'));
const modelNames = data.models.map(model => model.model);
const data = script.downloadUrlToString(this.apiBaseUrl + '/api/tags')

if (data === '') {
return;
}

const dataJson = JSON.parse();
const modelNames = dataJson.models.map(model => model.model);

if (modelNames.length > 0) {
this.models = modelNames.join(',');
Expand Down

0 comments on commit 185df5b

Please sign in to comment.