Skip to main content

Crate svir

Crate svir 

Source
Expand description

A small, composable SDK for talking to large language models.

The core is the wire protocol between an application and a model server: the types in this crate, an encoder, a decoder, a transport, and compatibility handling. Layers and tool sets sit on top, opt-in. There is no agent loop: feeding tool results back is a few lines of the caller’s code.

With the client feature, Client sends a Request to an OpenAI-compatible server and returns the answer whole or as an EventStream. The codec under it, openai::chat::Encoder and openai::chat::Decoder, works on its own with any transport. Layers (svir::layer) wrap every call; Toolbox and Tools describe tools to a model and answer its calls.

use svir::prelude::*;

let request = Request::new("qwen3-27b")
    .system("Be precise.")
    .reasoning(Effort::Low)
    .message(
        Message::user("What changed between these two?")
            .with(Image::path("before.png"))
            .with(Image::path("after.png"))
            .with(TextFile::path("diff.patch")),
    );

assert_eq!(request.messages[0].parts.len(), 4);

Modules§

body
A request body whose length is known before its first byte.
http
The HTTP seam: the little of HTTP that svir needs, as a trait.
layer
Layers: middleware around a call.
openai
OpenAI-compatible wire APIs.
prelude
The everyday imports.

Structs§

Client
A client for one model server.
ClientBuilder
Builds a Client. Created by Client::openai.
Completion
A whole answer.
Error
An error from svir.
EventStream
The answer to one request, as a stream of events.
Image
An image attachment.
Limits
Bounds on one response. They apply in every mode; reaching one is ErrorKind::ResponseLimit.
Message
One turn of a conversation: a role, and its parts in order.
Model
A model, as the server lists it.
RawStream
The bytes of a response as the server sent them, failing if it goes silent for too long.
Reasoning
Reasoning, and where in the response it came from.
Request
A request to a model.
Schema
A JSON Schema for the answer, with a name for it.
TextFile
A text file attachment, sent as text inside the message with its name.
Timing
When the first and the last visible text or reasoning arrived, from the start of the response.
Tool
A tool the model may call: a name, what it does, and the JSON Schema of its input.
ToolCall
A call the model made: which tool, and the arguments exactly as the model wrote them.
ToolCallDelta
A piece of a tool call as it streams.
ToolResult
The result of a tool call, as the caller’s own string.
Tools
A registry of tools and their handlers.
Usage
Token counts, as the server reported them.

Enums§

Effort
How much the model should reason before answering.
ErrorKind
What went wrong, in terms a caller can act on.
Event
One item of an answer stream.
FinishReason
Why the model stopped.
Mode
How strictly a response is read.
Part
A piece of a message.
ReasoningSource
Where reasoning came from in the response.
ResponseFormat
The shape of the answer’s text.
Role
Who a message is from.
Source
Where an attachment’s bytes are.
Think
What to do with <think>...</think> inside the answer text.
ToolChoice
Whether the model may call a tool, must call one, or must call a given one.

Traits§

ToolOutput
What a tool handler may return.
Toolbox
Anything that can describe tools to a model and answer its calls.

Type Aliases§

Result
A Result whose error is Error.