Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default for GriptapeCloudEventListenerDriver.api_key #990

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docs-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
GOOGLE_AUTH_URI: ${{ secrets.INTEG_GOOGLE_AUTH_URI }}
GOOGLE_TOKEN_URI: ${{ secrets.INTEG_GOOGLE_TOKEN_URI }}
GOOGLE_AUTH_PROVIDER_X509_CERT_URL: ${{ secrets.INTEG_GOOGLE_AUTH_PROVIDER_X509_CERT_URL }}
GT_CLOUD_API_KEY: ${{ secrets.INTEG_GRIPTAPE_CLOUD_API_KEY }}
GRIPTAPE_CLOUD_API_KEY: ${{ secrets.INTEG_GRIPTAPE_CLOUD_API_KEY }}
GRIPTAPE_CLOUD_STRUCTURE_ID: ${{ secrets.INTEG_GRIPTAPE_CLOUD_STRUCTURE_ID }}
GRIPTAPE_CLOUD_BASE_URL: ${{ secrets.INTEG_GRIPTAPE_CLOUD_BASE_URL }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Native function calling support to `OpenAiChatPromptDriver`, `AzureOpenAiChatPromptDriver`, `AnthropicPromptDriver`, `AmazonBedrockPromptDriver`, `GooglePromptDriver`, and `CoherePromptDriver`.
- `OllamaEmbeddingDriver` for generating embeddings with Ollama.
- `GriptapeCloudKnowledgeBaseVectorStoreDriver` to query Griptape Cloud Knowledge Bases.
- `GriptapeCloudEventListenerDriver.api_key` defaults to the value in the `GT_CLOUD_API_KEY` environment variable.

### Changed
- **BREAKING**: `BaseVectorStoreDriver.upsert_text_artifacts` optional arguments are now keyword-only arguments.
Expand Down
12 changes: 6 additions & 6 deletions docs/griptape-framework/drivers/event-listener-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ from griptape.drivers import GriptapeCloudEventListenerDriver
from griptape.events import FinishStructureRunEvent
from griptape.artifacts import TextArtifact

event_driver = GriptapeCloudEventListenerDriver(
api_key=os.environ["GRIPTAPE_CLOUD_API_KEY"]
)
# By default, GriptapeCloudEventListenerDriver uses the api key provided
# in the GT_CLOUD_API_KEY environment variable.
event_driver = GriptapeCloudEventListenerDriver()

done_event = FinishStructureRunEvent(
output_task_input=TextArtifact("Just started!"),
Expand Down Expand Up @@ -173,9 +173,9 @@ agent = Agent(
event_listeners=[
EventListener(
event_types=[FinishStructureRunEvent],
driver=GriptapeCloudEventListenerDriver(
api_key=os.environ["GRIPTAPE_CLOUD_API_KEY"],
),
# By default, GriptapeCloudEventListenerDriver uses the api key provided
# in the GT_CLOUD_API_KEY environment variable.
driver=GriptapeCloudEventListenerDriver(),
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GriptapeCloudEventListenerDriver(BaseEventListenerDriver):
default=Factory(lambda: os.getenv("GT_CLOUD_BASE_URL", "https://cloud.griptape.ai")),
kw_only=True,
)
api_key: str = field(kw_only=True)
api_key: str = field(default=Factory(lambda: os.getenv("GT_CLOUD_API_KEY")), kw_only=True)
headers: dict = field(
default=Factory(lambda self: {"Authorization": f"Bearer {self.api_key}"}, takes_self=True),
kw_only=True,
Expand Down
2 changes: 1 addition & 1 deletion griptape/tools/calculator/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Calculator(BaseTool):
},
)
def calculate(self, params: dict) -> BaseArtifact:
import numexpr
import numexpr # pyright: ignore[reportMissingImports]

try:
expression = params["values"]["expression"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ def mock_post(self, mocker):

@pytest.fixture()
def driver(self):
os.environ["GT_CLOUD_BASE_URL"] = "https://cloud123.griptape.ai"
environ = {
"GT_CLOUD_BASE_URL": "https://cloud123.griptape.ai",
"GT_CLOUD_API_KEY": "foo bar",
"GT_CLOUD_STRUCTURE_RUN_ID": "bar baz",
}
original_environ = {}
for key, value in environ.items():
original_environ[key] = os.environ.get(key)
os.environ[key] = value

return GriptapeCloudEventListenerDriver(api_key="foo bar", structure_run_id="bar baz")
yield GriptapeCloudEventListenerDriver()

for key, value in original_environ.items():
if value is None:
del os.environ[key]
else:
os.environ[key] = value

def test_init(self, driver):
assert driver
Expand Down
Loading