Skip to content

Commit

Permalink
Add logging filters, update config namespaces (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo authored Aug 15, 2024
1 parent c76b453 commit babc56a
Show file tree
Hide file tree
Showing 46 changed files with 185 additions and 81 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 TaskMemoryTool, 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
20 changes: 0 additions & 20 deletions griptape/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +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 .logging_config import LoggingConfig
from .config import config


__all__ = [
"BaseConfig",
"BaseDriverConfig",
"DriverConfig",
"OpenAiDriverConfig",
"AzureOpenAiDriverConfig",
"AmazonBedrockDriverConfig",
"AnthropicDriverConfig",
"GoogleDriverConfig",
"CohereDriverConfig",
"LoggingConfig",
"config",
]
4 changes: 2 additions & 2 deletions griptape/config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from griptape.mixins.serializable_mixin import SerializableMixin

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


@define(kw_only=True)
Expand Down
6 changes: 3 additions & 3 deletions griptape/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from attrs import define, field

from .base_config import BaseConfig
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 .base_driver_config import BaseDriverConfig
from .drivers.base_driver_config import BaseDriverConfig


@define(kw_only=True)
Expand Down
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,7 +4,7 @@

from attrs import Factory, define, field

from griptape.config import DriverConfig
from griptape.config.drivers import DriverConfig
from griptape.drivers import (
AmazonBedrockImageGenerationDriver,
AmazonBedrockImageQueryDriver,
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from attrs import Factory, define, field

from griptape.config import DriverConfig
from griptape.config.drivers import DriverConfig
from griptape.drivers import (
AzureOpenAiChatPromptDriver,
AzureOpenAiEmbeddingDriver,
Expand Down
File renamed without changes.
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 (
BaseEmbeddingDriver,
BasePromptDriver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from attrs import Factory, define, field

from griptape.config import BaseDriverConfig
from griptape.config.drivers import BaseDriverConfig
from griptape.drivers import (
DummyAudioTranscriptionDriver,
DummyEmbeddingDriver,
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 (
BaseEmbeddingDriver,
BasePromptDriver,
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 (
BaseAudioTranscriptionDriver,
BaseEmbeddingDriver,
Expand Down
5 changes: 5 additions & 0 deletions griptape/config/logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .logging_config import LoggingConfig
from .truncate_logging_filter import TruncateLoggingFilter
from .newline_logging_filter import NewlineLoggingFilter

__all__ = ["LoggingConfig", "TruncateLoggingFilter", "NewlineLoggingFilter"]
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@
@define
class LoggingConfig:
logger_name: str = field(default="griptape", kw_only=True)
logger_level: int = field(
default=logging.INFO,
kw_only=True,
on_setattr=lambda self, _, value: logging.getLogger(self.logger_name).setLevel(value),
)

def __attrs_post_init__(self) -> None:
logger = logging.getLogger(self.logger_name)

logger.setLevel(logging.INFO)
logger.propagate = False
logger.setLevel(self.logger_level)

logger.handlers = [RichHandler(show_time=True, show_path=False)]
logger.addHandler(RichHandler(show_time=True, show_path=False))
Loading

0 comments on commit babc56a

Please sign in to comment.