Zoonk.AI.AIPayload (Zoonk v0.1.0-dev)

View Source

Create AI payloads for external APIs/services.

This module allows you to build requests for AI services using a composable API.

It supports structured output via JSON Schema to ensure consistent responses.

Summary

Functions

Add instructions to the AI.

Add a message to the AI's context.

Set the AI model to use.

Set a schema.

Functions

add_instructions(ai, instructions)

Add instructions to the AI.

Inserts a system message as the first item in the model's context.

Examples

iex> add_instructions(%AIPayload{}, "Please summarize the text.")
%AIPayload{instructions: "Please summarize the text."}

add_message(ai, message)

Add a message to the AI's context.

This is usually a user message or input.

Examples

iex> add_message(%AIPayload{}, "What's the weather?")
%AIPayload{input: [%{role: "user", content: "What's the weather?"}]}

set_model(ai, model)

Set the AI model to use.

Examples

iex> set_model(%AIPayload{}, "gpt-4.1")
%AIPayload{model: "gpt-4.1"}

set_schema(ai, schema)

Set a schema.

Raises ArgumentError if schema's name is missing or empty.

Examples

iex> set_schema(%AIPayload{}, %AISchema{name: "test"})
%AIPayload{text: %{format: %AISchema{name: "test"}}}

iex> set_schema(%AIPayload{}, %AISchema{})
** (ArgumentError) schema name cannot be empty