Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/task-memory-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Aug 15, 2024
2 parents 2a61f43 + adb660e commit b2ee6f7
Show file tree
Hide file tree
Showing 55 changed files with 1,304 additions and 1,087 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Removed `Structure.embedding_driver`, set this via `griptape.config.config.drivers.embedding` instead.
- **BREAKING**: Removed `Structure.custom_logger` and `Structure.logger_level`, set these via `griptape.config.config.logger` instead.
- **BREAKING**: Removed `BaseStructureConfig.merge_config`.
- **BREAKING**: Renamed `StructureConfig` to `DriverConfig`, and renamed fields accordingly.
- **BREAKING**: Renamed `StructureConfig` to `DriverConfig`, moved to `griptape.config.drivers` and renamed fields accordingly.
- **BREAKING**: `RagContext.output` was changed to `RagContext.outputs` to support multiple outputs. All relevant RAG modules were adjusted accordingly.
- **BREAKING**: Removed before and after response modules from `ResponseRagStage`.
- **BREAKING**: Moved ruleset and metadata ingestion from standalone modules to `PromptResponseRagModule`.
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/src/multiple_agent_shared_memory_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from griptape.config import AzureOpenAiDriverConfig, config
from griptape.config import config
from griptape.config.drivers import AzureOpenAiDriverConfig
from griptape.drivers import AzureMongoDbVectorStoreDriver, AzureOpenAiEmbeddingDriver
from griptape.structures import Agent
from griptape.tools import QueryTool, WebScraperTool
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/src/talk_to_a_video_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import google.generativeai as genai

from griptape.artifacts import GenericArtifact, TextArtifact
from griptape.config import GoogleDriverConfig, config
from griptape.config import config
from griptape.config.drivers import GoogleDriverConfig
from griptape.structures import Agent

config.drivers = GoogleDriverConfig()
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/drivers/src/embedding_drivers_10.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from griptape.config import DriverConfig, config
from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.drivers import (
OpenAiChatPromptDriver,
VoyageAiEmbeddingDriver,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from griptape.config import DriverConfig, config
from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.drivers import AwsIotCoreEventListenerDriver, OpenAiChatPromptDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.rules import Rule
Expand Down
34 changes: 22 additions & 12 deletions docs/griptape-framework/structures/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,47 @@ search:

## Overview

The [DriverConfig](../../reference/griptape/config/driver_config.md) class allows for the customization of Structures within Griptape, enabling specific settings such as Drivers to be defined for Tasks.
Griptape exposes global configuration options to easily customize different parts of the framework.

### Premade Configs
### Driver Configs

Griptape provides predefined [DriverConfig](../../reference/griptape/config/driver_config.md)'s for widely used services that provide APIs for most Driver types Griptape offers.
The [DriverConfig](../../reference/griptape/config/drivers/driver_config.md) class allows for the customization of Structures within Griptape, enabling specific settings such as Drivers to be defined for Tasks.

Griptape provides predefined [DriverConfig](../../reference/griptape/config/drivers/driver_config.md)'s for widely used services that provide APIs for most Driver types Griptape offers.

#### OpenAI

The [OpenAI Driver config](../../reference/griptape/config/openai_driver_config.md) provides default Drivers for OpenAI's APIs. This is the default config for all Structures.
The [OpenAI Driver config](../../reference/griptape/config/drivers/openai_driver_config.md) provides default Drivers for OpenAI's APIs. This is the default config for all Structures.

```python
--8<-- "docs/griptape-framework/structures/src/config_1.py"
```

#### Azure OpenAI

The [Azure OpenAI Driver config](../../reference/griptape/config/azure_openai_driver_config.md) provides default Drivers for Azure's OpenAI APIs.
The [Azure OpenAI Driver config](../../reference/griptape/config/drivers/azure_openai_driver_config.md) provides default Drivers for Azure's OpenAI APIs.

```python
--8<-- "docs/griptape-framework/structures/src/config_2.py"
```

#### Amazon Bedrock
The [Amazon Bedrock Driver config](../../reference/griptape/config/amazon_bedrock_driver_config.md) provides default Drivers for Amazon Bedrock's APIs.
The [Amazon Bedrock Driver config](../../reference/griptape/config/drivers/amazon_bedrock_driver_config.md) provides default Drivers for Amazon Bedrock's APIs.

```python
--8<-- "docs/griptape-framework/structures/src/config_3.py"
```

#### Google
The [Google Driver config](../../reference/griptape/config/google_driver_config.md) provides default Drivers for Google's Gemini APIs.
The [Google Driver config](../../reference/griptape/config/drivers/google_driver_config.md) provides default Drivers for Google's Gemini APIs.

```python
--8<-- "docs/griptape-framework/structures/src/config_4.py"
```

#### Anthropic

The [Anthropic Driver config](../../reference/griptape/config/anthropic_driver_config.md) provides default Drivers for Anthropic's APIs.
The [Anthropic Driver config](../../reference/griptape/config/drivers/anthropic_driver_config.md) provides default Drivers for Anthropic's APIs.

!!! info
Anthropic does not provide an embeddings API which means you will need to use another service for embeddings.
Expand All @@ -56,22 +58,30 @@ The [Anthropic Driver config](../../reference/griptape/config/anthropic_driver_c

#### Cohere

The [Cohere Driver config](../../reference/griptape/config/cohere_driver_config.md) provides default Drivers for Cohere's APIs.
The [Cohere Driver config](../../reference/griptape/config/drivers/cohere_driver_config.md) provides default Drivers for Cohere's APIs.

```python
--8<-- "docs/griptape-framework/structures/src/config_6.py"
```

### Custom Configs
#### Custom

You can create your own [DriverConfig](../../reference/griptape/config/driver_config.md) by overriding relevant Drivers.
The [DriverConfig](../../reference/griptape/config/driver_config.md) class includes "Dummy" Drivers for all types, which throw a [DummyError](../../reference/griptape/exceptions/dummy_exception.md) if invoked without being overridden.
You can create your own [DriverConfig](../../reference/griptape/config/drivers/driver_config.md) by overriding relevant Drivers.
The [DriverConfig](../../reference/griptape/config/drivers/driver_config.md) class includes "Dummy" Drivers for all types, which throw a [DummyError](../../reference/griptape/exceptions/dummy_exception.md) if invoked without being overridden.
This approach ensures that you are informed through clear error messages if you attempt to use Structures without proper Driver configurations.

```python
--8<-- "docs/griptape-framework/structures/src/config_7.py"
```

### Logging Config

Griptape provides a predefined [LoggingConfig](../../reference/griptape/config/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 `config.logging.logger_name`.

```python
--8<-- "docs/griptape-framework/structures/src/config_logging.py"
```

### Loading/Saving Configs

```python
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from griptape.config import OpenAiDriverConfig, config
from griptape.config import config
from griptape.config.drivers import OpenAiDriverConfig
from griptape.structures import Agent

config.drivers = OpenAiDriverConfig()
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from griptape.config import AzureOpenAiDriverConfig, config
from griptape.config import config
from griptape.config.drivers import AzureOpenAiDriverConfig
from griptape.structures import Agent

config.drivers = AzureOpenAiDriverConfig(
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import boto3

from griptape.config import AmazonBedrockDriverConfig, config
from griptape.config import config
from griptape.config.drivers import AmazonBedrockDriverConfig
from griptape.structures import Agent

config.drivers = AmazonBedrockDriverConfig(
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from griptape.config import GoogleDriverConfig, config
from griptape.config import config
from griptape.config.drivers import GoogleDriverConfig
from griptape.structures import Agent

config.drivers = GoogleDriverConfig()
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from griptape.config import AnthropicDriverConfig, config
from griptape.config import config
from griptape.config.drivers import AnthropicDriverConfig
from griptape.structures import Agent

config.drivers = AnthropicDriverConfig()
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_6.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from griptape.config import CohereDriverConfig, config
from griptape.config import config
from griptape.config.drivers import CohereDriverConfig
from griptape.structures import Agent

config.drivers = CohereDriverConfig(api_key=os.environ["COHERE_API_KEY"])
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_7.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from griptape.config import DriverConfig, config
from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.drivers import AnthropicPromptDriver
from griptape.structures import Agent

Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-framework/structures/src/config_8.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from griptape.config import AmazonBedrockDriverConfig, config
from griptape.config import config
from griptape.config.drivers import AmazonBedrockDriverConfig
from griptape.structures import Agent

custom_config = AmazonBedrockDriverConfig()
Expand Down
14 changes: 14 additions & 0 deletions docs/griptape-framework/structures/src/config_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging

from griptape.config import config
from griptape.config.drivers import OpenAiDriverConfig
from griptape.config.logging import TruncateLoggingFilter
from griptape.structures import Agent

config.drivers = OpenAiDriverConfig()

logger = logging.getLogger(config.logging.logger_name)
logger.setLevel(logging.ERROR)
logger.addFilter(TruncateLoggingFilter(max_log_length=100))

agent = Agent()
6 changes: 2 additions & 4 deletions docs/griptape-framework/structures/src/task_memory_6.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from griptape.artifacts import TextArtifact
from griptape.config import (
OpenAiDriverConfig,
config,
)
from griptape.config import config
from griptape.config.drivers import OpenAiDriverConfig
from griptape.drivers import (
LocalVectorStoreDriver,
OpenAiChatPromptDriver,
Expand Down
3 changes: 2 additions & 1 deletion docs/griptape-tools/official-tools/src/rest_api_tool_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from json import dumps

from griptape.config import DriverConfig, config
from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.drivers import OpenAiChatPromptDriver
from griptape.memory.structure import ConversationMemory
from griptape.structures import Pipeline
Expand Down
18 changes: 0 additions & 18 deletions griptape/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
from .base_config import BaseConfig

from .base_driver_config import BaseDriverConfig

from .driver_config import DriverConfig
from .openai_driver_config import OpenAiDriverConfig
from .azure_openai_driver_config import AzureOpenAiDriverConfig
from .amazon_bedrock_driver_config import AmazonBedrockDriverConfig
from .anthropic_driver_config import AnthropicDriverConfig
from .google_driver_config import GoogleDriverConfig
from .cohere_driver_config import CohereDriverConfig
from .config import config


__all__ = [
"BaseConfig",
"BaseDriverConfig",
"DriverConfig",
"OpenAiDriverConfig",
"AzureOpenAiDriverConfig",
"AmazonBedrockDriverConfig",
"AnthropicDriverConfig",
"GoogleDriverConfig",
"CohereDriverConfig",
"config",
]
18 changes: 13 additions & 5 deletions griptape/config/base_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from __future__ import annotations

from abc import ABC
from typing import TYPE_CHECKING, Optional

from attrs import define
from attrs import define, field

from griptape.mixins.serializable_mixin import SerializableMixin

from .base_driver_config import BaseDriverConfig
from .logging_config import LoggingConfig
if TYPE_CHECKING:
from .drivers.base_driver_config import BaseDriverConfig
from .logging.logging_config import LoggingConfig


@define(kw_only=True)
class BaseConfig(SerializableMixin, ABC):
drivers: BaseDriverConfig
logging: LoggingConfig
_logging: Optional[LoggingConfig] = field(alias="logging")
_drivers: Optional[BaseDriverConfig] = field(alias="drivers")

def reset(self) -> None:
self._logging = None
self._drivers = None
41 changes: 34 additions & 7 deletions griptape/config/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
from attrs import Factory, define, field
from __future__ import annotations

from typing import TYPE_CHECKING, Optional

from attrs import define, field

from .base_config import BaseConfig
from .base_driver_config import BaseDriverConfig
from .logging_config import LoggingConfig
from .openai_driver_config import OpenAiDriverConfig
from .drivers.openai_driver_config import OpenAiDriverConfig
from .logging.logging_config import LoggingConfig

if TYPE_CHECKING:
from .drivers.base_driver_config import BaseDriverConfig

@define

@define(kw_only=True)
class _Config(BaseConfig):
drivers: BaseDriverConfig = field(default=Factory(lambda: OpenAiDriverConfig()), kw_only=True)
logging: LoggingConfig = field(default=Factory(lambda: LoggingConfig()), kw_only=True)
_logging: Optional[LoggingConfig] = field(default=None, alias="logging")
_drivers: Optional[BaseDriverConfig] = field(default=None, alias="drivers")

@property
def drivers(self) -> BaseDriverConfig:
"""Lazily instantiates the drivers configuration to avoid client errors like missing API key."""
if self._drivers is None:
self._drivers = OpenAiDriverConfig()
return self._drivers

@drivers.setter
def drivers(self, drivers: BaseDriverConfig) -> None:
self._drivers = drivers

@property
def logging(self) -> LoggingConfig:
if self._logging is None:
self._logging = LoggingConfig()
return self._logging

@logging.setter
def logging(self, logging: LoggingConfig) -> None:
self._logging = logging


config = _Config()
20 changes: 20 additions & 0 deletions griptape/config/drivers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .base_driver_config import BaseDriverConfig
from .driver_config import DriverConfig

from .openai_driver_config import OpenAiDriverConfig
from .azure_openai_driver_config import AzureOpenAiDriverConfig
from .amazon_bedrock_driver_config import AmazonBedrockDriverConfig
from .anthropic_driver_config import AnthropicDriverConfig
from .google_driver_config import GoogleDriverConfig
from .cohere_driver_config import CohereDriverConfig

__all__ = [
"BaseDriverConfig",
"DriverConfig",
"OpenAiDriverConfig",
"AzureOpenAiDriverConfig",
"AmazonBedrockDriverConfig",
"AnthropicDriverConfig",
"GoogleDriverConfig",
"CohereDriverConfig",
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

from attrs import Factory, define, field

from griptape.config import DriverConfig
from griptape.config.drivers import DriverConfig
from griptape.drivers import (
AmazonBedrockImageGenerationDriver,
AmazonBedrockImageQueryDriver,
AmazonBedrockPromptDriver,
AmazonBedrockTitanEmbeddingDriver,
BaseEmbeddingDriver,
BaseImageGenerationDriver,
BaseImageQueryDriver,
BasePromptDriver,
BaseVectorStoreDriver,
BedrockClaudeImageQueryModelDriver,
Expand Down Expand Up @@ -63,7 +64,7 @@ class AmazonBedrockDriverConfig(DriverConfig):
kw_only=True,
metadata={"serializable": True},
)
image_query: BaseImageGenerationDriver = field(
image_query: BaseImageQueryDriver = field(
default=Factory(
lambda self: AmazonBedrockImageQueryDriver(
session=self.session,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from attrs import Factory, define, field

from griptape.config import DriverConfig
from griptape.config.drivers import DriverConfig
from griptape.drivers import (
AnthropicImageQueryDriver,
AnthropicPromptDriver,
Expand Down
Loading

0 comments on commit b2ee6f7

Please sign in to comment.