pub trait CompletionClient: ProviderClient + Clone {
type CompletionModel: CompletionModel;
// Required method
fn completion_model(&self, model: &str) -> Self::CompletionModel;
// Provided methods
fn agent(&self, model: &str) -> AgentBuilder<Self::CompletionModel> { ... }
fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>(
&self,
model: &str,
) -> ExtractorBuilder<T, Self::CompletionModel> { ... }
}
Expand description
A provider client with completion capabilities. Clone is required for conversions between client types.
Required Associated Types§
Sourcetype CompletionModel: CompletionModel
type CompletionModel: CompletionModel
The type of CompletionModel used by the client.
Required Methods§
Sourcefn completion_model(&self, model: &str) -> Self::CompletionModel
fn completion_model(&self, model: &str) -> Self::CompletionModel
Create a completion model with the given name.
§Example with OpenAI
use rig::prelude::*;
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let gpt4 = openai.completion_model(openai::GPT_4);
Provided Methods§
Sourcefn agent(&self, model: &str) -> AgentBuilder<Self::CompletionModel>
fn agent(&self, model: &str) -> AgentBuilder<Self::CompletionModel>
Create an agent builder with the given completion model.
§Example with OpenAI
use rig::prelude::*;
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let agent = openai.agent(openai::GPT_4)
.preamble("You are comedian AI with a mission to make people laugh.")
.temperature(0.0)
.build();
Sourcefn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>(
&self,
model: &str,
) -> ExtractorBuilder<T, Self::CompletionModel>
fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>( &self, model: &str, ) -> ExtractorBuilder<T, Self::CompletionModel>
Create an extractor builder with the given completion model.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.