Merge pull request #75 from griptape-ai:simplifying_config

simplified environment variables
This commit is contained in:
Jason Schleifer
2024-07-16 09:57:04 -07:00
committed by GitHub
21 changed files with 57 additions and 79 deletions
+19 -10
View File
@@ -79,6 +79,9 @@ In this example, we're using three `Image Description` nodes to describe the giv
## Recent Changelog
### July 17, 2024
* Simplified API Keys by removing requirements for `griptape_config.json`. Now all keys are set in `.env`.
### July 16, 2024
* Reorganized all the nodes so each class is in it's own file. should make things easier to maintain
* Added `max_attemnpts_on_fail` parameter to all Config nodes to allow the user to determine the number of retries they want when an agent fails. This maps to the `max_attempts` parameter in the Griptape Framework.
@@ -131,13 +134,16 @@ If you'd like to run with a local LLM, you can use Ollama and install a model li
`ollama run llama3`
3. You now have ollama available to you.
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.
It's recommended to add these to a `.env` file in your base comfyUI folder before you start ComfyUI.
**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:
_Note: Most nodes will work fine with just the `OPENAI_API_KEY`, so at least make sure you have that one._
@@ -175,7 +181,7 @@ You can get the appropriate API keys from these respective sites:
* 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
* ELEVENLABS: https://elevenlabs.io/app/speech-synthesis
* 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
@@ -213,7 +219,6 @@ There are certain libraries required for Griptape nodes that are called out in t
```bash
griptape[all]
python-dotenv
duckduckgo_search
```
These should get installed automatically if you used the ComfyUI Manager installation method. However, if you're running into issues, please install them yourself either using `pip` or `poetry`, depending on your installation method.
@@ -221,13 +226,13 @@ These should get installed automatically if you used the ComfyUI Manager install
* Option A - **pip**
```bash
pip install "griptape[all]" python-dotenv duckduckgo_search
pip install "griptape[all]" python-dotenv
```
* Option B - **poetry**
```bash
poetry add "griptape[all]" python-dotenv duckduckgo_search
poetry add "griptape[all]" python-dotenv
```
#### 6. Restart ComfyUI
@@ -249,7 +254,7 @@ ImportError: cannot import name 'OllamaPromptDriver' from 'griptape.drivers' (C:
```
To resolve this, you must make sure Griptape is runnig with the appropriate version. Things to try:
To resolve this, you must make sure Griptape is running with the appropriate version. Things to try:
* Update again via the ComfyUI Manager
* Uninstall & Re-install the Griptape nodes via the ComfyUI Manager
@@ -258,11 +263,15 @@ To resolve this, you must make sure Griptape is runnig with the appropriate vers
### API Keys
When you run ComfyUI with the Griptape nodes installed, the installation method will check your environment variables and automatically install the appropriate API keys in a file called: `griptape_config.json`.
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`.
If for some reason your environment variables aren't being set properly, you can do this manually by simply copying over the `griptape_config.json.default` file to `griptape_config.json` and add the proper keys there.
For example, my `.env` is located here in **Windows**:
`C:\Users\jason\Documents\GitHub\ComfyUI\.env`
If you ever need to change your API keys, go ahead and update that configuration file with the proper key.
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.
---
-5
View File
@@ -79,7 +79,6 @@ from .nodes.tools.WebScraper import gtUIWebScraper
from .nodes.tools.WebSearch import gtUIWebSearch
from .py.griptape_config import (
load_and_prepare_config,
set_environment_variables_from_config,
)
# Setup to compute file paths relative to the directory containing this script
@@ -93,13 +92,9 @@ load_dotenv()
print("\n\033[34m[Griptape Custom Nodes]:\033[0m")
# Now load and prepare the configuration
config = load_and_prepare_config(DEFAULT_CONFIG_FILE, USER_CONFIG_FILE)
# Optionally set environment variables from this config if needed
set_environment_variables_from_config(config)
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
WEB_DIRECTORY = "./js"
-14
View File
@@ -1,18 +1,4 @@
{
"env": {
"OPENAI_API_KEY": "",
"GOOGLE_API_KEY": "",
"GOOGLE_API_SEARCH_ID": "",
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": "",
"AWS_DEFAULT_REGION": "us-east-1",
"LEONARDO_API_KEY": "",
"GRIPTAPE_API_KEY": "",
"ANTHROPIC_API_KEY": "",
"VOYAGE_API_KEY": "",
"HUGGINGFACE_HUB_ACCESS_TOKEN": "",
"AZURE_OPENAI_ENDPOINT": "",
"AZURE_OPENAI_API_KEY": "",
"ELEVEN_LABS_API_KEY": ""
}
}
+4 -3
View File
@@ -1,3 +1,5 @@
import os
from griptape.config import StructureConfig
# StructureGlobalDriversConfig,
@@ -8,7 +10,6 @@ from griptape.drivers import (
AzureOpenAiImageQueryDriver,
)
from ...py.griptape_config import get_config
from .BaseConfig import gtUIBaseConfig
@@ -52,8 +53,8 @@ class gtUIAzureOpenAiStructureConfig(gtUIBaseConfig):
max_attempts = kwargs.get("max_attempts_on_fail", 10)
prompt_model_deployment_id = kwargs.get("prompt_model_deployment_name", "gpt4o")
AZURE_OPENAI_ENDPOINT = get_config("env.AZURE_OPENAI_ENDPOINT")
AZURE_OPENAI_API_KEY = get_config("env.AZURE_OPENAI_API_KEY")
AZURE_OPENAI_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
AZURE_OPENAI_API_KEY = os.getenv("AZURE_OPENAI_API_KEY")
prompt_driver = AzureOpenAiChatPromptDriver(
api_key=AZURE_OPENAI_API_KEY,
+3 -2
View File
@@ -1,3 +1,5 @@
import os
from griptape.config import (
OpenAiStructureConfig,
)
@@ -10,7 +12,6 @@ from griptape.drivers import (
OpenAiImageQueryDriver,
)
from ...py.griptape_config import get_config
from .BaseConfig import gtUIBaseConfig
default_prompt_model = "gpt-4o"
@@ -52,7 +53,7 @@ class gtUIOpenAiStructureConfig(gtUIBaseConfig):
image_generation_driver = kwargs.get("image_generation_driver", None)
max_attempts = kwargs.get("max_attempts_on_fail", 10)
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
prompt_driver = OpenAiChatPromptDriver(
model=prompt_model,
api_key=OPENAI_API_KEY,
@@ -1,6 +1,7 @@
import os
from griptape.drivers import ElevenLabsTextToSpeechDriver
from ...py.griptape_config import get_config
from .BaseTextToSpeechDriver import gtUIBaseTextToSpeechDriver
premade_voices = []
@@ -27,7 +28,7 @@ class gtUIElevenLabsTextToSpeechDriver(gtUIBaseTextToSpeechDriver):
CATEGORY = "Griptape/Audio Drivers"
def create(self, **kwargs):
api_key = get_config(key="env.ELEVEN_LABS_API_KEY", default=None)
api_key = os.getenv("ELEVEN_LABS_API_KEY")
model = kwargs.get("model", "eleven_multilingual_v2")
voice = kwargs.get("voice", "Matilda")
+4 -7
View File
@@ -1,6 +1,7 @@
import os
from griptape.drivers import GoogleWebSearchDriver
from ...py.griptape_config import get_config
from .BaseWebSearchDriver import gtUIBaseWebSearchDriver
@@ -19,13 +20,9 @@ class gtUIGoogleWebSearchDriver(gtUIBaseWebSearchDriver):
)
return inputs
def get_api_key(self, KEY_ID):
# will get the API key from the environment, or return the default value
return get_config(key=KEY_ID, default=None)
def create(self, language="en", country="us", results_count=5):
GOOGLE_API_KEY = self.get_api_key("env.GOOGLE_API_KEY")
GOOGLE_API_SEARCH_ID = self.get_api_key("env.GOOGLE_API_SEARCH_ID")
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
GOOGLE_API_SEARCH_ID = os.getenv("GOOGLE_API_SEARCH_ID")
if not GOOGLE_API_KEY:
raise Exception(
@@ -1,8 +1,9 @@
import os
from griptape.drivers import (
LeonardoImageGenerationDriver,
)
from ...py.griptape_config import get_config
from .BaseImageDriver import gtUIBaseImageGenerationDriver
leonardo_models = [
@@ -96,7 +97,7 @@ class gtUILeonardoImageGenerationDriver(gtUIBaseImageGenerationDriver):
else:
m = self.get_model_by_name(model)
driver = LeonardoImageGenerationDriver(
api_key=get_config(key="env.LEONARDO_API_KEY", default=None),
api_key=os.getenv("LEONARDO_API_KEY"),
model=m,
)
return (driver,)
+3 -2
View File
@@ -1,3 +1,4 @@
import os
from textwrap import dedent
from griptape.drivers import (
@@ -14,11 +15,11 @@ from griptape.tasks import (
)
from griptape.utils import load_file
from ...py.griptape_config import get_config
from .BaseAudioTask import gtUIBaseAudioTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUIAudioTranscriptionTask(gtUIBaseAudioTask):
+3 -2
View File
@@ -1,12 +1,13 @@
import os
from griptape.tasks import (
CsvExtractionTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from .BaseTask import gtUIBaseTask
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUICsvExtractionTask(gtUIBaseTask):
+2 -2
View File
@@ -1,4 +1,5 @@
import base64
import os
from griptape.drivers import (
AmazonBedrockImageQueryDriver,
@@ -6,7 +7,6 @@ from griptape.drivers import (
)
from griptape.loaders import ImageLoader
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from ..utilities import (
convert_tensor_to_base_64,
@@ -14,7 +14,7 @@ from ..utilities import (
from .BaseImageTask import gtUIBaseImageTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUIImageQueryTask(gtUIBaseImageTask):
+3 -2
View File
@@ -1,13 +1,14 @@
import os
from griptape.tasks import (
JsonExtractionTask,
)
from schema import Schema
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from .BaseTask import gtUIBaseTask
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUIJsonExtractionTask(gtUIBaseTask):
+2 -2
View File
@@ -1,4 +1,5 @@
import base64
import os
from textwrap import dedent
from griptape.artifacts import BaseArtifact, TextArtifact
@@ -18,7 +19,6 @@ from griptape.tasks import (
PromptTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from ..utilities import (
convert_tensor_to_base_64,
@@ -26,7 +26,7 @@ from ..utilities import (
from .BaseImageTask import gtUIBaseImageTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def do_start_task(task: CodeExecutionTask) -> BaseArtifact:
+1 -2
View File
@@ -12,7 +12,6 @@ from griptape.tasks import (
PromptImageGenerationTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from ..utilities import (
image_path_to_output,
@@ -20,7 +19,7 @@ from ..utilities import (
from .BaseTask import gtUIBaseTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUIPromptImageGenerationTask(gtUIBaseTask):
+1 -2
View File
@@ -13,7 +13,6 @@ from griptape.tasks import (
VariationImageGenerationTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from ..utilities import (
convert_tensor_to_base_64,
@@ -22,7 +21,7 @@ from ..utilities import (
from .BaseImageTask import gtUIBaseImageTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
class gtUIPromptImageVariationTask(gtUIBaseImageTask):
-4
View File
@@ -1,8 +1,4 @@
from ...py.griptape_config import get_config
from .BaseTask import gtUIBaseTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
class gtUIPromptTask(gtUIBaseTask): ...
-4
View File
@@ -2,13 +2,9 @@ from griptape.tasks import (
TextSummaryTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from .BaseTask import gtUIBaseTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
class gtUITextSummaryTask(gtUIBaseTask):
DESCRIPTION = "Summarize a text prompt."
-4
View File
@@ -3,13 +3,9 @@ from griptape.tasks import (
ToolTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from .BaseTask import gtUIBaseTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
class gtUIToolTask(gtUIBaseTask):
DESCRIPTION = "Run a tool on a text prompt."
-4
View File
@@ -2,13 +2,9 @@ from griptape.tasks import (
ToolkitTask,
)
from ...py.griptape_config import get_config
from ..agent.agent import gtComfyAgent as Agent
from .BaseTask import gtUIBaseTask
default_prompt = "{{ input_string }}"
OPENAI_API_KEY = get_config("env.OPENAI_API_KEY")
class gtUIToolkitTask(gtUIBaseTask):
DESCRIPTION = "Provide a list of tools, and have the agent decide which of them to use utilizing Chain of Thought."
+3 -2
View File
@@ -1,9 +1,10 @@
import os
import requests
from griptape.tools import (
GriptapeCloudKnowledgeBaseClient,
)
from ...py.griptape_config import get_config
from .BaseTool import gtUIBaseTool
@@ -54,7 +55,7 @@ class gtUIKnowledgeBaseTool(gtUIBaseTool):
base_url,
knowledge_base_id,
):
api_key = get_config(f"env.{api_key_environment_variable}")
api_key = os.getenv(api_key_environment_variable)
# Use the Griptape API to grab the name and description of the knowledge base
data = self.getKnowledgeBaseInfo(api_key, base_url, knowledge_base_id)
+3 -2
View File
@@ -1,8 +1,9 @@
import os
from griptape.drivers import ElevenLabsTextToSpeechDriver
from griptape.engines import TextToSpeechEngine
from griptape.tools.text_to_speech_client.tool import TextToSpeechClient
from ...py.griptape_config import get_config
from .BaseTool import gtUIBaseTool
@@ -26,7 +27,7 @@ class gtUITextToSpeechClient(gtUIBaseTool):
def create(self, off_prompt, driver=None):
if not driver:
api_key = (get_config(key="env.ELEVEN_LABS_API_KEY", default=None),)
api_key = os.getenv("ELEVEN_LABS_API_KEY")
driver = ElevenLabsTextToSpeechDriver(
api_key=api_key, model="eleven_multilingual_v2", voice="Matilda"