Skip to content

Commit ff2e6bb

Browse files
Added preview_fn argument to LLMContextNode (#5341)
* Added preview_fn argument to LLMContextNode Signed-off-by: Elena Khaustova <ymax70rus@gmail.com> * Changed comment as suggested Signed-off-by: Elena Khaustova <ymax70rus@gmail.com> --------- Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>
1 parent c6afa49 commit ff2e6bb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kedro/pipeline/llm_context.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from ..utils import experimental
2222
from .node import Node
23+
from .preview_contract import PreviewPayload
2324

2425
T = TypeVar("T")
2526

@@ -154,6 +155,7 @@ def __init__( # noqa: PLR0913
154155
tags: str | Iterable[str] | None = None,
155156
confirms: str | list[str] | None = None,
156157
namespace: str | None = None,
158+
preview_fn: Callable[..., PreviewPayload] | None = None,
157159
):
158160
"""Create an LLMContextNode.
159161
@@ -167,6 +169,9 @@ def __init__( # noqa: PLR0913
167169
confirms: Optional name or the list of the names of the datasets
168170
that should be confirmed.
169171
namespace: Optional node namespace.
172+
preview_fn: Optional preview function that returns one of the valid
173+
preview types (TextPreview, MermaidPreview, JsonPreview, TablePreview,
174+
PlotlyPreview, ImagePreview, or CustomPreview). This is an experimental feature.
170175
"""
171176
inputs = {"llm": llm}
172177

@@ -206,7 +211,7 @@ def construct_context(llm: object, **kwargs: dict[str, Any]) -> LLMContext:
206211
tools=built_tools,
207212
)
208213

209-
# call the Node constructor with the func, inputs, outputs, name
214+
# call the Node constructor with required arguments
210215
super().__init__(
211216
func=construct_context,
212217
inputs=inputs,
@@ -215,6 +220,7 @@ def construct_context(llm: object, **kwargs: dict[str, Any]) -> LLMContext:
215220
tags=tags,
216221
confirms=confirms,
217222
namespace=namespace,
223+
preview_fn=preview_fn,
218224
)
219225

220226

@@ -229,6 +235,7 @@ def llm_context_node( # noqa: PLR0913
229235
tags: str | Iterable[str] | None = None,
230236
confirms: str | list[str] | None = None,
231237
namespace: str | None = None,
238+
preview_fn: Callable[..., PreviewPayload] | None = None,
232239
) -> Node:
233240
"""
234241
!!! warning "Experimental"
@@ -250,7 +257,9 @@ def llm_context_node( # noqa: PLR0913
250257
confirms: Optional name or the list of the names of the datasets
251258
that should be confirmed.
252259
namespace: Optional node namespace.
253-
260+
preview_fn: Optional preview function that returns one of the valid
261+
preview types (TextPreview, MermaidPreview, JsonPreview, TablePreview,
262+
PlotlyPreview, ImagePreview, or CustomPreview). This is an experimental feature.
254263
255264
Returns:
256265
A Kedro Node that loads all declared datasets, instantiates tools,
@@ -280,4 +289,5 @@ def llm_context_node( # noqa: PLR0913
280289
tags=tags,
281290
confirms=confirms,
282291
namespace=namespace,
292+
preview_fn=preview_fn,
283293
)

0 commit comments

Comments
 (0)