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

Global Config #1045

Merged
merged 46 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
adf4836
Add global event bus
collindutter Aug 7, 2024
ae20c82
WIP
collindutter Aug 6, 2024
44f9ebd
WIP
collindutter Aug 6, 2024
6b76237
Fix tests
collindutter Aug 6, 2024
e8c1fff
Namespace config
collindutter Aug 6, 2024
514665f
Rename driver config fields
collindutter Aug 6, 2024
ef24d49
Revert changelog update
collindutter Aug 6, 2024
ab65783
Rename Structure Config to Driver Config
collindutter Aug 6, 2024
ecfa358
Rename doc fields
collindutter Aug 6, 2024
582f55c
Move events into config
collindutter Aug 6, 2024
e80f78e
Add back util fields for Agent
collindutter Aug 6, 2024
91619a5
Revert changelog replaces
collindutter Aug 6, 2024
9ebd44e
Fix type
collindutter Aug 6, 2024
b7e1359
Revert some of agent test
collindutter Aug 6, 2024
97564a2
Add logging module to config
collindutter Aug 7, 2024
4220e0f
Fix bad rebase
collindutter Aug 7, 2024
f8a616f
Update docs
collindutter Aug 8, 2024
95d83b5
Add global event bus
collindutter Aug 7, 2024
951a4ed
Update docs
collindutter Aug 8, 2024
025437b
Make event listeners private
collindutter Aug 8, 2024
0f19385
Rename EventBus to event_bus
collindutter Aug 8, 2024
729f3aa
Fix doc
collindutter Aug 8, 2024
c391b14
Fix test
collindutter Aug 8, 2024
7baefac
Rename event bus
collindutter Aug 8, 2024
98fa12d
Merge branch 'feature/event-bus' into refactor/global-config
collindutter Aug 8, 2024
feec94b
Rename Config to config, fix tests
collindutter Aug 8, 2024
13969c3
Fix doc
collindutter Aug 8, 2024
f5c42e8
Update changelog
collindutter Aug 8, 2024
dd23d89
Add global event bus
collindutter Aug 7, 2024
39f75c4
Update docs
collindutter Aug 8, 2024
8a97313
Make event listeners private
collindutter Aug 8, 2024
0e1d019
Rename EventBus to event_bus
collindutter Aug 8, 2024
4d491c2
Fix doc
collindutter Aug 8, 2024
863bcde
Fix test
collindutter Aug 8, 2024
c173f49
Merge branch 'feature/event-bus' into refactor/global-config
collindutter Aug 8, 2024
12efa67
Fix doc
collindutter Aug 8, 2024
0d5ce93
Update changelog
collindutter Aug 8, 2024
5fbb1b1
Merge branch 'dev' into refactor/global-config
collindutter Aug 8, 2024
daa1710
Update changelog
collindutter Aug 8, 2024
8962648
Merge branch 'dev' into refactor/global-config
collindutter Aug 9, 2024
11f9ac8
Fix type errors
collindutter Aug 9, 2024
952e07f
Merge branch 'dev' into refactor/global-config
collindutter Aug 12, 2024
f3c908d
Merge branch 'dev' into refactor/global-config
collindutter Aug 12, 2024
d0fab25
Fix utilities checking for stream
collindutter Aug 12, 2024
1ff7e88
Clean up example
collindutter Aug 13, 2024
d179821
Default stream to config value
collindutter Aug 13, 2024
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
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's special about Agent.prompt_driver ?

Copy link
Member Author

Choose a reason for hiding this comment

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

From the PR description:

Note that Agent.prompt_driver and Agent.stream were kept since the purpose of an Agent is to provide a syntactically concise way to create a Structure with either a PromptTask/ToolkitTask. These fields felt consistent with the other helper field: Agent.tools.

Let me know if this is not a sufficient explanation, happy to go into more detail.

- **BREAKING**: Removed `Pipeline.stream` and `Workflow.stream`. `Agent.stream` has not been removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's special about Agent.stream?

Copy link
Member Author

Choose a reason for hiding this comment

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

Replied above.

- **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"
Comment on lines -131 to 134
Copy link
Contributor

Choose a reason for hiding this comment

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

Separating the snippets from the docs makes proof reading more difficult

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, but the type checking/linting was essential during development.

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
Loading