AI.Completion (fnord v0.8.33)

View Source

This module sends a request to the model and handles the response. It is able to handle tool calls and responses.

Input options

Output options

Output is controlled by the following mechanisms.

  1. log_msgs - log messages from the user and assistant as info
  2. log_tool_calls - log tool calls as info and tool call results as debug

LOGGER_LEVEL must be set to debug to see the output of tool call results.

Summary

Functions

Returns a map of tool names to the number of times each tool was called in the most recent round of the conversation, starting from the most recent user message.

Types

response()

@type response() ::
  {:ok, t()}
  | {:error, t()}
  | {:error, binary()}
  | {:error, :context_length_exceeded, non_neg_integer()}

t()

@type t() :: %AI.Completion{
  archive_notes: boolean(),
  compact?: bool(),
  log_msgs: boolean(),
  log_tool_calls: boolean(),
  messages: [AI.Util.msg()],
  model: String.t(),
  name: String.t() | nil,
  replay_conversation: boolean(),
  response: String.t() | nil,
  response_format: map() | nil,
  specs: [AI.Tools.tool_spec()] | nil,
  tool_call_requests: list(),
  toolbox: AI.Tools.toolbox() | nil,
  usage: integer()
}

Functions

get(opts)

@spec get(Keyword.t()) :: response()

handle_tool_call(state, map)

@spec handle_tool_call(t(), AI.Util.tool_call()) ::
  {:ok, AI.Util.tool_request_msg(), AI.Util.tool_response_msg()}

new(opts)

@spec new(Keyword.t()) :: {:ok, t()} | {:error, any()}

new_from_conversation(conversation, opts)

@spec new_from_conversation(Store.Project.Conversation.t(), Keyword.t()) ::
  {:ok, t()} | {:error, :conversation_not_found}

tools_used(map)

@spec tools_used(t()) :: %{required(binary()) => non_neg_integer()}

Returns a map of tool names to the number of times each tool was called in the most recent round of the conversation, starting from the most recent user message.