OpenAI

Type Alias OpenAI 

Source
pub type OpenAI = GenericOpenAI<OpenAIConfig>;
Available on crate feature openai only.
Expand description

The OpenAI struct encapsulates an OpenAI client and default options for embedding and prompt models. It uses the Builder pattern for flexible and customizable instantiation.

§Example


// Create an OpenAI client with default options. The client will use the OPENAI_API_KEY environment variable.
let openai = OpenAI::builder()
    .default_embed_model("text-embedding-3-small")
    .default_prompt_model("gpt-4")
    .build().unwrap();

// Create an OpenAI client with a custom api key.
let openai = OpenAI::builder()
    .default_embed_model("text-embedding-3-small")
    .default_prompt_model("gpt-4")
    .client(async_openai::Client::with_config(async_openai::config::OpenAIConfig::default().with_api_key("my-api-key")))
    .build().unwrap();

// Create an OpenAI client with custom options
let openai = OpenAI::builder()
    .default_embed_model("text-embedding-3-small")
    .default_prompt_model("gpt-4")
    .default_options(
        Options::builder()
          .temperature(1.0)
          .parallel_tool_calls(false)
          .user("MyUserId")
    )
    .build().unwrap();

Aliased Type§

pub struct OpenAI {
    pub stream_full: bool,
    /* private fields */
}

Fields§

§stream_full: bool

Convenience option to stream the full response. Defaults to true, because nobody has time to reconstruct the delta. Disabling this will make the streamed content only return the delta, for when performance matters. This only has effect when streaming is enabled.

Implementations§

Source§

impl OpenAI

Source

pub fn builder() -> OpenAIBuilder

Creates a new OpenAIBuilder for constructing OpenAI instances.