PhoenixAI.Pipeline (PhoenixAI v0.1.0)

Copy Markdown View Source

Sequential railway pipeline.

Steps execute in order. Each step receives the previous step's unwrapped {:ok, value} result. The pipeline halts on the first {:error, reason}.

Ad-hoc usage

Pipeline.run([
  fn query -> AI.chat([msg(query)], provider: :openai) end,
  fn %Response{content: text} -> String.upcase(text) end
], "Hello")

DSL usage

defmodule MyPipeline do
  use PhoenixAI.Pipeline

  step :search do
    fn query -> AI.chat([msg(query)], provider: :openai) end
  end
end

MyPipeline.run("Hello")

Summary

Functions

Executes a list of step functions sequentially.

Defines a named step in a pipeline module.

Types

step()

@type step() :: (term() -> {:ok, term()} | {:error, term()} | term())

Functions

run(steps, input, opts \\ [])

@spec run([step()], term(), keyword()) :: {:ok, term()} | {:error, term()}

Executes a list of step functions sequentially.

Each step receives the unwrapped value from the previous step's {:ok, value}. Halts on first {:error, reason}. Raw (non-tuple) returns are auto-wrapped in {:ok, value}.

step(name, list)

(macro)

Defines a named step in a pipeline module.

The block must return a function fn input -> {:ok, result} | {:error, reason} | term() end.