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 catalog;
36pub mod client;
37pub mod completion;
38pub mod driver;
39pub mod effect;
40pub mod embeddings;
41pub mod error;
42pub use rig_http::http_client;
43pub mod id;
44#[cfg(feature = "image")]
45#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
46pub mod image_generation;
47/// Internal JSON helpers shared with sibling runtime crates (e.g. `rig-agent`).
48/// Not part of rig-core's stable public API.
49#[doc(hidden)]
50pub mod json_utils;
51pub mod loaders;
52pub mod markers;
53pub mod memory;
54pub mod model;
55pub mod observe;
56pub mod operation;
57pub mod prelude;
58pub(crate) mod provider_response;
59pub mod providers;
60pub mod rerank;
61pub mod serve;
62
63pub mod streaming;
64pub mod structured_output;
65#[cfg(any(test, feature = "test-utils"))]
66#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
67pub mod test_utils;
68pub mod tool;
69pub mod transcript;
70pub mod transcription;
71pub mod vector_store;
72pub use rig_http::wasm_compat;
73pub mod wire;
74#[cfg(feature = "websocket")]
75#[cfg_attr(docsrs, doc(cfg(feature = "websocket")))]
76pub use rig_http::ws_client;
77
78pub use completion::message;
79pub use driver::{DynModel, Model};
80pub use embeddings::Embed;
81pub use error::{ErrorKind, ErrorReport, ProviderError};
82pub use provider_response::ProviderResponseError;
83// `schemars`, `serde`, and `serde_json` are re-exported so macro-generated
84// code (and downstream crates) can resolve them through Rig instead of
85// requiring a direct dependency on each.
86pub use schemars;
87pub use serde;
88pub use serde_json;
89
90#[cfg(feature = "derive")]
91#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
92pub use rig_derive::ContextValue;
93#[cfg(feature = "derive")]
94#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
95pub use rig_derive::Embed;
96
97#[cfg(feature = "derive")]
98#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
99pub use rig_derive::rig_tool;
100
101pub mod telemetry;
102
103// Native runtime values must retain their thread-safety bounds.
104#[cfg(not(target_family = "wasm"))]
105const _: fn() = || {
106    fn assert_send_sync_static<T: Send + Sync + 'static>() {}
107    fn assert_send_static<T: Send + 'static>() {}
108    assert_send_sync_static::<tool::ManagedToolToken>();
109    assert_send_sync_static::<streaming::StreamEvent>();
110    // The serializable identity a typed view is resolved from.
111    assert_send_sync_static::<completion::ModelRef>();
112    assert_send_sync_static::<tool::DynamicTool>();
113    // One erased transport, shared by every provider a host binds.
114    assert_send_sync_static::<http_client::DynHttpClient>();
115    // A live stream is owned by one poller: `Send` so it can move to a worker,
116    // not `Sync`.
117    assert_send_static::<streaming::CompletionStream>();
118};