This commit is contained in:
justumen
2024-11-22 12:30:00 +01:00
parent 840e62d00c
commit 0673c134d5
46 changed files with 1629 additions and 410 deletions

View File

@@ -0,0 +1,54 @@
import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "Bjornulf.OllamaConfig",
async nodeCreated(node) {
if (node.comfyClass === "Bjornulf_OllamaConfig") {
// Add model_list combo widget
const modelListWidget = node.addWidget(
"combo",
"select_model_here",
"",
(v) => {
// When model_list changes, update model_name
const modelNameWidget = node.widgets.find(w => w.name === "model_name");
if (modelNameWidget) {
modelNameWidget.value = v;
}
},
{ values: [] }
);
// Add update button
node.addCustomWidget({
name: "Update model_list",
type: "button",
value: "Update Models",
callback: async function() {
try {
const url = node.widgets.find(w => w.name === "ollama_url").value;
const response = await fetch(`${url}/api/tags`);
const data = await response.json();
if (data.models) {
const modelNames = data.models.map(m => m.name);
if (modelNames.length > 0) {
// Update model_list widget
modelListWidget.options.values = modelNames;
modelListWidget.value = modelNames[0];
// Update model_name widget
const modelNameWidget = node.widgets.find(w => w.name === "model_name");
if (modelNameWidget) {
modelNameWidget.value = modelNames[0];
}
}
}
} catch (error) {
console.error('Error updating models:', error);
}
}
});
}
}
});