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

Refactor/drivers config #1086

Merged
merged 9 commits into from
Aug 20, 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
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Parameter `structure` to `BaseTask`.
- Method `try_find_task` to `Structure`.
- `TranslateQueryRagModule` `RagEngine` module for translating input queries.
- Global event bus, `griptape.events.event_bus`, for publishing and subscribing to events.
- Global config, `griptape.config.config`, for setting global configuration defaults.
- Global event bus, `griptape.events.EventBus`, for publishing and subscribing to events.
- Global object, `griptape.configs.Defaults`, for setting default values throughout the framework.
- Unique name generation for all `RagEngine` modules.
- `ExtractionTool` for having the LLM extract structured data from text.
- `PromptSummaryTool` for having the LLM summarize text.
Expand All @@ -27,14 +27,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `griptape.utils.decorators.lazy_property` for creating lazy properties.

### Changed
- **BREAKING**: Removed all uses of `EventPublisherMixin` in favor of `event_bus`.
- **BREAKING**: Removed all uses of `EventPublisherMixin` in favor of `EventBus`.
- **BREAKING**: Removed `EventPublisherMixin`.
- **BREAKING**: Removed `Pipeline.prompt_driver` and `Workflow.prompt_driver`. `Agent.prompt_driver` has not been removed.
- **BREAKING**: Removed `Pipeline.stream` and `Workflow.stream`. `Agent.stream` has not been removed.
- **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 `Pipeline.prompt_driver` and `Workflow.prompt_driver`. Set this via `griptape.configs.Defaults.drivers.prompt_driver` instead. `Agent.prompt_driver` has not been removed.
- **BREAKING**: Removed `Pipeline.stream` and `Workflow.stream`. Set this via `griptape.configs.Defaults.drivers.prompt_driver.stream` instead. `Agent.stream` has not been removed.
- **BREAKING**: Removed `Structure.embedding_driver`, set this via `griptape.configs.Defaults.drivers.embedding_driver` instead.
- **BREAKING**: Removed `Structure.custom_logger` and `Structure.logger_level`, set these via `logging.getLogger(griptape.configs.Defaults.logger_name)` instead.
- **BREAKING**: Removed `BaseStructureConfig.merge_config`.
- **BREAKING**: Renamed `StructureConfig` to `DriverConfig`, moved to `griptape.config.drivers` and renamed fields accordingly.
- **BREAKING**: Renamed `StructureConfig` to `DriversConfig`, moved to `griptape.configs.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 All @@ -53,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Removed `JsonExtractionTask`, and `CsvExtractionTask` use `ExtractionTask` instead.
- **BREAKING**: Removed `TaskMemoryClient`, use `QueryClient`, `ExtractionTool`, or `PromptSummaryTool` instead.
- **BREAKING**: `BaseTask.add_parent/child` now take a `BaseTask` instead of `str | BaseTask`.
- Engines that previously required Drivers now pull from `griptape.config.config.drivers` by default.
- Engines that previously required Drivers now pull from `griptape.configs.Defaults.drivers_config` by default.
- `BaseTask.add_parent/child` will now call `self.structure.add_task` if possible.
- `BaseTask.add_parent/child` now returns `self`, allowing for chaining.
- `Chat` now sets the `griptape` logger level to `logging.ERROR`, suppressing all logs except for errors.
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/src/multiple_agent_shared_memory_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from griptape.config import config
from griptape.config.drivers import AzureOpenAiDriverConfig
from griptape.configs import Defaults
from griptape.configs.drivers import AzureOpenAiDriversConfig
from griptape.drivers import AzureMongoDbVectorStoreDriver, AzureOpenAiEmbeddingDriver
from griptape.structures import Agent
from griptape.tools import QueryTool, WebScraperTool
Expand Down Expand Up @@ -34,7 +34,7 @@
vector_path=MONGODB_VECTOR_PATH,
)

config.driver_config = AzureOpenAiDriverConfig(
Defaults.drivers_config = AzureOpenAiDriversConfig(
azure_endpoint=AZURE_OPENAI_ENDPOINT_1,
vector_store_driver=mongo_driver,
embedding_driver=embedding_driver,
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/src/talk_to_a_video_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import google.generativeai as genai

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

config.driver_config = GoogleDriverConfig()
Defaults.drivers_config = GoogleDriversConfig()

video_file = genai.upload_file(path="tests/resources/griptape-comfyui.mp4")
while video_file.state.name == "PROCESSING":
Expand Down
8 changes: 4 additions & 4 deletions docs/griptape-framework/drivers/src/embedding_drivers_10.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.configs import Defaults
from griptape.configs.drivers import DriversConfig
from griptape.drivers import (
OpenAiChatPromptDriver,
VoyageAiEmbeddingDriver,
)
from griptape.structures import Agent
from griptape.tools import PromptSummaryTool, WebScraperTool

config.driver_config = DriverConfig(
Defaults.drivers_config = DriversConfig(
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"),
embedding_driver=VoyageAiEmbeddingDriver(),
)

config.driver_config = DriverConfig(
Defaults.drivers_config = DriversConfig(
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"),
embedding_driver=VoyageAiEmbeddingDriver(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

from griptape.drivers import AmazonSqsEventListenerDriver
from griptape.events import EventListener, event_bus
from griptape.events import EventBus, EventListener
from griptape.rules import Rule
from griptape.structures import Agent

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
driver=AmazonSqsEventListenerDriver(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

from griptape.drivers import AmazonSqsEventListenerDriver
from griptape.events import EventListener, event_bus
from griptape.events import EventBus, EventListener
from griptape.rules import Rule
from griptape.structures import Agent

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
driver=AmazonSqsEventListenerDriver(
Expand Down
10 changes: 5 additions & 5 deletions docs/griptape-framework/drivers/src/event_listener_drivers_4.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os

from griptape.config import config
from griptape.config.drivers import DriverConfig
from griptape.configs import Defaults
from griptape.configs.drivers import DriversConfig
from griptape.drivers import AwsIotCoreEventListenerDriver, OpenAiChatPromptDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.rules import Rule
from griptape.structures import Agent

config.driver_config = DriverConfig(prompt_driver=OpenAiChatPromptDriver(model="gpt-3.5-turbo", temperature=0.7))
event_bus.add_event_listeners(
Defaults.drivers_config = DriversConfig(prompt_driver=OpenAiChatPromptDriver(model="gpt-3.5-turbo", temperature=0.7))
EventBus.add_event_listeners(
[
EventListener(
event_types=[FinishStructureRunEvent],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from griptape.drivers import GriptapeCloudEventListenerDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
event_types=[FinishStructureRunEvent],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

from griptape.drivers import WebhookEventListenerDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
event_types=[FinishStructureRunEvent],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

from griptape.drivers import PusherEventListenerDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
event_types=[FinishStructureRunEvent],
Expand Down
2 changes: 1 addition & 1 deletion docs/griptape-framework/misc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ search:

## Overview

You can configure the global [event_bus](../../reference/griptape/events/event_bus.md) with [EventListener](../../reference/griptape/events/event_listener.md)s to listen for various framework events.
You can configure the global [EventBus](../../reference/griptape/events/event_bus.md) with [EventListener](../../reference/griptape/events/event_listener.md)s to listen for various framework events.
See [Event Listener Drivers](../drivers/event-listener-drivers.md) for examples on forwarding events to external services.

## Specific Event Types
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_1.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from griptape.events import (
BaseEvent,
EventBus,
EventListener,
FinishActionsSubtaskEvent,
FinishPromptEvent,
FinishTaskEvent,
StartActionsSubtaskEvent,
StartPromptEvent,
StartTaskEvent,
event_bus,
)
from griptape.structures import Agent

Expand All @@ -16,7 +16,7 @@ def handler(event: BaseEvent) -> None:
print(event.__class__)


event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
handler,
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from griptape.events import BaseEvent, EventListener, event_bus
from griptape.events import BaseEvent, EventBus, EventListener
from griptape.structures import Agent


Expand All @@ -10,7 +10,7 @@ def handler2(event: BaseEvent) -> None:
print("Handler 2", event.__class__)


event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(handler1),
EventListener(handler2),
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import cast

from griptape.drivers import OpenAiChatPromptDriver
from griptape.events import CompletionChunkEvent, EventListener, event_bus
from griptape.events import CompletionChunkEvent, EventBus, EventListener
from griptape.structures import Pipeline
from griptape.tasks import ToolkitTask
from griptape.tools import PromptSummaryTool, WebScraperTool

event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
lambda e: print(cast(CompletionChunkEvent, e).token, end="", flush=True),
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from griptape.config import config
from griptape.configs import Defaults
from griptape.structures import Agent
from griptape.tools import PromptSummaryTool, WebScraperTool
from griptape.utils import Stream

# Hide Griptape's usual output
logging.getLogger(config.logging_config.logger_name).setLevel(logging.ERROR)
logging.getLogger(Defaults.logging_config.logger_name).setLevel(logging.ERROR)

agent = Agent(
input="Based on https://griptape.ai, tell me what griptape is.",
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_5.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from griptape import utils
from griptape.events import BaseEvent, EventListener, FinishPromptEvent, event_bus
from griptape.events import BaseEvent, EventBus, EventListener, FinishPromptEvent
from griptape.structures import Agent

token_counter = utils.TokenCounter()
Expand All @@ -10,7 +10,7 @@ def count_tokens(e: BaseEvent) -> None:
token_counter.add_tokens(e.output_token_count)


event_bus.add_event_listeners(
EventBus.add_event_listeners(
[
EventListener(
count_tokens,
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/misc/src/events_6.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from griptape.events import BaseEvent, EventListener, StartPromptEvent, event_bus
from griptape.events import BaseEvent, EventBus, EventListener, StartPromptEvent
from griptape.structures import Agent

event_bus.add_event_listeners([EventListener(handler=lambda e: print(e), event_types=[StartPromptEvent])])
EventBus.add_event_listeners([EventListener(handler=lambda e: print(e), event_types=[StartPromptEvent])])


def handler(event: BaseEvent) -> None:
Expand Down
89 changes: 0 additions & 89 deletions docs/griptape-framework/structures/config.md

This file was deleted.

Loading
Loading