OpenUI.Message (OpenUI v0.1.1)

Copy Markdown View Source

The protocol a host stores responses with (prompt.md, section 7): the program wrapped in ]]>openui:content, ]]>openui:context and ]]>openui:end marker lines. The model never writes or sees these lines.

raw = OpenUI.Message.build(content: program, context: [state], end: true)
%OpenUI.Message{content: program} = OpenUI.Message.parse(raw)

When a response was regenerated, the last content wins.

Summary

Functions

Writes a stored message. context is written as is when it is a string, else as JSON, and is left out when nil. attributes are key-value pairs, such as [{"library", "support@1.2.0"}].

The stored turn for an action that continues the conversation, in the reference format: the message, and as context ["User clicked: <message>", formState, context] (the context only when the action has one).

What the model reads of a stored message, with every marker line removed: the program for an assistant turn; for a user turn, the message and, when there is a context, context and form values = <its JSON>.

Reads a stored message. With streaming: true, a last line that may be a marker cut mid-stream is held back.

Types

t()

@type t() :: %OpenUI.Message{
  attributes: %{required(String.t()) => String.t()},
  content: String.t(),
  context: term(),
  end?: boolean()
}

Functions

build(opts)

@spec build(keyword()) :: String.t()

Writes a stored message. context is written as is when it is a string, else as JSON, and is left out when nil. attributes are key-value pairs, such as [{"library", "support@1.2.0"}].

from_event(event)

@spec from_event(OpenUI.Event.t()) :: String.t()

The stored turn for an action that continues the conversation, in the reference format: the message, and as context ["User clicked: <message>", formState, context] (the context only when the action has one).

model_text(raw, atom)

@spec model_text(String.t(), :assistant | :user) :: String.t()

What the model reads of a stored message, with every marker line removed: the program for an assistant turn; for a user turn, the message and, when there is a context, context and form values = <its JSON>.

parse(raw, opts \\ [])

@spec parse(String.t(), keyword()) :: t()

Reads a stored message. With streaming: true, a last line that may be a marker cut mid-stream is held back.