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 1 commit
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
7 changes: 5 additions & 2 deletions griptape/utils/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
)

def default_output_fn(self, text: str) -> None:
from griptape.config import config
from griptape.tasks.prompt_task import PromptTask

Check warning on line 28 in griptape/utils/chat.py

View check run for this annotation

Codecov / codecov/patch

griptape/utils/chat.py#L28

Added line #L28 was not covered by tests

if config.drivers.prompt.stream:
streaming_tasks = [
task for task in self.structure.tasks if isinstance(task, PromptTask) and task.prompt_driver.stream
]
if streaming_tasks:
print(text, end="", flush=True) # noqa: T201
else:
print(text) # noqa: T201

def start(self) -> None:
from griptape.config import config

Check warning on line 39 in griptape/utils/chat.py

View check run for this annotation

Codecov / codecov/patch

griptape/utils/chat.py#L39

Added line #L39 was not covered by tests

if self.intro_text:
self.output_fn(self.intro_text)
Expand Down
9 changes: 6 additions & 3 deletions griptape/utils/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ class Stream:

@structure.validator # pyright: ignore[reportAttributeAccessIssue]
def validate_structure(self, _: Attribute, structure: Structure) -> None:
from griptape.config import config
from griptape.tasks import PromptTask

if not config.drivers.prompt.stream:
raise ValueError("prompt driver does not have streaming enabled, enable with stream=True")
streaming_tasks = [
task for task in structure.tasks if isinstance(task, PromptTask) and task.prompt_driver.stream
]
if not streaming_tasks:
raise ValueError("Structure does not have any streaming tasks, enable with stream=True")
vachillo marked this conversation as resolved.
Show resolved Hide resolved

_event_queue: Queue[BaseEvent] = field(default=Factory(lambda: Queue()))

Expand Down
14 changes: 9 additions & 5 deletions tests/unit/utils/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import pytest

from griptape.config import config
from griptape.structures import Agent
from griptape.structures import Agent, Pipeline
from griptape.utils import Stream


class TestStream:
@pytest.fixture(params=[True, False])
def agent(self, request):
config.drivers.prompt.stream = request.param
return Agent()
return Agent(stream=request.param)

def test_init(self, agent):
if config.drivers.prompt.stream:
if agent.stream:
chat_stream = Stream(agent)

assert chat_stream.structure == agent
Expand All @@ -29,3 +27,9 @@ def test_init(self, agent):
else:
with pytest.raises(ValueError):
Stream(agent)

def test_validate_structure_invalid(self):
pipeline = Pipeline(tasks=[])

with pytest.raises(ValueError):
Stream(pipeline)
Loading