gleamunison/cli_llm

gleamunison llm — the LLM ability reachable from the shipped binary.

Env lookup and the op handler are both injected, so the live provider, a retry-wrapped provider, and a test mock are the same function call. That swap is the entire point of the ability design.

Types

pub type EnvLookup =
  fn(String) -> Result(String, Nil)

Values

pub fn command(args: List(String)) -> String

CLI entry: gleam run -- llm [openai|anthropic] <prompt>.

pub fn command_with_env(
  args: List(String),
  env: fn(String) -> Result(String, Nil),
) -> String
pub fn command_with_handler(
  args: List(String),
  env: fn(String) -> Result(String, Nil),
  handler: fn(
    List(dynamic.Dynamic),
    fn(dynamic.Dynamic) -> dynamic.Dynamic,
  ) -> dynamic.Dynamic,
) -> String

Test seam: same pipeline with the handler swapped in.

pub fn complete_with(
  handler: fn(
    List(dynamic.Dynamic),
    fn(dynamic.Dynamic) -> dynamic.Dynamic,
  ) -> dynamic.Dynamic,
  prompt: String,
) -> Result(llm.Completion, String)

Drive any LLM op handler with a single user prompt. The handler decides what that means — live HTTP, retry, mock; this function only moves data.

pub fn default_provider(
  env: fn(String) -> Result(String, Nil),
) -> llm.Provider

Which provider to call when the user did not say: Anthropic if its key exists, else OpenAI.

pub fn resolve_config(
  provider: llm.Provider,
  env: fn(String) -> Result(String, Nil),
) -> Result(llm.ProviderConfig, String)

Provider config from the environment, with sane defaults.

✨ Search Document