Expand description
Provider-agnostic completion requests and responses. A provider’s wire
translates CompletionRequest into its own request and normalizes the
reply as CompletionResponse; a Model sends it.
use rig_core::{Model, completion::CompletionRequest, providers::openai::OpenAIConfig};
let model = OpenAIConfig::from_env()?.connect(http).completion("gpt-4o");
let request = CompletionRequest::new("What is Rig?");
let response = model.call(request).await?;
println!("{:?}", response.choice);Re-exports§
pub use cache_cost::CacheCost;pub use cache_cost::CacheRates;pub use handle::ModelRef;pub use history::Accepts;pub use history::LaterSystem;pub use history::Media;pub use history::Pairing;pub use history::Place;pub use history::Replay;pub use history::ReplayTarget;pub use history::adapt;pub use message::AssistantContent;pub use message::AssistantMessage;pub use message::Message;pub use message::MessageError;pub use options::CacheRetention;pub use options::CheckError;pub use options::Effort;pub use options::GenerationOptions;pub use options::OnUnsupported;pub use options::Reasoning;pub use options::ServiceTier;pub use options::UnsupportedOption;pub use options::Verbosity;pub use prompt::Section;pub use prompt::SystemPrompt;pub use provider_options::ExtensionOptions;pub use provider_options::OptionsError;pub use provider_options::ProviderExtension;pub use provider_options::ProviderOptions;pub use provider_options::ReplyExtras;pub use provider_options::SHARED;pub use request::*;
Modules§
- cache_
cost - What prompt caching cost and saved, priced the same way on every provider.
- handle
- Serializable model labels resolved to live handles by a runtime.
- history
- Shaping a conversation for the model it is sent to.
adaptis the one place history meets its target: a turn the same model produced keeps its provider items, any other turn replays from its canonical fields, failed turns are skipped, and every tool call gets an answer. - message
- options
- Portable generation options: provider-neutral knobs a request sets once
and every completion wire maps to its own JSON, or refuses. They hold only
what
CompletionRequesthas no field for, sotemperature,max_tokens,tool_choiceandoutput_schemastay on the request. - prompt
- A system prompt as data: a role and named sections, rendered into one system message only when the request is sent, so a layer in between can read, change or move a section by its tag.
- provider_
options - Typed per-provider request options and reply extras. A provider’s
ProviderExtensionmarker names its key, its serialize-onlyOptionsand itsExtrasview of a reply.ProviderOptionsholds entries for several providers at once, and each wire reads only the entry named by its own provider. - request
- Completion requests, normalized responses, and provider model contracts.