From 1da3eac4425df35c54a5d150c4347a96dba6c119 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Fri, 28 Jun 2024 12:09:51 +1200 Subject: [PATCH 1/9] fixed temperature for ollama --- nodes/config_nodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/config_nodes.py b/nodes/config_nodes.py index 9ba395d..a6eabbd 100644 --- a/nodes/config_nodes.py +++ b/nodes/config_nodes.py @@ -154,7 +154,7 @@ class gtUIOllamaStructureConfig(gtUIBaseConfig): def create(self, prompt_model, temperature, seed): custom_config = StructureConfig( prompt_driver=OllamaPromptDriver( - model=prompt_model, temperature=temperature + model=prompt_model, options={"temperature": temperature} ), ) From 612b71b0932534cf623dfbba6de67bcad4f5ec28 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Fri, 28 Jun 2024 12:11:59 +1200 Subject: [PATCH 2/9] fixed configs --- js/gtUINodes.js | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/js/gtUINodes.js b/js/gtUINodes.js index ee9a8fa..48068b0 100644 --- a/js/gtUINodes.js +++ b/js/gtUINodes.js @@ -335,40 +335,27 @@ app.registerExtension({ init() { - // console.log("Griptape UI Extension Loaded"); - // let logging_entries = app.logging.app.logging.entries; - // // Filter to find the entry with type "warn" - // let warn_entry = logging_entries.find(entry => entry.type === "warn"); - // if (warn_entry) { - // console.log("Warn Entry:"); - // console.log(warn_entry); - // } else { - // console.log("No warn entry found"); - // } - - // console.log(logging_entries); - // let graphData = app.graphData; - // for (let n of graphData.nodes) { - // // Find missing node types - // if (!(n.type in LiteGraph.registered_node_types)) { - // missingNodeTypes.push(n.type); - // n.type = sanitizeNodeName(n.type); - // } - // } }, async beforeRegisterNodeDef(nodeType, nodeData, app) { + // if (nodeData.category.startsWith("Griptape")) { + // const origOnConfigure = nodeType.prototype.onConfigure; + // nodeType.prototype.onConfigure = function () { + // this.bgcolor = "#171717"; + // this.color = getColor(nodeData.category); + // }; + // Set Config node randomization to Fixed - if (nodeData.name.includes("Config")) { + if (nodeData.name.includes("Griptape Agent Config")) { const onNodeCreated = nodeType.prototype.onNodeCreated; nodeType.prototype.onNodeCreated = async function () { for (const widget of this.widgets) { if (widget.name === "control_after_generate") { widget.value = "fixed"; } + } } - } } // Create Audio Node From 5776cdda995d1363be2fc935af2ae3060b22564f Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 04:47:07 +1200 Subject: [PATCH 3/9] drag and drop working for audio --- js/gtUINodes.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/js/gtUINodes.js b/js/gtUINodes.js index 48068b0..32dd2a7 100644 --- a/js/gtUINodes.js +++ b/js/gtUINodes.js @@ -309,7 +309,37 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { } } }, + }); + this.onDragOver = function( e) { + if (e.dataTransfer && e.dataTransfer.items) { + const audio = [...e.dataTransfer.items].find((f) => f.kind === "file" && f.type.startsWith("audio/")); + console.log("dragover: " + audio);; + return !!audio; + } + return false; + } + this.onDragDrop = function (e) { + console.log("onDragDrop called"); + let handled = false; + for (const file of e.dataTransfer.files) { + if (file.type.startsWith("audio/")) { + handled = true; + uploadFile(file, !handled); + handled = true; + const filename = file.name; + console.log(filename); + pathWidget.options.values.push(filename); + pathWidget.value = filename; + if (pathWidget.callback) { + pathWidget.callback(filename) + } + + } + } + return handled; + + } }else { throw "Unknown upload type" } From f1b6f1cc4cc9ab6c05e95a9a15b3b83f3e4d8a40 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 04:48:18 +1200 Subject: [PATCH 4/9] removed console logs --- js/gtUINodes.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/gtUINodes.js b/js/gtUINodes.js index 32dd2a7..2dc9850 100644 --- a/js/gtUINodes.js +++ b/js/gtUINodes.js @@ -320,7 +320,6 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { return false; } this.onDragDrop = function (e) { - console.log("onDragDrop called"); let handled = false; for (const file of e.dataTransfer.files) { if (file.type.startsWith("audio/")) { @@ -328,7 +327,6 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { uploadFile(file, !handled); handled = true; const filename = file.name; - console.log(filename); pathWidget.options.values.push(filename); pathWidget.value = filename; if (pathWidget.callback) { From e05523b469f08145531c035504c6cd4eb449fb6c Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 07:47:50 +1200 Subject: [PATCH 5/9] only grab audio files --- nodes/audio_nodes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nodes/audio_nodes.py b/nodes/audio_nodes.py index 0eda757..35bfabf 100644 --- a/nodes/audio_nodes.py +++ b/nodes/audio_nodes.py @@ -1,8 +1,14 @@ +import mimetypes import os import folder_paths +def is_audio_file(filepath): + mime_type, _ = mimetypes.guess_type(filepath) + return mime_type is not None and mime_type.startswith("audio/") + + class gtUILoadAudio: DESCRIPTION = "Load an audio file for processing." @@ -13,6 +19,7 @@ class gtUILoadAudio: f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f)) + and is_audio_file(os.path.join(input_dir, f)) ] return { "required": {"audio": (sorted(files), {"audio_upload": True})}, From 06236a1c1bf3176a3ed12c2104868ba7f2e15b04 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 07:48:00 +1200 Subject: [PATCH 6/9] wip - adding audio css --- js/gtUI.css | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/js/gtUI.css b/js/gtUI.css index d6e4a23..9d2a0b3 100644 --- a/js/gtUI.css +++ b/js/gtUI.css @@ -9,3 +9,29 @@ width: 100%; overflow: auto; } + +.audio-container { + display: flex; + align-items: center; + justify-content: center; + margin-top: 20px; +} + +.play-pause-button { + background-color: #ff5722; + border: none; + border-radius: 50%; + color: white; + cursor: pointer; + font-size: 24px; + height: 50px; + width: 50px; +} + +.play-pause-button:focus { + outline: none; +} + +.button-icon { + font-size: 24px; +} From 236b72e18672decb4f13e50429068591dc307c52 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 07:48:36 +1200 Subject: [PATCH 7/9] wip loaders --- nodes/base_loader.py | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 nodes/base_loader.py diff --git a/nodes/base_loader.py b/nodes/base_loader.py new file mode 100644 index 0000000..bf987d3 --- /dev/null +++ b/nodes/base_loader.py @@ -0,0 +1,74 @@ +from griptape.structures import Agent +from griptape.tasks import PromptTask + + +class gtUIBaseTask: + def __init__(self): + pass + + DESCRIPTION = "Run a PromptTask." + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "STRING": ( + "STRING", + { + "multiline": True, + }, + ), + }, + "optional": { + "input_string": ( + "STRING", + { + "forceInput": True, + }, + ), + "agent": ("AGENT",), + }, + } + + RETURN_TYPES = ( + "STRING", + "AGENT", + ) + RETURN_NAMES = ( + "OUTPUT", + "AGENT", + ) + + FUNCTION = "run" + OUTPUT_NODE = True + + CATEGORY = "Griptape/Agent Tasks" + + def get_prompt_text(self, STRING, input_string): + # Get the prompt text + if not input_string: + prompt_text = STRING + else: + prompt_text = STRING + "\n\n" + input_string + + return prompt_text + + def run( + self, + STRING, + input_string=None, + agent=None, + ): + if not agent: + agent = Agent() + + prompt_text = self.get_prompt_text(STRING, input_string) + try: + agent.add_task(PromptTask(prompt_text)) + except Exception as e: + print(e) + result = agent.run() + return ( + result.output_task.output.value, + agent, + ) From b85f7d49dc652a88db6d4a459f89f25fe1318615 Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 07:50:35 +1200 Subject: [PATCH 8/9] added drag and drop --- js/gtUINodes.js | 50 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/js/gtUINodes.js b/js/gtUINodes.js index 2dc9850..a0c632d 100644 --- a/js/gtUINodes.js +++ b/js/gtUINodes.js @@ -229,6 +229,15 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { chainCallback(nodeType.prototype, "onNodeCreated", function() { const pathWidget = this.widgets.find((w) => w.name === widgetName); const fileInput = document.createElement("input"); + document.body.append(fileInput); + let uploadWidget = this.addWidget("button", "choose " + type + " to upload", "image", () => { + //clear the active click event + app.canvas.node_widget = null + + fileInput.click(); + }); + uploadWidget.options.serialize = false; + chainCallback(this, "onRemoved", () => { fileInput?.remove(); }); @@ -291,6 +300,24 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { }, }); } else if (type == "audio") { + // Create an audio element if not already created + // let audioWidget = document.getElementById('audio-widget'); + // let audioWidget = document.createElement('audio'); + // audioWidget.controls = true; // Add play controls + // document.body.append(audioWidget); // Append the audio element to the body or a specific container + // let audioButton = this.addWidget("button", "Play Audio ▶️", "audio", () => { + // audioWidget.play(); + // }); + // document.body.append(audioWidget); + // if (!audioWidget) { + // audioWidget = document.createElement('audio'); + // audioWidget.id = 'audio-widget'; + // audioWidget.controls = true; // Add play controls + // document.body.append(audioWidget); // Append the audio element to the body or a specific container + // let audioButton = this.addWidget("button", "Play Audio ▶️", "audio", () => { + // audioWidget.play(); + // }); + // } Object.assign(fileInput, { type: "file", accept: "audio/mpeg,audio/wav,audio/x-wav,audio/ogg", @@ -302,19 +329,25 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { return; } const filename = fileInput.files[0].name; + const filetype = fileInput.files[0].type; pathWidget.options.values.push(filename); pathWidget.value = filename; if (pathWidget.callback) { pathWidget.callback(filename) } + // Create a URL for the audio file and set it as the source of the audio element + // const audioURL = URL.createObjectURL(filename); + // audioWidget.src = audioURL; } }, }); + this.onDragOver = function( e) { if (e.dataTransfer && e.dataTransfer.items) { const audio = [...e.dataTransfer.items].find((f) => f.kind === "file" && f.type.startsWith("audio/")); - console.log("dragover: " + audio);; + // console.log("dragover: " + audio); + // console.log(audio); return !!audio; } return false; @@ -324,6 +357,7 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { for (const file of e.dataTransfer.files) { if (file.type.startsWith("audio/")) { handled = true; + console.log(file); uploadFile(file, !handled); handled = true; const filename = file.name; @@ -332,6 +366,12 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { if (pathWidget.callback) { pathWidget.callback(filename) } + + // Create a URL for the audio file and set it as the source of the audio element + // const audioURL = URL.createObjectURL(file); + // audioWidget.src = audioURL; + // audioWidget.play(); // Optionally play the audio automatically + } } @@ -341,14 +381,6 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { }else { throw "Unknown upload type" } - document.body.append(fileInput); - let uploadWidget = this.addWidget("button", "choose " + type + " to upload", "image", () => { - //clear the active click event - app.canvas.node_widget = null - - fileInput.click(); - }); - uploadWidget.options.serialize = false; }); } app.registerExtension({ From 14faf593173fe3959ae82e5336541491de6dcd1a Mon Sep 17 00:00:00 2001 From: Jason Schleifer Date: Sat, 29 Jun 2024 09:15:37 +1200 Subject: [PATCH 9/9] updated to 0.27.2 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4656482..96c512c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -griptape [all] == 0.27.1 +griptape [all] == 0.27.2 python-dotenv duckduckgo_search