Skip to content

Commit

Permalink
Run stream thread using with_contextvars
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Dec 16, 2024
1 parent 9aaceaa commit d45cdbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `StructureVisualizer.base_url` for setting the base URL on the url generated by `StructureVisualizer.to_url()`.
- `StructureVisualizer.query_params` for setting query parameters on the url generated by `StructureVisualizer.to_url()`.
- Parsing `ActionCallDeltaMessageContent`s with empty string `partial_input`s.
- `Stream` util not properly propagating thread contextvars.

## [1.0.0] - 2024-12-09

Expand Down
3 changes: 2 additions & 1 deletion griptape/utils/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FinishStructureRunEvent,
TextChunkEvent,
)
from griptape.utils.contextvars_utils import with_contextvars

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down Expand Up @@ -44,7 +45,7 @@ class Stream:
_event_queue: Queue[BaseEvent] = field(default=Factory(lambda: Queue()))

def run(self, *args) -> Iterator[TextArtifact]:
t = Thread(target=self._run_structure, args=args)
t = Thread(target=with_contextvars(self._run_structure), args=args)
t.start()

action_str = ""
Expand Down

0 comments on commit d45cdbe

Please sign in to comment.