add the thing formally
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user