Skip to content

Commit

Permalink
Merge pull request #147 from griptape-ai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
shhlife authored Oct 31, 2024
2 parents be0bbe2 + 6b07ec8 commit 104bd77
Show file tree
Hide file tree
Showing 30 changed files with 400 additions and 334 deletions.
111 changes: 44 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ You can previous and download more examples [here](examples/README.md).

## Recent Changelog

### Nov 1, 2024
* Major reworking of how API keys are set. Now you can use the ComfyUI Settings window and add your API keys there. This should simplify things quite a bit as you no longer need to create a `.env` file in your ComfyUI folder.

* Note: Existing environment variables will be picked up automatically.

![Griptape Settings](docs/images/griptape_settings.png)

### Oct 31, 2024
* Added tooltips for all drivers to help clarify properties
* Added fix for Ollama Driver Config so it wouldn't fail if no embedding driver was specified.
Expand Down Expand Up @@ -327,59 +334,7 @@ If you'd like to run with a local LLM, you can use Ollama and install a model li

3. You now have ollama available to you. To use it, follow the instructions in this YouTube video: https://youtu.be/jIq_TL5xmX0?si=0i-myC6tAqG8qbxR

#### 3. Add API Keys to your environment

For advanced features, it's recommended to use a more powerful model. These are available from the providers listed bellow, and will require API keys.

**Create a `.env` file**

* In the base comfyUI folder, create a file called `.env` if it doesn't already exist
* Add an API key for each of the services you require. You will see a list of the appropriate keys below:


```bash
OPENAI_API_KEY=
GOOGLE_API_KEY=
GOOGLE_API_SEARCH_ID=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
LEONARDO_API_KEY=
ANTHROPIC_API_KEY=
VOYAGE_API_KEY=
GRIPTAPE_CLOUD_API_KEY=
HUGGINGFACE_HUB_ACCESS_TOKEN=
AZURE_OPENAI_ENDPOINT=
AZURE_OPENAI_API_KEY=
COHERE_API_KEY=
ELEVEN_LABS_API_KEY=
```

You can get the appropriate API keys from these respective sites:

* OPENAI_API_KEY: https://platform.openai.com/api-keys
* GOOGLE_API_KEY: https://makersuite.google.com/app/apikey
* AWS_ACCESS_KEY_ID & SECURITY_ACCESS_KEY:
* Open the [AWS Console](https://console.aws.amazon.com/)
* Click on your username near the top right and select **Security Credentials**
* Click on **Users** in the sidebar
* Click on your username
* Click on the **Security Credentials** tab
* Click **Create Access Key**
* Click **Show User Security Credentials**
* LEONARDO_API_KEY: https://docs.leonardo.ai/docs/create-your-api-key
* ANTHROPIC_API_KEY: https://console.anthropic.com/settings/keys
* VOYAGE_API_KEY: https://dash.voyageai.com/
* HUGGINGFACE_HUB_ACCESS_TOKEN: https://huggingface.co/settings/tokens
* AZURE_OPENAI_ENDPOINT & AZURE_OPENAI_API_KEY: https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints
* COHERE_API_KEY: https://dashboard.cohere.com/api-keys
* ELEVEN_LABS_API_KEY: https://elevenlabs.io/app/
* Click on your username in the lower left
* Choose **Profile + API Key**
* Generate and copy the API key
* GRIPTAPE_CLOUD_API_KEY: https://cloud.griptape.ai/configuration/api-keys

#### 4. Install Griptape-ComfyUI
#### 3. Install Griptape-ComfyUI

There are two methods for installing the Griptape-ComfyUI repository. You can either download or git clone this repository inside the `ComfyUI/custom_nodes`, or use the [ComfyUI Manager](https://github.com/ltdrdata/ComfyUI-Manager).

Expand All @@ -403,7 +358,7 @@ There are two methods for installing the Griptape-ComfyUI repository. You can ei
```


#### 5. Make sure libraries are loaded
#### 4. Make sure libraries are loaded

Libraries should be installed automatically, but if you're having trouble, hopefully this can help.

Expand All @@ -428,12 +383,46 @@ These should get installed automatically if you used the ComfyUI Manager install
poetry add "griptape[all]" python-dotenv
```

#### 6. Restart ComfyUI
#### 5. Restart ComfyUI

Now if you restart comfyUI, you should see the Griptape menu when you click with the Right Mouse button.

If you don't see the menu, please come to our [Discord](https://discord.gg/fexDeKxf) and let us know what kind of errors you're getting - we would like to resolve them as soon as possible!

#### 6. Set API Keys

For advanced features, it's recommended to use a more powerful model. These are available from the providers listed bellow, and will require API keys.
1. To set an API key, click on the `Settings` button in the **ComfyUI Sidebar**.
2. Select the `Griptape` option.
3. Scroll down to the API key you'd like to set and enter it.

*Note: If you already have a particular API key set in your environment, it will automatically show up here.*

You can get the appropriate API keys from these respective sites:

* OPENAI_API_KEY: https://platform.openai.com/api-keys
* GOOGLE_API_KEY: https://makersuite.google.com/app/apikey
* AWS_ACCESS_KEY_ID & SECURITY_ACCESS_KEY:
* Open the [AWS Console](https://console.aws.amazon.com/)
* Click on your username near the top right and select **Security Credentials**
* Click on **Users** in the sidebar
* Click on your username
* Click on the **Security Credentials** tab
* Click **Create Access Key**
* Click **Show User Security Credentials**
* LEONARDO_API_KEY: https://docs.leonardo.ai/docs/create-your-api-key
* ANTHROPIC_API_KEY: https://console.anthropic.com/settings/keys
* VOYAGE_API_KEY: https://dash.voyageai.com/
* HUGGINGFACE_HUB_ACCESS_TOKEN: https://huggingface.co/settings/tokens
* AZURE_OPENAI_ENDPOINT & AZURE_OPENAI_API_KEY: https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints
* COHERE_API_KEY: https://dashboard.cohere.com/api-keys
* ELEVEN_LABS_API_KEY: https://elevenlabs.io/app/
* Click on your username in the lower left
* Choose **Profile + API Key**
* Generate and copy the API key
* GRIPTAPE_CLOUD_API_KEY: https://cloud.griptape.ai/configuration/api-keys

---

## Troubleshooting
Expand Down Expand Up @@ -463,18 +452,6 @@ To resolve this, you must make sure Griptape is running with the appropriate ver
* In the terminal, go to your ComfyUI directory and type: `python -m pip install griptape -U`
* Reach out on [Discord](https://discord.gg/fexDeKxf) and ask for help.
### API Keys
Griptape will use API keys set as environment variables. Please ensure you have your keys set in a `.env` file located in the base directory of `comfyUI`.
For example, my `.env` is located here in **Windows**:
`C:\Users\jason\Documents\GitHub\ComfyUI\.env`
It's located here in **MacOS**:
`/Users/jason/Documents/GitHub/ComfyUI/.env`

If you ever need to change your API keys, go ahead and update that file with the proper key and restart ComfyUI.

### StabilityMatrix
If you are using [StabilityMatrix](https://github.com/LykosAI/StabilityMatrix) to run ComfyUI, you may find that after you install Griptape you get an error like the following:
Expand Down
14 changes: 12 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import os
import sys

from dotenv import load_dotenv

Expand All @@ -15,7 +14,6 @@
from .nodes.agent.gtUICreateAgentFromConfig import gtUICreateAgentFromConfig
from .nodes.agent.gtUIReplaceRulesetsOnAgent import gtUIReplaceRulesetsOnAgent
from .nodes.agent.gtUIReplaceToolsOnAgent import gtUIReplaceToolsOnAgent
from .nodes.agent.gtUIRunAgent import gtUIRunAgent
from .nodes.agent.gtUISetDefaultAgent import gtUISetDefaultAgent
from .nodes.agent.RunAgent import RunAgent

Expand Down Expand Up @@ -291,6 +289,7 @@
from .py.griptape_config import (
load_and_prepare_config,
)
from .py.griptape_settings import GriptapeSettings

# Setup to compute file paths relative to the directory containing this script

Expand Down Expand Up @@ -473,6 +472,17 @@
"Griptape RAG Response: Footnote Prompt Module": gtUIFootnotePromptResponseRagModule,
}

# Let's do the settings

root = "Griptape"
settings = GriptapeSettings()
settings.get_key_config()
settings.get_all_services()
for service in settings.all_services:
keys = settings.get_keys_for_service(service)
for key in keys:
settings.set_settings_key(f"{root}.{key}", os.getenv(key))
settings.save_settings()

__all__ = ["NODE_CLASS_MAPPINGS", "WEB_DIRECTORY"]
print(" \033[34m- \033[92mDone!\033[0m\n")
Binary file added docs/images/griptape_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions js/griptape_api_keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const keys_organized = {
"@Griptape": [
"GRIPTAPE_CLOUD_API_KEY"
],
"OpenAI": [
"OPENAI_API_KEY"
],
"Amazon": [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_DEFAULT_REGION",
"AMAZON_OPENSEARCH_HOST",
"AMAZON_OPENSEARCH_INDEX_NAME"
],
"Anthropic": [
"ANTHROPIC_API_KEY"
],
"Microsoft Azure": [
"AZURE_OPENAI_ENDPOINT",
"AZURE_OPENAI_DALL_E_3_ENDPOINT",
"AZURE_OPENAI_DALL_E_3_API_KEY",
"AZURE_OPENAI_API_KEY"
],
"Cohere": [
"COHERE_API_KEY"
],
"Eleven Labs": [
"ELEVEN_LABS_API_KEY"
],
"Exa": [
"EXA_API_KEY"
],
"Groq": [
"GROQ_API_KEY"
],
"Google": [
"GOOGLE_API_KEY",
"GOOGLE_API_SEARCH_ID"
],
"Huggingface": [
"HUGGINGFACE_HUB_ACCESS_TOKEN"
],
"LeonardoAI": [
"LEONARDO_API_KEY"
],
"Pinecone": [
"PINECONE_API_KEY",
"PINECONE_ENVIRONMENT",
"PINECONE_INDEX_NAME"
],
"Tavily": [
"TAVILY_API_KEY"
]
}
47 changes: 16 additions & 31 deletions js/gtUINodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ import { setupExtractionNodes } from "./ExtractionNodes.js";
import { setupTextLoaderModuleNodes } from "./TextLoaderModuleNodes.js";
import { gtUIAddUploadWidget } from "./gtUIUtils.js";
import { setupMenuSeparator } from "./gtUIMenuSeparator.js";
// app.extensionManager.registerSidebarTab({
// id: "search",
// icon: "pi pi-search",
// title: "search",
// tooltip: "search",
// type: "custom",
// render: (el: HTMLElement) => {
// el.innerHTML = "<div>Custom search tab</div>";
// },
// });
import { keys_organized } from "./griptape_api_keys.js";

app.registerExtension({
name: "comfy.gtUI",
Expand All @@ -36,28 +27,22 @@ app.registerExtension({
// console.log(event.detail.message)
}
api.addEventListener("comfy.gtUI.runagent", messageHandler);

// app.ui.settings.addSetting({
// id: "griptape.api_keys.openai_api_key",
// name: "OPENAI_API_KEY",
// type: "textbox", // "text" is another simple option

// defaultValue: "123456",
// /* To listen for changes, add an onChange parameter
// onChange: (newVal, oldVal) => { console.log("Setting got changed!") },
// */
// });
// app.ui.settings.addSetting({
// id: "griptape.api_keys.griptape_api_key",
// name: "GRIPTAPE_API_KEY",
// type: "textbox", // "text" is another simple option

// defaultValue: "123456",
// /* To listen for changes, add an onChange parameter
// onChange: (newVal, oldVal) => { console.log("Setting got changed!") },
// */
// });

// Create the settings
Object.entries(keys_organized).forEach(([category, keys]) => {
keys.forEach(key => {
app.ui.settings.addSetting({
id: `Griptape.${key}`,
category: ["Griptape", category, key],
name: key,
type: "text",
defaultValue: "",
/* To listen for changes, add an onChange parameter
onChange: (newVal, oldVal) => { console.log("Setting got changed!") },
*/
});
});
});
},


Expand Down
9 changes: 8 additions & 1 deletion js/versions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
export const versions = {
"version": "0.34.0b",
"version": "0.34.0c",
"releaseDate": "2024-10-31",
"name": "ComfyUI-Griptape",
"description": "Griptape integration for ComfyUI",
"author": "Jason Schleifer",
"repository": "https://github.com/griptape-ai/ComfyUI-Griptape",
"changelog": [
{
"version": "0.34.0c",
"date": "2024-11-11",
"changes": [
"Updated environment configuration",
]
},
{
"version": "0.34.0b",
"date": "2024-10-31",
Expand Down
17 changes: 12 additions & 5 deletions nodes/agent/BaseAgent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import logging

from comfy_execution.graph import ExecutionBlocker
from griptape.drivers import DummyVectorStoreDriver
from griptape.tools import QueryTool, RagTool, VectorStoreTool
from openai import OpenAIError
Expand Down Expand Up @@ -179,8 +182,16 @@ def run(self, **kwargs):

# Warn for models
model, simple_model = self.agent.model_check()

if model == "":
error_msg = "You have provided a blank model for the Agent Configuration.\n\nPlease specify a model configuration, or disconnect it from the agent."
logging.error(error_msg)
raise Exception(error_msg)
return (
ExecutionBlocker(error_msg),
self.agent,
)
if simple_model:
print(f"This is a simple model: {model}")
return (self.agent.model_response(model), self.agent)

# Check for inputs. If none, then just create the agent
Expand All @@ -193,10 +204,6 @@ def run(self, **kwargs):
else:
prompt_text = STRING + "\n\n" + input_string

# if len(tools) > 0:
# self.agent.add_task(ToolkitTask(prompt_text, tools=tools))
# else:
# self.agent.add_task(PromptTask(prompt_text))
result = self.agent.run(prompt_text)
output_string = result.output_task.output.value
return (
Expand Down
2 changes: 1 addition & 1 deletion nodes/agent/gtComfyAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def model_check(self):
simple_models = ["llama3", "llama3:latest", "mistral", "LLama-3"]
drivers = ["OllamaPromptDriver", "LMStudioPromptDriver"]
agent_prompt_driver_name = self.prompt_driver.__class__.__name__

print(f"Agent Prompt Driver Name: {agent_prompt_driver_name=}")
model = self.prompt_driver.model
if agent_prompt_driver_name in drivers:
if model == "":
Expand Down
Loading

0 comments on commit 104bd77

Please sign in to comment.