mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-12-03 11:08:23 +00:00
* use reqwest
* support multipart form * fix audio apits
This commit is contained in:
11
README.md
11
README.md
@@ -7,7 +7,7 @@ Check out the [docs.rs](https://docs.rs/openai-api-rs/).
|
||||
Cargo.toml
|
||||
```toml
|
||||
[dependencies]
|
||||
openai-api-rs = "4.1.1"
|
||||
openai-api-rs = "5.0.0"
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -48,13 +48,14 @@ $ export OPENAI_API_BASE=https://api.openai.com/v1
|
||||
|
||||
## Example of chat completion
|
||||
```rust
|
||||
use openai_api_rs::v1::api::Client;
|
||||
use openai_api_rs::v1::api::OpenAIClient;
|
||||
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
|
||||
use openai_api_rs::v1::common::GPT4_O;
|
||||
use std::env;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = OpenAIClient::new(env::var("OPENAI_API_KEY").unwrap().to_string());
|
||||
|
||||
let req = ChatCompletionRequest::new(
|
||||
GPT4_O.to_string(),
|
||||
@@ -65,7 +66,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}],
|
||||
);
|
||||
|
||||
let result = client.chat_completion(req)?;
|
||||
let result = client.chat_completion(req).await?;
|
||||
println!("Content: {:?}", result.choices[0].message.content);
|
||||
println!("Response Headers: {:?}", result.headers);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user