Skip to content

Commit 2f2d544

Browse files
author
Guantong
committed
Add Example
1 parent ef5b56b commit 2f2d544

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
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.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openai_api_rust"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
authors = ["i@guantong.dev"]
55
edition = "2021"
66
license = "MIT"

README.md

Lines changed: 2 additions & 3 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.3"
33+
openai_api_rust = "0.1.5"
3434
```
3535

3636
Export your API key into the environment variables
@@ -78,8 +78,7 @@ Load proxy from env
7878

7979
```rust
8080
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
81-
.use_env_proxy()
82-
.unwrap();
81+
.use_env_proxy();
8382
```
8483

8584
Set the proxy manually

src/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1+
//! Pull parser for [CommonMark](https://commonmark.org). This crate provides a [Parser](struct.Parser.html) struct
2+
//! which is an iterator over [Event](enum.Event.html)s. This iterator can be used
3+
//! directly, or to output HTML using the [HTML module](html/index.html).
4+
//!
5+
//! By default, only CommonMark features are enabled. To use extensions like tables,
6+
//! footnotes or task lists, enable them by setting the corresponding flags in the
7+
//! [Options](struct.Options.html) struct.
8+
//!
9+
//! # Example
10+
//! ```rust
11+
//! use openai_api_rust::*;
12+
//! use openai_api_rust::chat::*;
13+
//! use openai_api_rust::completions::*;
14+
//!
15+
//! fn main() {
16+
//! // Load API key from environment OPENAI_API_KEY.
17+
//! // You can also hadcode through `Auth::new(<your_api_key>)`, but it is not recommended.
18+
//! let auth = Auth::from_env().unwrap();
19+
//! let openai = OpenAI::new(auth, "https://api.openai.com/v1/");
20+
//! let body = ChatBody {
21+
//! model: "gpt-3.5-turbo".to_string(),
22+
//! max_tokens: Some(7),
23+
//! temperature: Some(0_f32),
24+
//! top_p: Some(0_f32),
25+
//! n: Some(2),
26+
//! stream: Some(false),
27+
//! stop: None,
28+
//! presence_penalty: None,
29+
//! frequency_penalty: None,
30+
//! logit_bias: None,
31+
//! user: None,
32+
//! messages: vec![Message { role: Role::User, content: "Hello!".to_string() }],
33+
//! };
34+
//! let rs = openai.chat_completion_create(&body);
35+
//! let choice = rs.unwrap().choices;
36+
//! let message = &choice[0].message.as_ref().unwrap();
37+
//! assert!(message.content.contains("Hello"));
38+
//! }
39+
//! ```
40+
//!
41+
//! ## Use proxy
42+
//!
43+
//! ```rust
44+
//! // Load proxy from env
45+
//! let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
46+
//! .use_env_proxy();
47+
//!
48+
//! // Set the proxy manually
49+
//! let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
50+
//! .set_proxy("http://127.0.0.1:1080");
51+
//! ```
52+
53+
54+
155
#![warn(unused_crate_dependencies)]
256

357
pub mod apis;

0 commit comments

Comments
 (0)