rig-core 0.47.0

An opinionated library for building LLM powered applications.
Documentation
//! Cohere configuration, model identifiers, and its chat and embedding
//! wires.
//!
//! [`Cohere::completion`] chats through Cohere's OpenAI Compatibility API on
//! the shared Chat Completions wire, as the
//! [`COHERE`](crate::providers::openai::wire::COHERE) dialect.
//! [`Cohere::native_completion`] chats through Cohere's native chat API
//! ([`NativeChat`]), which grounds the answer in the request's documents and
//! keeps the citations that point at each text block in its provider item.
//! A turn made on one API replays on the other from its canonical fields
//! only, so its citations and tool plan stay behind. Text and image embeddings use Cohere's own `/v1/embed`.
//!
//! ```no_run
//! use rig_core::providers::cohere;
//!
//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let provider = cohere::Cohere::from_env()?;
//!
//! let command_a = provider.native_completion(cohere::COMMAND_A_03_2025);
//! let embeddings = provider.embedding(cohere::EMBED_V4, None);
//! # Ok(())
//! # }
//! ```

pub mod chat;
pub mod embeddings;
pub mod extension;
pub mod streaming;
pub mod wire;

pub use crate::client::cohere::Cohere;
pub use chat::NativeChat;
pub use embeddings::{
    EMBED_ENGLISH_LIGHT_V3, EMBED_ENGLISH_V3, EMBED_MULTILINGUAL_LIGHT_V3, EMBED_MULTILINGUAL_V3,
    EMBED_V4, Embeddings, ImageEmbeddings,
};
pub use wire::CohereConfig;

/// Stable descriptor name recorded on normalized responses and telemetry.
pub const PROVIDER_NAME: &str = "cohere";

/// `command-a-plus-05-2026` completion model
pub const COMMAND_A_PLUS_05_2026: &str = "command-a-plus-05-2026";
/// `command-a-03-2025` completion model
pub const COMMAND_A_03_2025: &str = "command-a-03-2025";
/// `command-a-reasoning-08-2025` completion model
pub const COMMAND_A_REASONING_08_2025: &str = "command-a-reasoning-08-2025";
/// `command-a-vision-07-2025` completion model
pub const COMMAND_A_VISION_07_2025: &str = "command-a-vision-07-2025";
/// `command-a-translate-08-2025` completion model
pub const COMMAND_A_TRANSLATE_08_2025: &str = "command-a-translate-08-2025";
/// `command-r7b-12-2024` completion model
pub const COMMAND_R7B_12_2024: &str = "command-r7b-12-2024";
/// `command-r-plus-08-2024` completion model
pub const COMMAND_R_PLUS_08_2024: &str = "command-r-plus-08-2024";
/// `command-r-08-2024` completion model
pub const COMMAND_R_08_2024: &str = "command-r-08-2024";

/// Whether `model`, an id the catalog does not list, reads user images by
/// its name: Cohere's vision models (Command A Vision, Aya Vision) do, and
/// its text models do not.
pub(crate) fn reads_images(model: &str) -> bool {
    model.contains("vision")
}

/// Whether `model` thinks, as its facts say, or `None` for an id the
/// catalog does not list.
pub(crate) fn thinks(facts: &crate::catalog::ModelFacts, model: &str) -> Option<bool> {
    facts
        .for_model(PROVIDER_NAME, model)
        .map(|spec| spec.reasoning.supported())
}

#[cfg(test)]
mod history_tests;