From df53cdeef9915dd215b2a88bc85b36ca09def293 Mon Sep 17 00:00:00 2001 From: Zach Giordano Date: Mon, 9 Sep 2024 13:43:19 -0400 Subject: [PATCH] Add docs showing how to override default configs --- Makefile | 4 ++ README.md | 2 + docs/griptape-framework/structures/configs.md | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Makefile b/Makefile index 1db428b2c..3e4f35f54 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,10 @@ check/spell: docs: ## Build documentation. @poetry run mkdocs build +.PHONY: docs/serve +docs/serve: ## Server documentation. + @poetry run mkdocs serve + .DEFAULT_GOAL := help .PHONY: help help: ## Print Makefile help text. diff --git a/README.md b/README.md index 95f6326dd..e68400ffa 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,8 @@ Run `make test/unit` to execute the test suite locally. Run `make docs` to build the documentation locally. +Run `make docs/serve` to serve the documentation locally. + 5. **Code Checks:** Griptape a variety of tools to enforce code quality and style. Your code must pass all checks before it can be merged. Run `make check` to run all code checks locally. diff --git a/docs/griptape-framework/structures/configs.md b/docs/griptape-framework/structures/configs.md index 2a9b5c62d..e22787909 100644 --- a/docs/griptape-framework/structures/configs.md +++ b/docs/griptape-framework/structures/configs.md @@ -74,6 +74,55 @@ This approach ensures that you are informed through clear error messages if you --8<-- "docs/griptape-framework/structures/src/drivers_config_7.py" ``` +### Overriding Default Configs + +While using a Default Driver Config, there may be instances in which you wish to override default drivers in order to mix and match LLM providers as needed. The following example showcases a Default of `OpenAiDriversConfig` with overrides for the `vector_store_driver`: + +```python +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)) +``` + ### Logging Config Griptape provides a predefined [LoggingConfig](../../reference/griptape/configs/logging/logging_config.md)'s for easily customizing the logging events that the framework emits. In order to customize the logger, the logger can be fetched by using the `Defaults.logging.logger_name`.