class

LLM::Chat

Inherits Reference < Object

Chat is an abstract class that serves as a base for creating various chat implementations.

Constructors

Instance methods

append_conversations(to : Chat, which : Conversation) : Bool

Append conversations to target chat's history

Source
ask(content : String, attach : ChatInclusions | Nil = nil, response_schema : ResponseSchema | Nil = nil, exclude_reasoning_in_history = false, & : ChatEvent -> ) : Nil

Submit a query, with optional attachments and request for response as a JSON object by specifying a JSON schema.

Source
call_tools_and_setup_ask(tool_calls : Array(JSON::Any), & : LLM::ChatEvent -> ) : Int32

Invoke tool calls and return number of calls made; if positive call re_ask to hand call results to the models to process

Source
debug?
Source
each_tool(origin : String | Nil = nil, &)
Source
each_tool
Source
each_tool_origin
Source
erase_history

Erase history but keep connection

Source
extract_conversations(which : Conversation) : String | Nil

Extract conversations and return as a JSON string or nil

Source
find_tool?(name)
Source
fork(from : Chat) : Nil

Replace current session with a "fork" of the session from the given Chat instance; may fail if self is not compatible.

Source
import(prompt : MCP::PromptResult, emit = false, & : ChatEvent -> ) : Nil
Source
load(io : IO | String) : Nil

Load chat history

Source
model
Source
re_ask(response_schema : ResponseSchema | Nil = nil, exclude_reasoning_in_history = false, & : ChatEvent -> ) : Nil

Resubmit current session as a query to get another answer

Source
readonly?
Source
reasoning
Source
save(io : IO | JSON::Builder) : Nil

Save chat history

Source
send_tail(to : Chat, num_responses = 1, filter_by_role : String = nil) : Nil

Append latest num_responses messages to the target chat's history

Source
streaming?
Source
system_message
Source
tail(num_responses = 1, & : ChatEvent -> ) : Nil

Yield the latest num_responses messages from chat history

Source
with_debug
Source
with_model(model : String)
Source
with_readonly

Make chat session read-only. This will remove all tools that are not readonly.

Source
with_reasoning(effort : Reasoning)
Source
with_streaming
Source
with_system_message(content : String)
Source
with_tool(function : Function) : Function | Nil

Return nil if unable to use / enable the function

Source
without_tool(function_name)
Source