Skip to main content

svir/
lib.rs

1//! A small, composable SDK for talking to large language models.
2//!
3//! The core is the wire protocol between an application and a model server: the types in this
4//! crate, an encoder, a decoder, a transport, and compatibility handling. Layers and tool sets
5//! sit on top, opt-in. There is no agent loop: feeding tool results back is a few lines of the
6//! caller's code.
7//!
8//! With the `client` feature, `Client` sends a [`Request`] to an OpenAI-compatible server and
9//! returns the answer whole or as an `EventStream`. The codec under it,
10//! [`openai::chat::Encoder`] and [`openai::chat::Decoder`], works on its own with any transport.
11//! Layers (`svir::layer`) wrap every call; [`Toolbox`] and [`Tools`] describe tools to a model
12//! and answer its calls.
13//!
14//! ```
15//! use svir::prelude::*;
16//!
17//! let request = Request::new("qwen3-27b")
18//!     .system("Be precise.")
19//!     .reasoning(Effort::Low)
20//!     .message(
21//!         Message::user("What changed between these two?")
22//!             .with(Image::path("before.png"))
23//!             .with(Image::path("after.png"))
24//!             .with(TextFile::path("diff.patch")),
25//!     );
26//!
27//! assert_eq!(request.messages[0].parts.len(), 4);
28//! ```
29
30pub mod body;
31mod decode;
32mod error;
33mod message;
34mod request;
35mod response;
36mod tool;
37mod tools;
38
39#[cfg(feature = "client")]
40mod client;
41#[cfg(feature = "client")]
42pub mod http;
43#[cfg(feature = "client")]
44pub mod layer;
45pub mod openai;
46#[cfg(feature = "client")]
47mod stream;
48
49#[cfg(feature = "client")]
50pub use client::{Client, ClientBuilder, Model};
51#[cfg(feature = "client")]
52pub use stream::{EventStream, RawStream};
53
54pub use decode::{Limits, Mode, Think};
55pub use error::{Error, ErrorKind, Result};
56pub use message::{Image, Message, Part, Role, Source, TextFile, ToolResult};
57pub use request::{Effort, Request, ResponseFormat, Schema};
58pub use response::{
59    Completion, Event, FinishReason, Reasoning, ReasoningSource, Timing, ToolCallDelta, Usage,
60};
61pub use tool::{Tool, ToolCall, ToolChoice};
62pub use tools::{ToolOutput, Toolbox, Tools};
63
64/// The everyday imports.
65pub mod prelude {
66    #[cfg(feature = "client")]
67    pub use crate::{Client, EventStream};
68    pub use crate::{
69        Completion, Effort, Error, ErrorKind, Event, FinishReason, Image, Message, Part, Reasoning,
70        Request, ResponseFormat, Role, Schema, TextFile, Tool, ToolCall, ToolChoice, ToolResult,
71        Toolbox, Tools, Usage,
72    };
73}