Oi.Step (oi v0.1.0)

Copy Markdown

轻量级声明式语法层,在 Orchid.Step / OrchidSymbiont.Step 之上提供简易 API,并产出 __node_spec__/0 供 topology 集成。

Pure step

defmodule MyApp.Steps.Upcase do
  use Oi.Step, name: :upcase

  manifest(
    inputs: [:text],
    outputs: [result: :string]
  )

  routine text, opts do
    report(opts, 100, "Reached!")
    text |> String.upcase() |> ok()
  end
end

Symbiont step

defmodule MyApp.Steps.Predict do
  use Oi.Step, name: :predict, symbiont?: true

  manifest(
    inputs: [:features],
    outputs: [prediction: :tensor],
    models: [:encoder, :predictor],
    heavy?: true
  )

  routine features, models, opts do
    {:ok, {enc}} = OrchidSymbiont.call(models.encoder, {:infer, features})
    ok(enc)
  end
end

ok / err — Rust 风格结果构造器

routine text, opts do
  case validate(text) do
    {:ok, v}    -> ok(v)
    {:error, e} -> err(e)
  end
end
  • 单输出:ok(value){:ok, %Orchid.Param{}}
  • 多输出:ok({a, b}) / ok([a, b]){:ok, [%Param{}, %Param{}]}

Summary

Functions

将 reason 包装为 {:error, reason}

声明 step 元数据,必须在 routine 之前调用。

将值包装为 {:ok, Param | [Param]}

定义执行逻辑,展开为 run/2 (pure) 或 run_with_model/3 (symbiont)。

Functions

err(reason)

将 reason 包装为 {:error, reason}

manifest(opts)

(macro)

声明 step 元数据,必须在 routine 之前调用。

  • :inputs — 输入端口名列表 (atoms)
  • :outputs — keyword list,port_name => param_type
  • :models — symbiont step 的 model 名列表(symbiont? 时必填)
  • :heavy? — boolean,默认 false

ok(value)

(macro)

将值包装为 {:ok, Param | [Param]}

routine(input, opts_var, list)

(macro)

定义执行逻辑,展开为 run/2 (pure) 或 run_with_model/3 (symbiont)。

自动解包输入 Param:

  • 单输入 routine text, opts → payload 直接绑定
  • 多输入 routine [a, b], opts → list 解包
  • 多输入 routine {a, b}, opts → tuple 解包

symbiont 的 models 绑定到 handler map(models.encoder 等)。

routine(input, models_var, opts_var, list)

(macro)