Skip to content

Commit

Permalink
Merge pull request #219 from griptape-ai:fix/openai_api_key
Browse files Browse the repository at this point in the history
- `openai_utils` no longer breaks startup if OPENAI_API_KEY is incorrect.
  • Loading branch information
shhlife authored Jan 3, 2025
2 parents e078fe3 + a9399e9 commit ae80168
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Security -->

## [2.1.05] - 2025-04-01
### Fixed
- `openai_utils` no longer breaks startup if OPENAI_API_KEY is incorrect.

## [2.1.04] - 2025-04-01
### Added
- `Griptape Util: Switch Node` - This node lets you choose an output from multiple inputs.
Expand Down
25 changes: 15 additions & 10 deletions nodes/utils/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ def get_available_models(model_type: ModelTypes) -> list:
api_key = settings.get_settings_key_or_use_env(API_KEY)
if api_key is None:
return []
client = OpenAI(api_key=api_key)
available_models = client.models.list().data

# Get the predefined list of ChatModel IDs
chat_model_ids = set(get_args(model_type_map[model_type]))

# Filter available models to include only those matching ChatModel
filtered_chat_models = [
model.id for model in available_models if model.id in chat_model_ids
]

return filtered_chat_models
model_ids = get_args(model_type_map[model_type])
try:
client = OpenAI(api_key=api_key)
# Filter available models to include only those matching ChatModel
chat_model_ids = set(model_ids)
available_models = client.models.list().data
filtered_chat_models = [
model.id for model in available_models if model.id in chat_model_ids
]

return filtered_chat_models
except Exception:
print("Warning: Could not connect to OpenAI API - returning all models.")
chat_model_ids = list(model_ids)
return chat_model_ids
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "comfyui-griptape"
version = "2.1.04"
version = "2.1.05"
description = "Griptape LLM(Large Language Model) Nodes for ComfyUI."
authors = ["Jason Schleifer <[email protected]>"]
readme = "README.md"
Expand All @@ -9,7 +9,7 @@ readme = "README.md"
[project]
name = "comfyui-griptape"
description = "Griptape LLM(Large Language Model) Nodes for ComfyUI."
version = "2.1.04"
version = "2.1.05"
license = {file = "LICENSE"}
dependencies = ["attrs==^24.3.0", "openai==^1.58.1", "griptape[all]==^1.1.0", "python-dotenv", "poetry==1.8.5", "griptape-black-forest @ git+https://github.com/griptape-ai/griptape-black-forest.git"]

Expand Down

0 comments on commit ae80168

Please sign in to comment.