class

LLM::OpenAI::History

Inherits JSON::Serializable::Unmapped < JSON::Serializable < Reference < Object

The serializable chat history keeps all wrapped messages to save the additional information when saving the session.

Constructors

new(pull : JSON::PullParser)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

append_last_conversation(to : History, outer = false)

Append last whole conversation, starting with most recent user message,

  • either all messages, or
  • user and assistant only
Source
append_message(msg : Message, usage : Usage | Nil = nil)
Source
append_session_conversation(to : History, outer = false)

Append conversation from the branch-point of this session, starting with most recent user message,

  • either all messages, or
  • user and assistant only
Source
branch(from : History, exclude_last_turn = false)

Copy the messages from another session's history, optionally excluding the last "turn".

Source
each_message

This yields each Message in the history

Source
extract_last_conversation(outer = false)

Extract last whole conversation, starting with most recent user message,

  • either all messages, or
  • user and assistant only
Source
extract_session_conversation(outer = false)

Extract conversation from the branch-point of this session, starting with most recent user message,

  • either all messages, or
  • user and assistant only
Source
format
Source
import(prompt : MCP::PromptResult, emit = false, & : ChatEvent -> ) : Nil
Source
last_usage

Returns the most recent usage information

Source
tail_chats(num = -1, & : ChatEvent -> )

Emit the last N request responses. Always tries to emit the query before the response. May include tool calls as a result. Use N=-1 to list all

Source
transfer_tail_chats(to : History, num = 1, filter_by_role : String | Nil = nil)
Source

Nested types