Skip to content

Commit

Permalink
Update docs for saving/loading drivers configs
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Dec 16, 2024
1 parent ca39b3b commit 79ca6c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions docs/griptape-framework/structures/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
6 changes: 3 additions & 3 deletions docs/griptape-framework/structures/conversation-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,15 +46,15 @@ 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"
```

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"
Expand Down
24 changes: 12 additions & 12 deletions docs/griptape-framework/structures/src/drivers_config_8.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 79ca6c0

Please sign in to comment.