API reference

Entry point for the ai-python sample application.

main.main() None[source]

Print a greeting to stdout.

lcel — minimal Runnable / |

Minimal LCEL-style composition: Runnable steps wired with the pipe operator |.

This is a tiny re-implementation of the idea behind LangChain Expression Language—no langchain dependency. Enough to express linear chains, assign on dict state, and parallel fan-out that merges back in a later step.

class lcel.Runnable[source]

Bases: ABC

One step in a pipeline: call invoke; use a | b to chain.

abstractmethod invoke(input: Any) Any[source]

Execute this step and return its output.

class lcel.RunnableAssign(getters: Mapping[str, Callable[[Any], Any]])[source]

Bases: Runnable

{**input, k: fn(input)} for each configured k.

invoke(input: Any) Any[source]

Execute this step and return its output.

class lcel.RunnableLambda(func: Callable[[Any], Any])[source]

Bases: Runnable

Wrap any single-argument callable as a Runnable.

invoke(input: Any) Any[source]

Execute this step and return its output.

class lcel.RunnableParallel(**branches: Runnable | Callable[[Any], Any])[source]

Bases: Runnable

Run several runnables on the same input; output is {branch_name: branch_output}.

invoke(input: Any) Any[source]

Execute this step and return its output.

class lcel.RunnablePassthrough[source]

Bases: Runnable

Identity step. assign builds a step that augments mapping inputs.

classmethod assign(**kwargs: Callable[[Any], Any]) RunnableAssign[source]

Each keyword becomes a new key; values are fn(input) (input is the full mapping).

invoke(input: Any) Any[source]

Execute this step and return its output.

class lcel.RunnableSequence(left: Runnable, right: Runnable)[source]

Bases: Runnable

Result of left | right: run left, pass output into right.

invoke(input: Any) Any[source]

Execute this step and return its output.

demo — runnable demos

演示自建 lcel 模块中的 Runnable 与管道操作符(竖线 |,LCEL 风格,无第三方 LangChain)。

demo.demo_dict_between_steps() None[source]

各步之间传递 dict,便于携带多个字段。

demo.demo_linear_pipe() None[source]

线性链:上游输出直接作为下游输入。

demo.demo_parallel_branches() None[source]

RunnableParallel:同一份输入并行走多路,输出 dict 再交给下游。

demo.demo_passthrough_assign() None[source]

RunnablePassthrough.assign:保留原字段并挂上派生字段。

demo.run_all() None[source]

入口:运行演示。

demo.run_lcel_demos() None[source]

运行上述管道示例。