Jido.AI.Actions.OpenaiEx (Jido AI v0.5.2)

View Source

Summary

Functions

category()

description()

name()

on_after_run(result)

Callback implementation for Jido.Action.on_after_run/1.

on_after_validate_params(params)

Callback implementation for Jido.Action.on_after_validate_params/1.

on_before_validate_params(params)

Callback implementation for Jido.Action.on_before_validate_params/1.

on_error(failed_params, error, context, opts)

Callback implementation for Jido.Action.on_error/4.

run(params, context)

@spec run(map(), map()) :: {:ok, map()} | {:error, any()}

Runs a chat completion request using OpenAI Ex.

Parameters

  • params: Map containing:
    • model: Either a %Jido.AI.Model{} struct or a tuple of {provider, opts}
    • messages: List of message maps with :role and :content (required if prompt is not provided)
    • prompt: A %Jido.AI.Prompt{} struct or string (required if messages is not provided)
    • tools: Optional list of Jido.Action modules for function calling
    • tool_choice: Optional tool choice configuration
    • temperature: Optional float between 0 and 2 (defaults to model's temperature)
    • max_tokens: Optional integer (defaults to model's max_tokens)
    • top_p: Optional float between 0 and 1
    • frequency_penalty: Optional float between -2.0 and 2.0
    • presence_penalty: Optional float between -2.0 and 2.0
    • stop: Optional list of strings
    • response_format: Optional atom (:text or :json)
    • seed: Optional integer for deterministic responses
    • stream: Optional boolean for streaming responses
  • context: The action context containing state and other information

Returns

  • } on success
  • on failure
  • Stream of chunks if streaming is enabled

schema()

tags()

to_json()

to_tool()

validate_params(params)

@spec validate_params(map()) :: {:ok, map()} | {:error, String.t()}

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"}

vsn()