add the thing formally
This commit is contained in:
@@ -43,10 +43,12 @@ from .nodes import (
|
||||
AsyncRegistryHandler,
|
||||
NodeReturn,
|
||||
NodeSpec,
|
||||
Nothing,
|
||||
SyncRegistryHandler,
|
||||
build_async_registry,
|
||||
build_registry,
|
||||
node,
|
||||
outcome,
|
||||
)
|
||||
from .schemas import StateFieldMetadata, state_field
|
||||
from .subgraph import subgraph_node
|
||||
@@ -64,6 +66,7 @@ __all__ = [
|
||||
"PickKeyInput",
|
||||
"NodeReturn",
|
||||
"NodeSpec",
|
||||
"Nothing",
|
||||
"AsyncRegistryHandler",
|
||||
"SyncRegistryHandler",
|
||||
"SequenceInput",
|
||||
@@ -95,6 +98,7 @@ __all__ = [
|
||||
"length",
|
||||
"pick_key",
|
||||
"node",
|
||||
"outcome",
|
||||
"state",
|
||||
"state_field",
|
||||
"state_path",
|
||||
|
||||
@@ -13,7 +13,7 @@ from .callables import (
|
||||
from .inference import accepts_context, infer_models, is_basemodel_subclass
|
||||
from .decorator import node
|
||||
from .registry import build_async_registry, build_registry
|
||||
from .result import NodeReturn
|
||||
from .result import NodeReturn, Nothing, outcome
|
||||
from .schema import schema_ref_for
|
||||
from .spec import NodeSpec
|
||||
|
||||
@@ -27,6 +27,7 @@ __all__ = [
|
||||
"NodeCallable",
|
||||
"NodeReturn",
|
||||
"NodeSpec",
|
||||
"Nothing",
|
||||
"OutputT",
|
||||
"PlainNodeCallable",
|
||||
"SyncRegistryHandler",
|
||||
@@ -36,5 +37,6 @@ __all__ = [
|
||||
"infer_models",
|
||||
"is_basemodel_subclass",
|
||||
"node",
|
||||
"outcome",
|
||||
"schema_ref_for",
|
||||
]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Generic, TypeVar
|
||||
from typing import Generic, TypeVar, overload
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -14,3 +14,25 @@ class NodeReturn(Generic[OutputT_co]):
|
||||
|
||||
outcome: str
|
||||
output: OutputT_co
|
||||
|
||||
|
||||
class Nothing(BaseModel):
|
||||
"""Empty output model for nodes that only choose an outcome."""
|
||||
|
||||
|
||||
@overload
|
||||
def outcome(name: str) -> NodeReturn[Nothing]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def outcome(name: str, output: OutputT_co) -> NodeReturn[OutputT_co]: ...
|
||||
|
||||
|
||||
def outcome(
|
||||
name: str,
|
||||
output: OutputT_co | None = None,
|
||||
) -> NodeReturn[OutputT_co] | NodeReturn[Nothing]:
|
||||
"""Create a node result with an optional output model."""
|
||||
if output is None:
|
||||
return NodeReturn(outcome=name, output=Nothing())
|
||||
return NodeReturn(outcome=name, output=output)
|
||||
|
||||
@@ -8,12 +8,14 @@ from .nodes import (
|
||||
NodeCallable,
|
||||
NodeReturn,
|
||||
NodeSpec,
|
||||
Nothing,
|
||||
OutputT,
|
||||
PlainNodeCallable,
|
||||
SyncRegistryHandler,
|
||||
build_async_registry,
|
||||
build_registry,
|
||||
node,
|
||||
outcome,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -26,10 +28,12 @@ __all__ = [
|
||||
"NodeCallable",
|
||||
"NodeReturn",
|
||||
"NodeSpec",
|
||||
"Nothing",
|
||||
"OutputT",
|
||||
"PlainNodeCallable",
|
||||
"SyncRegistryHandler",
|
||||
"build_async_registry",
|
||||
"build_registry",
|
||||
"node",
|
||||
"outcome",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user