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
//! An unofficial Rust client for [the OpenAI API](https://platform.openai.com/docs/api-reference).
//!
//! ## Feature flags
//! - [`audio`](`crate::audio`)
//! - [`chat`](`crate::chat`)
//!
//! > [!NOTE]
//! > You need to enable feature flags to use the corresponding APIs.
//!
//! ## Supported APIs
//! - [x] [Audio](https://platform.openai.com/docs/api-reference/audio)
//! - [x] [speech](https://platform.openai.com/docs/api-reference/audio/createSpeech)
//! - [x] [transcriptions](https://platform.openai.com/docs/api-reference/audio/createTranscription)
//! - [x] [translations](https://platform.openai.com/docs/api-reference/audio/createTranslation)
//! - [x] [Chat](https://platform.openai.com/docs/api-reference/chat)
//! - [x] [completions](https://platform.openai.com/docs/api-reference/chat/create)
//! - [x] [completions streaming](https://platform.openai.com/docs/api-reference/chat/create)
//! - [ ] [Embeddings](https://platform.openai.com/docs/api-reference/embeddings)
//! - [ ] [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning)
//! - [ ] [Files](https://platform.openai.com/docs/api-reference/files)
//! - [ ] [Images](https://platform.openai.com/docs/api-reference/images)
//! - [ ] [Models](https://platform.openai.com/docs/api-reference/models)
//! - [ ] [Moderations](https://platform.openai.com/docs/api-reference/moderations)
//!
//! Beta version APIs:
//! - [ ] [Assistants](https://platform.openai.com/docs/api-reference/assistants)
//! - [ ] [Threads](https://platform.openai.com/docs/api-reference/threads)
//! - [ ] [Messages](https://platform.openai.com/docs/api-reference/messages)
//! - [ ] [Runs](https://platform.openai.com/docs/api-reference/runs)
//!
//! ## Usage
//! 1. Enable API feature flags that you want to use, e.g. `chat`.
//! 2. Create a [Client](`crate::Client`) with the API key and the other optional settings.
//! 3. Use the client to call the APIs, e.g. [`Client::chat_complete`].
//!
//! See also examples in documents of each feature module for more details.
//!
//! ## Examples
//! An example to call the chat completions API with the `chat` feature flag:
//!
//! ```toml
//! [dependencies]
//! oaapi = { version = "0.2.0", features = ["chat"] }
//! ```
//!
//! and setting the API key to the environment variable :`OPENAI_API_KEY`
//!
//! ```env
//! OPENAI_API_KEY={your-openai-api-key}
//! ```
//!
//! 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(())
//! }
//! ```
//!
//! See also examples in documents of each feature module for more details.
// Re-exports
pub use crateApiKey;
pub use crateClient;
pub use crateApiError;
pub use crateApiErrorBody;
pub use crateClientError;
pub use crateErrorResponse;
pub use crateValidationError;
pub use crateOrganizationId;
pub use cratePrompt;
pub use crateValidationResult;
pub use crateTemperature;
// Third party re-exports
pub use reqwest;
pub use serde_json;
pub use subtp;
// Feature modules
// Internal modules
pub
// Private modules