Restore MSR character analyze config and parsing
This commit is contained in:
@@ -92,6 +92,9 @@ function setWidgetValue(node, widget, value) {
|
||||
function syncFormFromWidgets(node) {
|
||||
const description = findWidget(node, "description")?.value || "";
|
||||
const alias = findWidget(node, "alias")?.value || "";
|
||||
const provider = findWidget(node, "analyze_provider")?.value || "ollama";
|
||||
const model = findWidget(node, "analyze_model")?.value || "";
|
||||
const baseUrl = findWidget(node, "analyze_base_url")?.value || "";
|
||||
|
||||
if (node._msrAliasInput && node._msrAliasInput.value !== alias) {
|
||||
node._msrAliasInput.value = alias;
|
||||
@@ -104,6 +107,7 @@ function syncFormFromWidgets(node) {
|
||||
alias
|
||||
? `Alias: <span style="color:#e8e8e8">@${String(alias).replace(/^@/, "")}</span>`
|
||||
: "Alias: <span style=\"color:#666\">none</span>",
|
||||
`<div style="margin-top:4px;color:#888">Analyze: ${provider}${model ? ` / ${model}` : ""}${baseUrl ? ` / ${baseUrl}` : ""}</div>`,
|
||||
description
|
||||
? `<div style="margin-top:4px;color:#d0d0d0">${description}</div>`
|
||||
: `<div style="margin-top:4px;color:#666">Description will be used for prompt replacement outside MSR prefix mode.</div>`,
|
||||
@@ -189,6 +193,36 @@ function buildCharacterUi(node) {
|
||||
gap: "6px",
|
||||
});
|
||||
|
||||
const settingsButton = document.createElement("button");
|
||||
settingsButton.type = "button";
|
||||
settingsButton.textContent = "Analyze Settings";
|
||||
Object.assign(settingsButton.style, {
|
||||
alignSelf: "flex-start",
|
||||
background: "#252525",
|
||||
color: "#ddd",
|
||||
border: "1px solid #444",
|
||||
borderRadius: "6px",
|
||||
padding: "6px 10px",
|
||||
fontSize: "11px",
|
||||
cursor: "pointer",
|
||||
});
|
||||
settingsButton.addEventListener("click", () => {
|
||||
const providerWidget = findWidget(node, "analyze_provider");
|
||||
const baseUrlWidget = findWidget(node, "analyze_base_url");
|
||||
const modelWidget = findWidget(node, "analyze_model");
|
||||
const provider = window.prompt("Analyze provider: ollama, lmstudio, custom, off", providerWidget?.value || "ollama");
|
||||
if (provider == null) return;
|
||||
const baseUrl = window.prompt("Analyze base URL (blank = default)", baseUrlWidget?.value || "");
|
||||
if (baseUrl == null) return;
|
||||
const model = window.prompt("Analyze model (blank = provider default)", modelWidget?.value || "");
|
||||
if (model == null) return;
|
||||
setWidgetValue(node, providerWidget, provider.trim() || "ollama");
|
||||
setWidgetValue(node, baseUrlWidget, baseUrl.trim());
|
||||
setWidgetValue(node, modelWidget, model.trim());
|
||||
syncFormFromWidgets(node);
|
||||
node.setDirtyCanvas?.(true, true);
|
||||
});
|
||||
|
||||
const aliasLabel = document.createElement("label");
|
||||
aliasLabel.textContent = "Alias";
|
||||
Object.assign(aliasLabel.style, {
|
||||
@@ -245,6 +279,7 @@ function buildCharacterUi(node) {
|
||||
form.appendChild(aliasInput);
|
||||
form.appendChild(descLabel);
|
||||
form.appendChild(descInput);
|
||||
form.appendChild(settingsButton);
|
||||
|
||||
container.appendChild(previewRow);
|
||||
container.appendChild(meta);
|
||||
@@ -261,6 +296,9 @@ function buildCharacterUi(node) {
|
||||
async function analyzeCharacterNode(node, buttonWidget) {
|
||||
const descriptionWidget = findWidget(node, "description");
|
||||
if (!descriptionWidget) return;
|
||||
const providerWidget = findWidget(node, "analyze_provider");
|
||||
const baseUrlWidget = findWidget(node, "analyze_base_url");
|
||||
const modelWidget = findWidget(node, "analyze_model");
|
||||
|
||||
buttonWidget.label = "Analyzing...";
|
||||
node.setDirtyCanvas?.(true, true);
|
||||
@@ -280,7 +318,9 @@ async function analyzeCharacterNode(node, buttonWidget) {
|
||||
const response = await api.fetchApi("/ltx_director/analyze_character", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
provider: "ollama",
|
||||
provider: providerWidget?.value || "ollama",
|
||||
base_url: baseUrlWidget?.value || "",
|
||||
model: modelWidget?.value || "",
|
||||
image_b64: images,
|
||||
}),
|
||||
});
|
||||
@@ -332,6 +372,18 @@ app.registerExtension({
|
||||
buttonWidget.label = "Analyze with Ollama";
|
||||
}
|
||||
|
||||
if (!findWidget(this, "analyze_provider")) {
|
||||
this.addWidget("combo", "analyze_provider", "ollama", null, {
|
||||
values: ["ollama", "lmstudio", "custom", "off"],
|
||||
});
|
||||
}
|
||||
if (!findWidget(this, "analyze_base_url")) {
|
||||
this.addWidget("text", "analyze_base_url", "");
|
||||
}
|
||||
if (!findWidget(this, "analyze_model")) {
|
||||
this.addWidget("text", "analyze_model", "");
|
||||
}
|
||||
|
||||
if (!this._msrPreviewWidget) {
|
||||
const previewContainer = buildCharacterUi(this);
|
||||
this._msrPreviewWidget = this.addDOMWidget("msr_character_ui", "msr_character_ui", previewContainer, {
|
||||
@@ -358,7 +410,7 @@ app.registerExtension({
|
||||
return result;
|
||||
};
|
||||
|
||||
["alias", "description"].forEach((widgetName) => {
|
||||
["alias", "description", "analyze_provider", "analyze_base_url", "analyze_model"].forEach((widgetName) => {
|
||||
hideNodeWidget(findWidget(this, widgetName));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user