pub struct OpenAIClientBuilder { /* private fields */ }
Implementations§
Source§impl OpenAIClientBuilder
impl OpenAIClientBuilder
pub fn new() -> Self
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Examples found in repository?
examples/audio_translations.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioTranslationRequest::new(
"examples/data/problem_cn.mp3".to_string(),
WHISPER_1.to_string(),
);
let result = client.audio_translation(req).await?;
println!("{:?}", result);
Ok(())
}
More examples
examples/audio_transcriptions.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioTranscriptionRequest::new(
"examples/data/problem.mp3".to_string(),
WHISPER_1.to_string(),
);
let result = client.audio_transcription(req).await?;
println!("{:?}", result);
Ok(())
}
examples/embedding.rs (line 9)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut req = EmbeddingRequest::new(
TEXT_EMBEDDING_3_SMALL.to_string(),
vec!["story time".to_string(), "Once upon a time".to_string()],
);
req.dimensions = Some(10);
let result = client.embedding(req).await?;
println!("{:?}", result.data);
Ok(())
}
examples/audio_speech.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioSpeechRequest::new(
TTS_1.to_string(),
String::from("Money is not the problem, the problem is no money."),
audio::VOICE_ALLOY.to_string(),
String::from("examples/data/problem.mp3"),
);
let result = client.audio_speech(req).await?;
println!("{:?}", result);
Ok(())
}
examples/completion.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = CompletionRequest::new(
completion::GPT3_TEXT_DAVINCI_003.to_string(),
String::from("What is Bitcoin?"),
)
.max_tokens(3000)
.temperature(0.9)
.top_p(1.0)
.stop(vec![String::from(" Human:"), String::from(" AI:")])
.presence_penalty(0.6)
.frequency_penalty(0.0);
let result = client.completion(req).await?;
println!("{:}", result.choices[0].text);
Ok(())
}
examples/chat_completion.rs (line 9)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = ChatCompletionRequest::new(
GPT4_O_MINI.to_string(),
vec![chat_completion::ChatCompletionMessage {
role: chat_completion::MessageRole::user,
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);
let result = client.chat_completion(req).await?;
println!("Content: {:?}", result.choices[0].message.content);
println!("Response Headers: {:?}", result.headers);
Ok(())
}
Additional examples can be found in:
pub fn with_endpoint(self, endpoint: impl Into<String>) -> Self
pub fn with_organization(self, organization: impl Into<String>) -> Self
pub fn with_proxy(self, proxy: impl Into<String>) -> Self
pub fn with_timeout(self, timeout: u64) -> Self
pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Sourcepub fn build(self) -> Result<OpenAIClient, Box<dyn Error>>
pub fn build(self) -> Result<OpenAIClient, Box<dyn Error>>
Examples found in repository?
examples/audio_translations.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioTranslationRequest::new(
"examples/data/problem_cn.mp3".to_string(),
WHISPER_1.to_string(),
);
let result = client.audio_translation(req).await?;
println!("{:?}", result);
Ok(())
}
More examples
examples/audio_transcriptions.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioTranscriptionRequest::new(
"examples/data/problem.mp3".to_string(),
WHISPER_1.to_string(),
);
let result = client.audio_transcription(req).await?;
println!("{:?}", result);
Ok(())
}
examples/embedding.rs (line 9)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let mut req = EmbeddingRequest::new(
TEXT_EMBEDDING_3_SMALL.to_string(),
vec!["story time".to_string(), "Once upon a time".to_string()],
);
req.dimensions = Some(10);
let result = client.embedding(req).await?;
println!("{:?}", result.data);
Ok(())
}
examples/audio_speech.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = AudioSpeechRequest::new(
TTS_1.to_string(),
String::from("Money is not the problem, the problem is no money."),
audio::VOICE_ALLOY.to_string(),
String::from("examples/data/problem.mp3"),
);
let result = client.audio_speech(req).await?;
println!("{:?}", result);
Ok(())
}
examples/completion.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = CompletionRequest::new(
completion::GPT3_TEXT_DAVINCI_003.to_string(),
String::from("What is Bitcoin?"),
)
.max_tokens(3000)
.temperature(0.9)
.top_p(1.0)
.stop(vec![String::from(" Human:"), String::from(" AI:")])
.presence_penalty(0.6)
.frequency_penalty(0.0);
let result = client.completion(req).await?;
println!("{:}", result.choices[0].text);
Ok(())
}
examples/chat_completion.rs (line 9)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
let client = OpenAIClient::builder().with_api_key(api_key).build()?;
let req = ChatCompletionRequest::new(
GPT4_O_MINI.to_string(),
vec![chat_completion::ChatCompletionMessage {
role: chat_completion::MessageRole::user,
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);
let result = client.chat_completion(req).await?;
println!("Content: {:?}", result.choices[0].message.content);
println!("Response Headers: {:?}", result.headers);
Ok(())
}
Additional examples can be found in:
Trait Implementations§
Source§impl Default for OpenAIClientBuilder
impl Default for OpenAIClientBuilder
Source§fn default() -> OpenAIClientBuilder
fn default() -> OpenAIClientBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OpenAIClientBuilder
impl RefUnwindSafe for OpenAIClientBuilder
impl Send for OpenAIClientBuilder
impl Sync for OpenAIClientBuilder
impl Unpin for OpenAIClientBuilder
impl UnwindSafe for OpenAIClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more