Skip to content

Commit d3fa489

Browse files
author
Guantong
committed
Update readme
1 parent adac74e commit d3fa489

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ___
3030
Add the following to your Cargo.toml file:
3131

3232
```toml
33-
openai_api_rust = "0.1.1"
33+
openai_api_rust = "0.1.3"
3434
```
3535

3636
Export your API key into the environment variables
@@ -43,33 +43,39 @@ Then use the crate in your Rust code:
4343

4444
```rust
4545
use openai_api_rust::*;
46-
use openai_api_rust::edits::*;
46+
use openai_api_rust::chat::*;
47+
use openai_api_rust::completions::*;
4748

4849
fn main() {
4950
// Load API key from environment OPENAI_API_KEY.
5051
// You can also hadcode through `Auth::new(<your_api_key>)`, but it is not recommended.
5152
let auth = Auth::from_env().unwrap();
5253
let openai = OpenAI::new(auth, "https://api.openai.com/v1/");
53-
let body = EditsBody {
54-
model: "text-davinci-edit-001".to_string(),
55-
temperature: None,
56-
top_p: None,
54+
let body = ChatBody {
55+
model: "gpt-3.5-turbo".to_string(),
56+
max_tokens: Some(7),
57+
temperature: Some(0_f32),
58+
top_p: Some(0_f32),
5759
n: Some(2),
58-
instruction: "Fix the spelling mistakes".to_string(),
59-
input: Some("What day of the wek is it?".to_string()),
60+
stream: Some(false),
61+
stop: None,
62+
presence_penalty: None,
63+
frequency_penalty: None,
64+
logit_bias: None,
65+
user: None,
66+
messages: vec![Message {
67+
role: Some("user".to_string()),
68+
content: Some("Hello!".to_string()),
69+
}],
6070
};
61-
let rs = openai.edit_create(&body).unwrap();
62-
let choice = rs.choices.get(0).unwrap();
63-
println!("choice: {:?}", choice.text);
71+
let rs = openai.chat_completion_create(&body);
72+
let choice = rs.unwrap().choices;
73+
let message = &choice[0].message.as_ref().unwrap();
74+
let content = message.content.as_ref().unwrap();
75+
assert!(content.contains("Hello"));
6476
}
6577
```
6678

67-
Output:
68-
69-
```bash
70-
choice: Some("What day of the week is it?\n")
71-
```
72-
7379
### Use proxy
7480

7581
Load proxy from env

0 commit comments

Comments
 (0)