Merge pull request #42 from griptape-ai:dev

Dev
This commit is contained in:
Jason Schleifer
2024-06-28 14:16:34 -07:00
committed by GitHub
6 changed files with 186 additions and 32 deletions
+26
View File
@@ -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;
}
+77 -30
View File
@@ -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,25 +329,58 @@ 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(audio);
return !!audio;
}
return false;
}
this.onDragDrop = function (e) {
let handled = false;
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;
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(file);
// audioWidget.src = audioURL;
// audioWidget.play(); // Optionally play the audio automatically
}
}
return handled;
}
}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({
@@ -335,40 +395,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
+7
View File
@@ -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})},
+74
View File
@@ -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,
)
+1 -1
View File
@@ -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}
),
)
+1 -1
View File
@@ -1,3 +1,3 @@
griptape [all] == 0.27.1
griptape [all] == 0.27.2
python-dotenv
duckduckgo_search