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, ornil:messages- the conversation so far, as a list ofOmni.Messagestructs, oldest first:tools- theOmni.Toolstructs the model may use
Summary
Functions
Creates a new context from a string, list of messages, keyword list, or map.
Appends messages to the context.
Types
@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
@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.
@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.