Skip to main content

Crate rust_llm_loco

Crate rust_llm_loco 

Source
Expand description

§rust_llm_loco

RubyLLM’s Rails integration (acts_as_chat, acts_as_message, acts_as_tool_call, the rust_llm_models/rust_llm_usages ledgers) for Loco’s default ORM, SeaORM.

class Chat < ApplicationRecord
  acts_as_chat
end
chat = Chat.create!(model: "claude-haiku-4-5")
chat.with_tools(Weather).ask("What's the weather in Berlin?")
chat.messages.count # => user, assistant tool call, tool result, assistant
use rust_llm_loco::ChatRecord;

let record = ChatRecord::create(db, "claude-haiku-4-5", None).await?;
let mut chat = record.to_llm(db).await?.with_tool(Weather);
record.ask(db, &mut chat, "What's the weather in Berlin?").await?;
let rows = record.messages(db).await?; // user, assistant tool call, tool result, assistant

Like RubyLLM, every message, tool call, and billed attempt is written as it happens, so a chat can be reloaded mid-round (parked on a tool approval or an MCP input request) and continued later, and another process can cancel it through the chats.cancelled column. Add migrations() to your Loco migrator for the tables.

Message attachments live in rust_llm_attachments (bytes plus the filename, content type, and resolution RubyLLM keeps on the Active Storage blob), since Loco has no Active Storage. See the persistence guide.

Re-exports§

pub use batch::BatchStore;
pub use model_store::ModelStore;

Modules§

batch
Port of lib/ruby_llm/active_record/batch.rb: RustLLM’s persistence for provider-side batches, in rust_llm_batches. With a BatchStore set as config.batch_store (the Railtie sets RubyLLM::ActiveRecord::Batch there), rust_llm::batch(chats) records the batch and its chats when it is submitted, Batch::find(id) rebuilds it from the row in any process, with the records’ chats attached, and refresh/cancel write the new state back.
entities
SeaORM entities for the tables migrations creates: RubyLLM::ActiveRecord::Model, ToolCall, Usage, and the app’s Chat/Message (acts_as_chat/acts_as_message), plus rust_llm_attachments, which stands in for Active Storage, and rust_llm_batches.
migrations
Port of rails generate rust_llm:install’s migrations: the same tables and columns, as SeaORM migrations. Add rust_llm_loco::migrations() to your app’s Migrator.
model_store
Port of lib/ruby_llm/active_record/model.rb: the rust_llm_models table as the model registry store. Chats point at a row through chats.rust_llm_model_id; listed returns the rows the provider still serves, unlisted the ones kept only because a chat references them.

Structs§

ChatRecord
A persisted chat: the Chat model that acts_as_chat.
McpCredentialStore
RubyLLM::ActiveRecord::MCPCredential as a CredentialStore.
ProviderFile
RubyLLM::ActiveRecord::ProviderFile.
UsageLedger
rust_llm_usages as Accounting::Usage.ledger (Ruby’s railtie sets RubyLLM::ActiveRecord::Usage there). Rows belong to no chat and keep their owner when it is a record (rust_llm::accounting::UsageOwner::Record).

Enums§

Error
StreamEvent
What ChatRecord::complete_stream reports while it runs: RubyLLM’s on_new_message, each streamed chunk, and on_end_message, each with the messages row it belongs to.

Constants§

CANCELLATION_POLL_INTERVAL
ChatMethods::CANCELLATION_POLL_INTERVAL: how often a running complete reads the chats.cancelled column another process may have set.
CHAT_TYPE
The polymorphic type names written into message_type/chat_type, like Rails’ class names.
MESSAGE_TYPE

Functions§

find_or_create_model
ChatMethods#find_or_create_model: Model.find_or_create_by!(provider:, model_id:) with the registry’s metadata, reusing the row another process inserted between the lookup and the insert.
insert_model
The insert half of find_or_create_model, after its lookup missed: inserts the row, or returns the one another process inserted in between (the unique index rejects ours).
message_to_llm
message.to_llm for a messages row read from the database: its tool calls, the tool call it answers, attachments, and usage entries are loaded with it, so model, model_info, and the finish predicates answer as they do on the in-memory message.
migrations
The Rust migrations to append to an app’s Migrator::migrations().
purge_attachments
message.attachments.purge: deletes the attachment rows of these messages and, like the after_destroy hook RubyLLM puts on Active Storage blobs, the provider uploads recorded against them (ProviderFile.forget_blob).
tool_error_message
tool_error_message (PayloadHelpers#payload_error_message): the error of a JSON object payload, such as a failed tool result’s content or a tool call’s arguments, or None.

Type Aliases§

Result