Skip to main content

rig_core/client/
completion.rs

1use crate::completion::CompletionModel;
2
3/// A provider client with completion capabilities.
4/// Clone is required for conversions between client types.
5pub trait CompletionClient {
6    /// The type of CompletionModel used by the client.
7    type CompletionModel: CompletionModel<Client = Self>;
8
9    /// Create a completion model with the given model.
10    ///
11    /// # Example with OpenAI
12    /// ```no_run
13    /// use rig_core::prelude::*;
14    /// use rig_core::providers::openai::{Client, self};
15    ///
16    /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
17    /// // Initialize the OpenAI client
18    /// let openai = Client::new("your-open-ai-api-key")?;
19    ///
20    /// let gpt = openai.completion_model(openai::GPT_5_2);
21    /// # Ok(())
22    /// # }
23    /// ```
24    fn completion_model(&self, model: impl Into<String>) -> Self::CompletionModel {
25        Self::CompletionModel::make(self, model)
26    }
27}