Jido.AI.Actions.Instructor (Jido AI v0.5.2)
View SourceA low-level action that provides direct access to Instructor's chat completion functionality. Supports most Instructor options and integrates with Jido's Model and Prompt structures.
Features
- Multi-provider support (Anthropic, OpenAI, Ollama, llamacpp, Together, OpenRouter, etc.)
- Streaming capabilities with array or partial response models
- Response mode configuration (:json, :function_call)
- Structured output validation with automatic retries
Usage
# Define a response model with Ecto
defmodule WeatherResponse do
use Ecto.Schema
embedded_schema do
field :temperature, :float
field :conditions, :string
field :city, :string
end
end
# Create a structured response
{:ok, result, _} = Jido.AI.Actions.Instructor.run(%{
model: %Jido.AI.Model{provider: :anthropic, model: "claude-3-sonnet-20240229", api_key: "key"},
prompt: Jido.AI.Prompt.new(:user, "What's the weather in Tokyo?"),
response_model: WeatherResponse,
max_retries: 2
})
Support Matrix
Provider | Adapter | Configuration |
---|---|---|
anthropic | Anthropic | api_key |
openai | OpenAI | openai: [api_key: "key"] |
openrouter | OpenAI | openai: [api_key, api_url] |
ollama | OpenAI | openai: [api_key, api_url] |
llamacpp | Llamacpp | llamacpp: [api_url] |
together | OpenAI | openai: [api_key, api_url] |
other | Defaults to Anthropic | api_key |
Summary
Functions
Callback implementation for Jido.Action.on_after_run/1
.
Callback implementation for Jido.Action.on_after_validate_params/1
.
Callback implementation for Jido.Action.on_error/4
.
Executes the Action with the given parameters and context.
Validates the input parameters for the Action.
Functions
Callback implementation for Jido.Action.on_after_run/1
.
Callback implementation for Jido.Action.on_after_validate_params/1
.
Callback implementation for Jido.Action.on_error/4
.
Executes the Action with the given parameters and context.
The run/2
function must be implemented in the module using Jido.Action.
Validates the input parameters for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> schema: [
...> input: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}
iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}