Skip to content

Commit

Permalink
Global Config (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter authored Aug 13, 2024
1 parent 688bc98 commit e600334
Show file tree
Hide file tree
Showing 147 changed files with 834 additions and 1,237 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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.
- Unique name generation for all `RagEngine` modules.

### Changed
- **BREAKING**: Removed all uses of `EventPublisherMixin` in favor of `event_bus`.
- **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 `BaseStructureConfig.merge_config`.
- **BREAKING**: Renamed `StructureConfig` to `DriverConfig`, 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`.
- Engines that previously required Drivers now pull from `griptape.config.config.drivers` by default.
- `BaseTask.add_parent/child` will now call `self.structure.add_task` if possible.

## [0.29.1] - 2024-08-02
Expand Down
10 changes: 4 additions & 6 deletions docs/examples/src/multiple_agent_shared_memory_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from griptape.config import AzureOpenAiStructureConfig
from griptape.config import AzureOpenAiDriverConfig, config
from griptape.drivers import AzureMongoDbVectorStoreDriver, AzureOpenAiEmbeddingDriver
from griptape.structures import Agent
from griptape.tools import TaskMemoryClient, WebScraper
Expand Down Expand Up @@ -33,25 +33,23 @@
vector_path=MONGODB_VECTOR_PATH,
)

config = AzureOpenAiStructureConfig(
config.drivers = AzureOpenAiDriverConfig(
azure_endpoint=AZURE_OPENAI_ENDPOINT_1,
vector_store_driver=mongo_driver,
embedding_driver=embedding_driver,
vector_store=mongo_driver,
embedding=embedding_driver,
)

loader = Agent(
tools=[
WebScraper(off_prompt=True),
],
config=config,
)
asker = Agent(
tools=[
TaskMemoryClient(off_prompt=False),
],
meta_memory=loader.meta_memory,
task_memory=loader.task_memory,
config=config,
)

if __name__ == "__main__":
Expand Down
7 changes: 4 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,9 +3,11 @@
import google.generativeai as genai

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

config.drivers = GoogleDriverConfig()

video_file = genai.upload_file(path="tests/resources/griptape-comfyui.mp4")
while video_file.state.name == "PROCESSING":
time.sleep(2)
Expand All @@ -15,11 +17,10 @@
raise ValueError(video_file.state.name)

agent = Agent(
config=GoogleStructureConfig(),
input=[
GenericArtifact(video_file),
TextArtifact("Answer this question regarding the video: {{ args[0] }}"),
],
]
)

agent.run("Are there any scenes that show a character with earings?")
Expand Down
2 changes: 1 addition & 1 deletion docs/griptape-framework/drivers/embedding-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The [CohereEmbeddingDriver](../../reference/griptape/drivers/embedding/cohere_em
```

### Override Default Structure Embedding Driver
Here is how you can override the Embedding Driver that is used by default in Structures.
Here is how you can override the Embedding Driver that is used by default in Structures.

```python
--8<-- "docs/griptape-framework/drivers/src/embedding_drivers_10.py"
Expand Down
1 change: 0 additions & 1 deletion docs/griptape-framework/drivers/prompt-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ The [AmazonSageMakerJumpstartPromptDriver](../../reference/griptape/drivers/prom
Amazon Sagemaker Jumpstart provides a wide range of models with varying capabilities.
This Driver has been primarily _chat-optimized_ models that have a [Huggingface Chat Template](https://huggingface.co/docs/transformers/en/chat_templating) available.
If your model does not fit this use-case, we suggest sub-classing [AmazonSageMakerJumpstartPromptDriver](../../reference/griptape/drivers/prompt/amazon_sagemaker_jumpstart_prompt_driver.md) and overriding the `_to_model_input` and `_to_model_params` methods.


```python
--8<-- "docs/griptape-framework/drivers/src/prompt_drivers_14.py"
Expand Down
11 changes: 6 additions & 5 deletions docs/griptape-framework/drivers/src/embedding_drivers_10.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from griptape.config import StructureConfig
from griptape.config import DriverConfig, config
from griptape.drivers import (
OpenAiChatPromptDriver,
VoyageAiEmbeddingDriver,
)
from griptape.structures import Agent
from griptape.tools import TaskMemoryClient, WebScraper

config.drivers = DriverConfig(
prompt=OpenAiChatPromptDriver(model="gpt-4o"),
embedding=VoyageAiEmbeddingDriver(),
)

agent = Agent(
tools=[WebScraper(off_prompt=True), TaskMemoryClient(off_prompt=False)],
config=StructureConfig(
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"),
embedding_driver=VoyageAiEmbeddingDriver(),
),
)

agent.run("based on https://www.griptape.ai/, tell me what Griptape is")
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os

from griptape.config import StructureConfig
from griptape.config import DriverConfig, config
from griptape.drivers import AwsIotCoreEventListenerDriver, OpenAiChatPromptDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.rules import Rule
from griptape.structures import Agent

config.drivers = DriverConfig(prompt=OpenAiChatPromptDriver(model="gpt-3.5-turbo", temperature=0.7))
event_bus.add_event_listeners(
[
EventListener(
Expand All @@ -20,7 +21,6 @@

agent = Agent(
rules=[Rule(value="You will be provided with a text, and your task is to extract the airport codes from it.")],
config=StructureConfig(prompt_driver=OpenAiChatPromptDriver(model="gpt-3.5-turbo", temperature=0.7)),
)

agent.run("I want to fly from Orlando to Boston")
5 changes: 1 addition & 4 deletions docs/griptape-framework/drivers/src/prompt_drivers_1.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from griptape.config import StructureConfig
from griptape.drivers import OpenAiChatPromptDriver
from griptape.rules import Rule
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", temperature=0.3),
),
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", temperature=0.3),
input="You will be provided with a tweet, and your task is to classify its sentiment as positive, neutral, or negative. Tweet: {{ args[0] }}",
rules=[Rule(value="Output only the sentiment.")],
)
Expand Down
7 changes: 2 additions & 5 deletions docs/griptape-framework/drivers/src/prompt_drivers_10.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from griptape.config import StructureConfig
from griptape.drivers import OllamaPromptDriver
from griptape.structures import Agent
from griptape.tools import Calculator

agent = Agent(
config=StructureConfig(
prompt_driver=OllamaPromptDriver(
model="llama3.1",
),
prompt_driver=OllamaPromptDriver(
model="llama3.1",
),
tools=[Calculator()],
)
Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_11.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import HuggingFaceHubPromptDriver
from griptape.rules import Rule, Ruleset
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=HuggingFaceHubPromptDriver(
model="HuggingFaceH4/zephyr-7b-beta",
api_token=os.environ["HUGGINGFACE_HUB_ACCESS_TOKEN"],
)
prompt_driver=HuggingFaceHubPromptDriver(
model="HuggingFaceH4/zephyr-7b-beta",
api_token=os.environ["HUGGINGFACE_HUB_ACCESS_TOKEN"],
),
rulesets=[
Ruleset(
Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_12.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import HuggingFaceHubPromptDriver
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=HuggingFaceHubPromptDriver(
model="http://127.0.0.1:8080",
api_token=os.environ["HUGGINGFACE_HUB_ACCESS_TOKEN"],
),
prompt_driver=HuggingFaceHubPromptDriver(
model="http://127.0.0.1:8080",
api_token=os.environ["HUGGINGFACE_HUB_ACCESS_TOKEN"],
),
)

Expand Down
7 changes: 2 additions & 5 deletions docs/griptape-framework/drivers/src/prompt_drivers_13.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from griptape.config import StructureConfig
from griptape.drivers import HuggingFacePipelinePromptDriver
from griptape.rules import Rule, Ruleset
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=HuggingFacePipelinePromptDriver(
model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
)
prompt_driver=HuggingFacePipelinePromptDriver(
model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
),
rulesets=[
Ruleset(
Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_14.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import (
AmazonSageMakerJumpstartPromptDriver,
)
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=AmazonSageMakerJumpstartPromptDriver(
endpoint=os.environ["SAGEMAKER_LLAMA_3_INSTRUCT_ENDPOINT_NAME"],
model="meta-llama/Meta-Llama-3-8B-Instruct",
)
prompt_driver=AmazonSageMakerJumpstartPromptDriver(
endpoint=os.environ["SAGEMAKER_LLAMA_3_INSTRUCT_ENDPOINT_NAME"],
model="meta-llama/Meta-Llama-3-8B-Instruct",
)
)

Expand Down
15 changes: 6 additions & 9 deletions docs/griptape-framework/drivers/src/prompt_drivers_3.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import OpenAiChatPromptDriver
from griptape.rules import Rule
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=OpenAiChatPromptDriver(
api_key=os.environ["OPENAI_API_KEY"],
temperature=0.1,
model="gpt-4o",
response_format="json_object",
seed=42,
)
prompt_driver=OpenAiChatPromptDriver(
api_key=os.environ["OPENAI_API_KEY"],
temperature=0.1,
model="gpt-4o",
response_format="json_object",
seed=42,
),
input="You will be provided with a description of a mood, and your task is to generate the CSS code for a color that matches it. Description: {{ args[0] }}",
rules=[Rule(value='Write your output in json with a single key called "css_code".')],
Expand Down
7 changes: 2 additions & 5 deletions docs/griptape-framework/drivers/src/prompt_drivers_4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from griptape.config import StructureConfig
from griptape.drivers import OpenAiChatPromptDriver
from griptape.rules import Rule
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=OpenAiChatPromptDriver(
base_url="http://127.0.0.1:1234/v1", model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF", stream=True
)
prompt_driver=OpenAiChatPromptDriver(
base_url="http://127.0.0.1:1234/v1", model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF", stream=True
),
rules=[Rule(value="You are a helpful coding assistant.")],
)
Expand Down
13 changes: 5 additions & 8 deletions docs/griptape-framework/drivers/src/prompt_drivers_5.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import AzureOpenAiChatPromptDriver
from griptape.rules import Rule
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=AzureOpenAiChatPromptDriver(
api_key=os.environ["AZURE_OPENAI_API_KEY_1"],
model="gpt-3.5-turbo",
azure_deployment=os.environ["AZURE_OPENAI_35_TURBO_DEPLOYMENT_ID"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT_1"],
)
prompt_driver=AzureOpenAiChatPromptDriver(
api_key=os.environ["AZURE_OPENAI_API_KEY_1"],
model="gpt-3.5-turbo",
azure_deployment=os.environ["AZURE_OPENAI_35_TURBO_DEPLOYMENT_ID"],
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT_1"],
),
rules=[
Rule(
Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_6.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import CoherePromptDriver
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=CoherePromptDriver(
model="command-r",
api_key=os.environ["COHERE_API_KEY"],
)
prompt_driver=CoherePromptDriver(
model="command-r",
api_key=os.environ["COHERE_API_KEY"],
)
)

Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_7.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import AnthropicPromptDriver
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=AnthropicPromptDriver(
model="claude-3-opus-20240229",
api_key=os.environ["ANTHROPIC_API_KEY"],
)
prompt_driver=AnthropicPromptDriver(
model="claude-3-opus-20240229",
api_key=os.environ["ANTHROPIC_API_KEY"],
)
)

Expand Down
9 changes: 3 additions & 6 deletions docs/griptape-framework/drivers/src/prompt_drivers_8.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os

from griptape.config import StructureConfig
from griptape.drivers import GooglePromptDriver
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=GooglePromptDriver(
model="gemini-pro",
api_key=os.environ["GOOGLE_API_KEY"],
)
prompt_driver=GooglePromptDriver(
model="gemini-pro",
api_key=os.environ["GOOGLE_API_KEY"],
)
)

Expand Down
7 changes: 2 additions & 5 deletions docs/griptape-framework/drivers/src/prompt_drivers_9.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from griptape.config import StructureConfig
from griptape.drivers import AmazonBedrockPromptDriver
from griptape.rules import Rule
from griptape.structures import Agent

agent = Agent(
config=StructureConfig(
prompt_driver=AmazonBedrockPromptDriver(
model="anthropic.claude-3-sonnet-20240229-v1:0",
)
prompt_driver=AmazonBedrockPromptDriver(
model="anthropic.claude-3-sonnet-20240229-v1:0",
),
rules=[
Rule(
Expand Down
Loading

0 comments on commit e600334

Please sign in to comment.