Anu.AI (Anu v0.2.1)

Copy Markdown View Source

Cloud-powered AI helpers backed by anu_cloud.

These primitives let you classify, extract, draft, and summarize WhatsApp conversation text without managing your own LLM provider. Pair them with Anu.Message to build conversational flows in a few lines.

Client

Every function takes an %Anu.Client{} as its last argument. The client carries the cloud API key, cloud URL and Finch instance:

client =
  Anu.Client.new(
    finch: MyApp.Finch,
    cloud_api_key: System.fetch_env!("ANU_API_KEY")
  )

Example

with {:ok, %{"intent" => "support"}} <-
       Anu.AI.classify(text, [intents: ["support", "sales", "spam"]], client),
     {:ok, %{"reply" => reply}} <-
       Anu.AI.reply(text, [tone: "warm"], client) do
  from
  |> Anu.Message.new()
  |> Anu.Message.text(reply)
  |> Anu.deliver(client)
end

All functions return {:ok, decoded_map} or {:error, %Anu.Error{} | :cloud_not_configured}. Response keys are strings (decoded JSON).

Summary

Functions

Classifies text against a list of intents. Returns {intent, confidence}.

Extracts structured data from text matching the given JSON schema.

Drafts a reply to the user text.

Summarizes a list of conversation messages into a short summary.

Types

result()

@type result() :: {:ok, map()} | {:error, Anu.Error.t() | :cloud_not_configured}

Functions

classify(text, opts, client)

@spec classify(String.t(), keyword(), Anu.Client.t()) :: result()

Classifies text against a list of intents. Returns {intent, confidence}.

Options

  • :intents (required) - list of candidate intent strings.

Examples

Anu.AI.classify("I need to reset my password", [intents: ["support", "sales", "spam"]], client)
#=> {:ok, %{"intent" => "support", "confidence" => 0.93}}

extract(text, opts, client)

@spec extract(String.t(), keyword(), Anu.Client.t()) :: result()

Extracts structured data from text matching the given JSON schema.

Options

  • :schema (required) - a map describing the fields to extract.

Examples

Anu.AI.extract("My name is Ana and my order is #123", [schema: %{name: "string", order_id: "string"}], client)
#=> {:ok, %{"data" => %{"name" => "Ana", "order_id" => "123"}}}

reply(text, opts \\ [], client)

@spec reply(String.t(), keyword(), Anu.Client.t()) :: result()

Drafts a reply to the user text.

Options

  • :context - extra background to ground the reply (string)
  • :tone - e.g. "warm", "professional", "playful"

Examples

Anu.AI.reply("when does my package arrive?", [tone: "warm"], client)
#=> {:ok, %{"reply" => "Hi! Your package is on its way..."}}

summarize(messages, client)

@spec summarize([map()], Anu.Client.t()) :: result()

Summarizes a list of conversation messages into a short summary.

Examples

Anu.AI.summarize([
  %{role: "user", content: "hi"},
  %{role: "assistant", content: "hello, how can I help?"}
], client)
#=> {:ok, %{"summary" => "User said hi; we offered help."}}