Skip to content

Commit a141d6c

Browse files
Add RunContext to doc and improve protocol description (neo4j#320)
* Add RunContext to doc and improve protocol description * Ruff * Rename for clarity * Add RunContext to doc and improve protocol description * Ruff * Rename for clarity * Update docs/source/types.rst Co-authored-by: Alex Thomas <alexthomas93@users.noreply.github.com> --------- Co-authored-by: Alex Thomas <alexthomas93@users.noreply.github.com>
1 parent fd169f2 commit a141d6c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docs/source/types.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,16 @@ EventCallbackProtocol
177177

178178
.. autoclass:: neo4j_graphrag.experimental.pipeline.notification.EventCallbackProtocol
179179
:members: __call__
180+
181+
182+
TaskProgressCallbackProtocol
183+
============================
184+
185+
.. autoclass:: neo4j_graphrag.experimental.pipeline.types.context.TaskProgressNotifierProtocol
186+
:members: __call__
187+
188+
189+
RunContext
190+
==========
191+
192+
.. autoclass:: neo4j_graphrag.experimental.pipeline.types.context.RunContext

src/neo4j_graphrag/experimental/pipeline/notification.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class TaskEvent(Event):
7474

7575

7676
class EventCallbackProtocol(Protocol):
77+
"""This protocol is used to send events about pipeline progress
78+
from the pipeline itself. It will receive either PipelineEvent or
79+
TaskEvent depending on the event type.
80+
"""
81+
7782
def __call__(self, event: Event) -> Awaitable[None]: ...
7883

7984

src/neo4j_graphrag/experimental/pipeline/types/context.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020

2121
@runtime_checkable
22-
class TaskProgressCallbackProtocol(Protocol):
22+
class TaskProgressNotifierProtocol(Protocol):
23+
"""This protocol is used to send events from the component to the
24+
Pipeline callback protocol.
25+
The event sent to the callback will be of type :ref:`TaskEvent`,
26+
with `event_type=TASK_PROGRESS`.
27+
"""
28+
2329
def __call__(self, message: str, data: dict[str, Any]) -> Awaitable[None]: ...
2430

2531

@@ -28,7 +34,7 @@ class RunContext(BaseModel):
2834

2935
run_id: str
3036
task_name: str
31-
notifier: Optional[TaskProgressCallbackProtocol] = None
37+
notifier: Optional[TaskProgressNotifierProtocol] = None
3238

3339
model_config = ConfigDict(arbitrary_types_allowed=True)
3440

0 commit comments

Comments
 (0)