-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add doc example for overriding default config
- Loading branch information
1 parent
1bc1a5f
commit 3a23e94
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docs/griptape-framework/structures/src/config_defaults_override.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
|
||
from griptape.configs import Defaults | ||
from griptape.configs.drivers import OpenAiDriversConfig | ||
from griptape.drivers import AstraDbVectorStoreDriver, OpenAiEmbeddingDriver | ||
from griptape.loaders import WebLoader | ||
from griptape.structures import Agent | ||
|
||
# Astra DB secrets and connection parameters | ||
api_endpoint = os.environ["ASTRA_DB_API_ENDPOINT"] | ||
token = os.environ["ASTRA_DB_APPLICATION_TOKEN"] | ||
astra_db_namespace = os.environ.get("ASTRA_DB_KEYSPACE") # optional | ||
TEST_COLLECTION_NAME = "gt_int_test" | ||
|
||
embedding_driver = OpenAiEmbeddingDriver(api_key=os.environ["OPENAI_API_KEY"]) | ||
vector_store_driver = AstraDbVectorStoreDriver( | ||
embedding_driver=embedding_driver, | ||
api_endpoint=api_endpoint, | ||
token=token, | ||
collection_name=TEST_COLLECTION_NAME, | ||
astra_db_namespace=astra_db_namespace, # optional | ||
) | ||
Defaults.drivers_config = OpenAiDriversConfig( | ||
embedding_driver=embedding_driver, | ||
vector_store_driver=vector_store_driver, | ||
) | ||
|
||
# This agent will be created with all the default drivers from the OpenAI drivers config, | ||
# and an override for the vector_store_driver to use AstraDbVectorStoreDriver | ||
openai_agent = Agent() | ||
|
||
# Load Artifacts from the web | ||
artifacts = WebLoader().load("https://www.griptape.ai") | ||
|
||
# Upsert Artifacts into the Vector Store Driver | ||
[vector_store_driver.upsert_text_artifact(a, namespace="griptape") for a in artifacts] | ||
|
||
results = vector_store_driver.query(query="What is griptape?") | ||
|
||
values = [r.to_artifact().value for r in results] | ||
|
||
print("\n\n".join(values)) |