Skip to main content

rig_core/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(
3    test,
4    allow(
5        clippy::expect_used,
6        clippy::indexing_slicing,
7        clippy::panic,
8        clippy::unwrap_used,
9        clippy::unreachable
10    )
11)]
12//! Provider-agnostic model, message, tool, memory, and vector-store contracts.
13//! Provider configurations build endpoint wires, and a [`Model`] binds a
14//! wire to a [`driver::Transport`]; a [`DynModel`] is a model erased to
15//! its operation, for consumers that store one. Companion crates supply
16//! transports, agent runtimes, and external storage integrations.
17//!
18//! ```no_run
19//! use rig_core::DynModel;
20//! use rig_core::completion::{CompletionRequest, CompletionResponse};
21//! use rig_core::error::ProviderError;
22//! use rig_core::operation::Completion;
23//!
24//! async fn ask(model: &DynModel<Completion>) -> Result<CompletionResponse, ProviderError> {
25//!     let request = CompletionRequest::new("Who are you?");
26//!     model.call(request).await
27//! }
28//! ```
29
30extern crate self as rig;
31
32#[cfg(feature = "audio")]
33#[cfg_attr(docsrs, doc(cfg(feature = "audio")))]
34pub mod audio_generation;
35pub mod client;
36pub mod completion;
37pub mod driver;
38pub mod effect;
39pub mod embeddings;
40pub mod error;
41pub use rig_http::http_client;
42pub mod id;
43#[cfg(feature = "image")]
44#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
45pub mod image_generation;
46/// Internal JSON helpers shared with sibling runtime crates (e.g. `rig-agent`).
47/// Not part of rig-core's stable public API.
48#[doc(hidden)]
49pub mod json_utils;
50pub mod loaders;
51pub mod markers;
52pub mod memory;
53pub mod model;
54pub mod observe;
55pub mod operation;
56pub mod prelude;
57pub(crate) mod provider_response;
58pub mod providers;
59pub mod rerank;
60pub mod serve;
61
62pub mod streaming;
63#[cfg(any(test, feature = "test-utils"))]
64#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
65pub mod test_utils;
66pub mod tool;
67pub mod transcript;
68pub mod transcription;
69pub mod vector_store;
70pub use rig_http::wasm_compat;
71pub mod wire;
72#[cfg(feature = "websocket")]
73#[cfg_attr(docsrs, doc(cfg(feature = "websocket")))]
74pub use rig_http::ws_client;
75
76pub use completion::message;
77pub use driver::{DynModel, Model};
78pub use embeddings::Embed;
79pub use error::{ErrorKind, ErrorReport, ProviderError};
80pub use provider_response::ProviderResponseError;
81// `schemars`, `serde`, and `serde_json` are re-exported so macro-generated
82// code (and downstream crates) can resolve them through Rig instead of
83// requiring a direct dependency on each.
84pub use schemars;
85pub use serde;
86pub use serde_json;
87
88#[cfg(feature = "derive")]
89#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
90pub use rig_derive::ContextValue;
91#[cfg(feature = "derive")]
92#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
93pub use rig_derive::Embed;
94
95#[cfg(feature = "derive")]
96#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
97pub use rig_derive::rig_tool;
98
99pub mod telemetry;
100
101// Native runtime values must retain their thread-safety bounds.
102#[cfg(not(target_family = "wasm"))]
103const _: fn() = || {
104    fn assert_send_sync_static<T: Send + Sync + 'static>() {}
105    fn assert_send_static<T: Send + 'static>() {}
106    assert_send_sync_static::<tool::ManagedToolToken>();
107    assert_send_sync_static::<streaming::StreamEvent>();
108    // The serializable identity a typed view is resolved from.
109    assert_send_sync_static::<completion::ModelRef>();
110    assert_send_sync_static::<tool::DynamicTool>();
111    // One erased transport, shared by every provider a host binds.
112    assert_send_sync_static::<http_client::DynHttpClient>();
113    // A live stream is owned by one poller: `Send` so it can move to a worker,
114    // not `Sync`.
115    assert_send_static::<streaming::CompletionStream>();
116};