1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! The chat APIs of the OpenAI API.
//!
//! ## NOTE
//! This is only available for `chat` feature flag.
//!
//! ## Supported APIs
//! - [x] [Completions](https://platform.openai.com/docs/api-reference/chat/create)
//! - [x] [Completions streaming](https://platform.openai.com/docs/api-reference/chat/create)
//!
//! ## Examples
//!
//! ### Completions
//! An example to call the chat completions API with the `chat` feature flag, `tokio` and `anyhow` crate is as follows:
//!
//! ```no_run
//! use oaapi::Client;
//! use oaapi::chat::CompletionsRequestBody;
//! use oaapi::chat::SystemMessage;
//! use oaapi::chat::UserMessage;
//! use oaapi::chat::ChatModel;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // 1. Create a client with the API key from the environment variable: "OPENAI_API_KEY"
//! let client = Client::from_env()?;
//! // or specify the API key directly.
//! // let client = Client::new(oaapi::ApiKey::new("OPENAI_API_KEY"), None, None);
//!
//! // 2. Create a request body parameters.
//! let request_body = CompletionsRequestBody {
//! messages: vec![
//! SystemMessage::new("Prompt.", None).into(),
//! UserMessage::new("Chat message from user.".into(), None).into(),
//! ],
//! model: ChatModel::Gpt35Turbo,
//! ..Default::default()
//! };
//!
//! // 3. Call the API.
//! let response = client
//! .chat_complete(request_body)
//! .await?;
//!
//! // 4. Use the response.
//! println!("Result:\n{}", response);
//!
//! Ok(())
//! }
//! ```
//!
//! ### Completions streaming
//! An example to call the chat completions streaming API with the `chat` feature flag, `tokio`, `anyhow` and `tokio_stream` crate is as follows:
//!
//! ```no_run
//! use oaapi::Client;
//! use oaapi::chat::CompletionsRequestBody;
//! use oaapi::chat::SystemMessage;
//! use oaapi::chat::UserMessage;
//! use oaapi::chat::ChatModel;
//! use oaapi::chat::StreamOption;
//!
//! use tokio_stream::StreamExt;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // 1. Create a client with the API key from the environment variable: "OPENAI_API_KEY"
//! let client = Client::from_env()?;
//! // or specify the API key directly.
//! // let client = Client::new(oaapi::ApiKey::new("OPENAI_API_KEY"), None, None);
//!
//! // 2. Create a request body parameters with specifying the streaming option: `StreamOption::ReturnStream`.
//! let request_body = CompletionsRequestBody {
//! messages: vec![
//! SystemMessage::new("Prompt.", None).into(),
//! UserMessage::new("Chat message from user.".into(), None).into(),
//! ],
//! model: ChatModel::Gpt35Turbo,
//! stream: Some(StreamOption::ReturnStream),
//! ..Default::default()
//! };
//!
//! // 3. Call the API.
//! let mut stream = client
//! .chat_complete_stream(request_body)
//! .await?;
//!
//! // 4. Receive the response stream.
//! while let Some(response) = stream.next().await {
//! // Do something with the response.
//! println!("Chunk:\n{}", response?);
//! }
//!
//! Ok(())
//! }
//! ```
pub use CompletionsRequestBody;
pub use AssistantMessage;
pub use CalledFunction;
pub use ToolCall;
pub use Bias;
pub use ChatCompletionChunkObject;
pub use ChatCompletionObject;
pub use ChatApiError;
pub use ChatChunkError;
pub use Logprobs;
pub use LogprobsContent;
pub use TopLogprobsContent;
pub use LogprobsOption;
pub use MaxTokens;
pub use Message;
pub use ChatModel;
pub use Penalty;
pub use ResponseFormat;
pub use ResponseFormatType;
pub use ChatApiResult;
pub use ChatChunkResult;
pub use Role;
pub use StopOption;
pub use StreamOption;
pub use SystemMessage;
pub use Function;
pub use Tool;
pub use ToolType;
pub use SpecifiedFunction;
pub use SpecifiedTool;
pub use TooChoiceOption;
pub use ToolChoice;
pub use ToolMessage;
pub use TopLogprobs;
pub use TopP;
pub use ImageContentPart;
pub use ImageDetail;
pub use ImageFormat;
pub use ImageUrl;
pub use MessageContent;
pub use MessageContentPart;
pub use TextContentPart;
pub use UserMessage;
pub use complete;
pub use complete_stream;