chain#
- langchain_core.runnables.base.chain(
- func:Callable[[Input],Coroutine[Any,Any,Output]],
- langchain_core.runnables.base.chain(
- func:Callable[[Input],Iterator[Output]],
- langchain_core.runnables.base.chain(
- func:Callable[[Input],AsyncIterator[Output]],
- langchain_core.runnables.base.chain(
- func:Callable[[Input],Output],
Decorate a function to make it a Runnable.
Sets the name of the Runnable to the name of the function.Any runnables called by the function will be traced as dependencies.
- Parameters:
func – A callable.
- Returns:
A Runnable.
Example:
fromlangchain_core.runnablesimportchainfromlangchain_core.promptsimportPromptTemplatefromlangchain_openaiimportOpenAI@chaindefmy_func(fields):prompt=PromptTemplate("Hello,{name}!")llm=OpenAI()formatted=prompt.invoke(**fields)forchunkinllm.stream(formatted):yieldchunk
Examples using chain
On this page