Skip to content

Commit df82373

Browse files
authored
Merge pull request #84 from dongri/fix-readme
Fix readme
2 parents 6553ba3 + 91fdaf3 commit df82373

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,32 @@ The library needs to be configured with your account's secret key, which is avai
1818
$ export OPENAI_API_KEY=sk-xxxxxxx
1919
```
2020

21-
### Set OPENAI_API_BASE to environment variable (optional)
22-
```bash
23-
$ export OPENAI_API_BASE=https://api.openai.com/v1
24-
```
25-
2621
### Create client
2722
```rust
28-
use openai_api_rs::v1::api::Client;
29-
use std::env;
3023
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
3124
```
3225

3326
### Create request
3427
```rust
35-
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
36-
use openai_api_rs::v1::common::GPT4;
3728
let req = ChatCompletionRequest::new(
3829
GPT4.to_string(),
3930
vec![chat_completion::ChatCompletionMessage {
4031
role: chat_completion::MessageRole::user,
41-
content: chat_completion::Content::Text(String::from("Hello OpenAI!")),
32+
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
4233
name: None,
4334
}],
4435
);
4536
```
4637

4738
### Send request
4839
```rust
49-
let result = client.completion(req)?;
50-
println!("{:?}", result.choices[0].text);
40+
let result = client.chat_completion(req)?;
41+
println!("Content: {:?}", result.choices[0].message.content);
42+
```
43+
44+
### Set OPENAI_API_BASE to environment variable (optional)
45+
```bash
46+
$ export OPENAI_API_BASE=https://api.openai.com/v1
5147
```
5248

5349
## Example of chat completion
@@ -59,16 +55,20 @@ use std::env;
5955

6056
fn main() -> Result<(), Box<dyn std::error::Error>> {
6157
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().to_string());
58+
6259
let req = ChatCompletionRequest::new(
6360
GPT4.to_string(),
6461
vec![chat_completion::ChatCompletionMessage {
6562
role: chat_completion::MessageRole::user,
66-
content: chat_completion::Content::Text(String::from("What is Bitcoin?")),
63+
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
6764
name: None,
6865
}],
6966
);
67+
7068
let result = client.chat_completion(req)?;
71-
println!("{:?}", result.choices[0].message.content);
69+
println!("Content: {:?}", result.choices[0].message.content);
70+
println!("Response Headers: {:?}", result.headers);
71+
7272
Ok(())
7373
}
7474
```

0 commit comments

Comments
 (0)