CompletionClient

Trait CompletionClient 

Source
pub trait CompletionClient {
    type CompletionModel: CompletionModel<Client = Self>;

    // Provided methods
    fn completion_model(
        &self,
        model: impl Into<String>,
    ) -> Self::CompletionModel { ... }
    fn agent(
        &self,
        model: impl Into<String>,
    ) -> AgentBuilder<Self::CompletionModel> { ... }
    fn extractor<T>(
        &self,
        model: impl Into<String>,
    ) -> ExtractorBuilder<Self::CompletionModel, T>
       where T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync { ... }
}
Expand description

A provider client with completion capabilities. Clone is required for conversions between client types.

Required Associated Types§

Source

type CompletionModel: CompletionModel<Client = Self>

The type of CompletionModel used by the client.

Provided Methods§

Source

fn completion_model(&self, model: impl Into<String>) -> Self::CompletionModel

Create a completion model with the given 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 gpt4 = openai.completion_model(openai::GPT4);
Source

fn agent(&self, model: impl Into<String>) -> 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();
Source

fn extractor<T>( &self, model: impl Into<String>, ) -> ExtractorBuilder<Self::CompletionModel, T>
where T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync,

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.

Implementors§

Source§

impl<M, Ext, H> CompletionClient for Client<Ext, H>
where Ext: Capabilities<H, Completion = Capable<M>>, M: CompletionModel<Client = Self>,