From 79ca6c0989ba1183f1f90cf0258e4ba82af3e94d Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Thu, 12 Dec 2024 13:25:28 -0800 Subject: [PATCH] Update docs for saving/loading drivers configs --- docs/griptape-framework/structures/configs.md | 2 ++ .../structures/conversation-memory.md | 6 ++--- .../structures/src/drivers_config_8.py | 24 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/docs/griptape-framework/structures/configs.md b/docs/griptape-framework/structures/configs.md index fa72a1314..52c1c82f4 100644 --- a/docs/griptape-framework/structures/configs.md +++ b/docs/griptape-framework/structures/configs.md @@ -174,6 +174,8 @@ agent.run("Hello world!") ### Loading/Saving Configs +You can serialize and deserialize Driver Configs using the [to_json()](../../reference/griptape/mixins/serializable_mixin.md#griptape.mixins.serializable_mixin.SerializableMixin.to_json) and [from_json()](../../reference/griptape/mixins/serializable_mixin.md#griptape.mixins.serializable_mixin.SerializableMixin.from_json) methods. + ```python --8<-- "docs/griptape-framework/structures/src/drivers_config_8.py" ``` diff --git a/docs/griptape-framework/structures/conversation-memory.md b/docs/griptape-framework/structures/conversation-memory.md index 98f316b9b..e4e30ad7e 100644 --- a/docs/griptape-framework/structures/conversation-memory.md +++ b/docs/griptape-framework/structures/conversation-memory.md @@ -36,7 +36,7 @@ You can disable conversation memory in any structure by setting it to `None`: #### Per Structure -By default, Conversation Memory [Runs](../../reference/griptape/memory/structure/run.md) are created for each run of the structure. Griptape takes the Structure's [input_task](../../reference/griptape/structures/structure.md#griptape.structures.Structure.input_task)'s input and the [output_task](../../reference/griptape/structures/structure.md#griptape.structures.Structure.output_task)'s output, storing them in the Run. Tasks that are neither the input task nor the output task are not stored in the Run. +By default, Conversation Memory [Runs](../../reference/griptape/memory/structure/run.md) are created for each run of the structure. Griptape takes the Structure's [input_task](../../reference/griptape/structures/structure.md#griptape.structures.structure.Structure.input_task)'s input and the [output_task](../../reference/griptape/structures/structure.md#griptape.structures.structure.Structure.output_task)'s output, storing them in the Run. Tasks that are neither the input task nor the output task are not stored in the Run. ```python --8<-- "docs/griptape-framework/structures/src/conversation_memory_per_structure.py" @@ -46,7 +46,7 @@ In this example, the `improve` Task is "forgotten" after the Structure's run is #### Per Task -You can change when Conversation Memory Runs are created by modifying [Structure.conversation_memory_strategy](../../reference/griptape/structures/structure.md#griptape.structures.Structure.conversation_memory_strategy) from the default `per_structure` to `per_task`. +You can change when Conversation Memory Runs are created by modifying [Structure.conversation_memory_strategy](../../reference/griptape/structures/structure.md#griptape.structures.structure.Structure.conversation_memory_strategy) from the default `per_structure` to `per_task`. ```python --8<-- "docs/griptape-framework/structures/src/conversation_memory_per_task.py" @@ -54,7 +54,7 @@ You can change when Conversation Memory Runs are created by modifying [Structure Now, each _Task_ creates a Conversation Memory Run when it runs. This eliminates the need to feed the output of Tasks into each other using context variables like `{{ parent_output }}` since the output of the previous Task is stored in Conversation Memory and loaded when the next Task runs. -To blend the two approaches, you can disable Conversation Memory on individual tasks by setting [PromptTask.conversation_memory](../../reference/griptape/tasks/prompt_task.md#griptape.tasks.PromptTask.conversation_memory) to `None`. +To blend the two approaches, you can disable Conversation Memory on individual tasks by setting [PromptTask.conversation_memory](../../reference/griptape/tasks/prompt_task.md#griptape.tasks.prompt_task.PromptTask.conversation_memory) to `None`. ```python --8<-- "docs/griptape-framework/structures/src/conversation_memory_per_task_with_none.py" diff --git a/docs/griptape-framework/structures/src/drivers_config_8.py b/docs/griptape-framework/structures/src/drivers_config_8.py index f34a6d0b1..4abd8a361 100644 --- a/docs/griptape-framework/structures/src/drivers_config_8.py +++ b/docs/griptape-framework/structures/src/drivers_config_8.py @@ -1,18 +1,18 @@ +from pathlib import Path + from griptape.configs import Defaults -from griptape.configs.drivers import AmazonBedrockDriversConfig +from griptape.configs.drivers import DriversConfig from griptape.structures import Agent -custom_config = AmazonBedrockDriversConfig() -dict_config = custom_config.to_dict() -# Use OpenAi for embeddings -dict_config["embedding_driver"] = { - "base_url": None, - "model": "text-embedding-3-small", - "organization": None, - "type": "OpenAiEmbeddingDriver", -} -custom_config = AmazonBedrockDriversConfig.from_dict(dict_config) +config_file = "config.json" + +# Save config +config_text = Defaults.drivers_config.to_json() +Path(config_file).write_text(config_text) + +# Load config +config_text = Path(config_file).read_text() +Defaults.drivers_config = DriversConfig.from_json(config_text) -Defaults.drivers_config = custom_config agent = Agent()