|
|
|
@ -162,6 +162,12 @@ class Runnable(Generic[Input, Output], ABC):
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
"""The type of input this runnable accepts specified as a pydantic model."""
|
|
|
|
|
return self.get_input_schema()
|
|
|
|
|
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
"""The type of input this runnable accepts specified as a pydantic model."""
|
|
|
|
|
root_type = self.InputType
|
|
|
|
|
|
|
|
|
@ -174,6 +180,12 @@ class Runnable(Generic[Input, Output], ABC):
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def output_schema(self) -> Type[BaseModel]:
|
|
|
|
|
"""The type of output this runnable produces specified as a pydantic model."""
|
|
|
|
|
return self.get_output_schema()
|
|
|
|
|
|
|
|
|
|
def get_output_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
"""The type of output this runnable produces specified as a pydantic model."""
|
|
|
|
|
root_type = self.OutputType
|
|
|
|
|
|
|
|
|
@ -1044,13 +1056,15 @@ class RunnableSequence(RunnableSerializable[Input, Output]):
|
|
|
|
|
def OutputType(self) -> Type[Output]:
|
|
|
|
|
return self.last.OutputType
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
return self.first.input_schema
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
return self.first.get_input_schema(config)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def output_schema(self) -> Type[BaseModel]:
|
|
|
|
|
return self.last.output_schema
|
|
|
|
|
def get_output_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
return self.last.get_output_schema(config)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
|
|
|
@ -1551,10 +1565,11 @@ class RunnableParallel(RunnableSerializable[Input, Dict[str, Any]]):
|
|
|
|
|
|
|
|
|
|
return Any
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
if all(
|
|
|
|
|
s.input_schema.schema().get("type", "object") == "object"
|
|
|
|
|
s.get_input_schema(config).schema().get("type", "object") == "object"
|
|
|
|
|
for s in self.steps.values()
|
|
|
|
|
):
|
|
|
|
|
# This is correct, but pydantic typings/mypy don't think so.
|
|
|
|
@ -1563,15 +1578,16 @@ class RunnableParallel(RunnableSerializable[Input, Dict[str, Any]]):
|
|
|
|
|
**{
|
|
|
|
|
k: (v.annotation, v.default)
|
|
|
|
|
for step in self.steps.values()
|
|
|
|
|
for k, v in step.input_schema.__fields__.items()
|
|
|
|
|
for k, v in step.get_input_schema(config).__fields__.items()
|
|
|
|
|
if k != "__root__"
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return super().input_schema
|
|
|
|
|
return super().get_input_schema(config)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def output_schema(self) -> Type[BaseModel]:
|
|
|
|
|
def get_output_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
# This is correct, but pydantic typings/mypy don't think so.
|
|
|
|
|
return create_model( # type: ignore[call-overload]
|
|
|
|
|
"RunnableParallelOutput",
|
|
|
|
@ -2040,8 +2056,9 @@ class RunnableLambda(Runnable[Input, Output]):
|
|
|
|
|
except ValueError:
|
|
|
|
|
return Any
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
"""The pydantic schema for the input to this runnable."""
|
|
|
|
|
func = getattr(self, "func", None) or getattr(self, "afunc")
|
|
|
|
|
|
|
|
|
@ -2066,7 +2083,7 @@ class RunnableLambda(Runnable[Input, Output]):
|
|
|
|
|
**{key: (Any, None) for key in dict_keys}, # type: ignore
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return super().input_schema
|
|
|
|
|
return super().get_input_schema(config)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def OutputType(self) -> Any:
|
|
|
|
@ -2215,12 +2232,13 @@ class RunnableEach(RunnableSerializable[List[Input], List[Output]]):
|
|
|
|
|
def InputType(self) -> Any:
|
|
|
|
|
return List[self.bound.InputType] # type: ignore[name-defined]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
return create_model(
|
|
|
|
|
"RunnableEachInput",
|
|
|
|
|
__root__=(
|
|
|
|
|
List[self.bound.input_schema], # type: ignore[name-defined]
|
|
|
|
|
List[self.bound.get_input_schema(config)], # type: ignore
|
|
|
|
|
None,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
@ -2229,12 +2247,14 @@ class RunnableEach(RunnableSerializable[List[Input], List[Output]]):
|
|
|
|
|
def OutputType(self) -> Type[List[Output]]:
|
|
|
|
|
return List[self.bound.OutputType] # type: ignore[name-defined]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def output_schema(self) -> Type[BaseModel]:
|
|
|
|
|
def get_output_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
schema = self.bound.get_output_schema(config)
|
|
|
|
|
return create_model(
|
|
|
|
|
"RunnableEachOutput",
|
|
|
|
|
__root__=(
|
|
|
|
|
List[self.bound.output_schema], # type: ignore[name-defined]
|
|
|
|
|
List[schema], # type: ignore
|
|
|
|
|
None,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
@ -2332,13 +2352,15 @@ class RunnableBinding(RunnableSerializable[Input, Output]):
|
|
|
|
|
def OutputType(self) -> Type[Output]:
|
|
|
|
|
return self.bound.OutputType
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def input_schema(self) -> Type[BaseModel]:
|
|
|
|
|
return self.bound.input_schema
|
|
|
|
|
def get_input_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
return self.bound.get_input_schema(merge_configs(self.config, config))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def output_schema(self) -> Type[BaseModel]:
|
|
|
|
|
return self.bound.output_schema
|
|
|
|
|
def get_output_schema(
|
|
|
|
|
self, config: Optional[RunnableConfig] = None
|
|
|
|
|
) -> Type[BaseModel]:
|
|
|
|
|
return self.bound.get_output_schema(merge_configs(self.config, config))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
|
|
|
|