Omni.Context (Omni v2.0.0)

Copy Markdown View Source

The context for a conversation with an LLM.

A context is what a text request sends: the second argument to Omni.generate_text/3 and Omni.stream_text/3. Both also take a string or a list of messages and build the context for you. Contexts and messages shows a conversation carried over several turns.

context = Omni.context(system: "You are a helpful assistant.", messages: [Omni.message("Hello!")])

{:ok, response} = Omni.generate_text("anthropic:claude-sonnet-5-5", context)
context = Omni.Context.push(context, response)

Struct fields

  • :system - the system prompt, or nil
  • :messages - the conversation so far, as a list of Omni.Message structs, oldest first
  • :tools - the Omni.Tool structs the model may use

Summary

Types

t()

System prompt, messages, and tools for a generation request.

Functions

Creates a new context from a string, list of messages, keyword list, or map.

Appends messages to the context.

Types

t()

@type t() :: %Omni.Context{
  messages: [Omni.Message.t()],
  system: String.t() | nil,
  tools: [Omni.Tool.t()]
}

System prompt, messages, and tools for a generation request.

Functions

new(attrs \\ [])

@spec new(Enumerable.t() | String.t() | [Omni.Message.t()] | t()) :: t()

Creates a new context from a string, list of messages, keyword list, or map.

A string is a single user message. A list of messages is the message history. A keyword list or map sets :system, :messages and :tools. An existing context is returned as is.

push(context, message)

@spec push(t(), Omni.Message.t() | [Omni.Message.t()] | Omni.Response.t()) :: t()

Appends messages to the context.

Takes one message, a list of messages, or an Omni.Response. A response adds all of its :messages, which after a tool loop includes every tool use and tool result along the way.