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

Update docs for saving/loading drivers configs #1436

Merged
merged 1 commit into from
Dec 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
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,
Comment on lines -5 to -11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other docs showing this type of example of manipulating the "json" directly? Or maybe its not needed since why would you do that if you are already using python?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this example didn't feel all that necessary to me

"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()
Loading