|
54 | 54 | //! # }); |
55 | 55 | //!``` |
56 | 56 | //! |
57 | | -//! ## Bring Your Own Types |
| 57 | +//! ## OpenAI Compatible Providers |
| 58 | +//! |
| 59 | +//! Even though the scope of the crate is official OpenAI APIs, it is very configurable to work with compatible providers. |
| 60 | +//! |
| 61 | +//! ### Bring Your Own Types |
58 | 62 | //! |
59 | 63 | //! To use custom types for inputs and outputs, enable `byot` feature which provides additional generic methods with same name and `_byot` suffix. |
60 | 64 | //! This feature is available on methods whose return type is not `Bytes` |
|
109 | 113 | //! # }); |
110 | 114 | //! ``` |
111 | 115 | //! |
112 | | -//! ## Rust Types |
113 | | -//! |
114 | | -//! To only use Rust types from the crate - use feature flag `types`. |
115 | | -//! |
116 | | -//! There are granular feature flags like `response-types`, `chat-completion-types`, etc. |
| 116 | +//! ### Configurable Requests |
| 117 | +//! Configure path, headers, and query parameters for a HTTP request. |
117 | 118 | //! |
118 | | -//! These granular types are enabled when the corresponding API feature is enabled - for example `responses` will enable `response-types`. |
| 119 | +//! **Request Options** |
119 | 120 | //! |
120 | | -//! ## WASM |
121 | | -//! WASM is supported for all APIs. |
122 | | -//! See [examples/wasm-responses](https://github.com/64bit/async-openai/tree/main/examples/wasm-responses) or [examples/tower-wasm](https://github.com/64bit/async-openai/tree/main/examples/tower-wasm). |
| 121 | +//! Use `path()`, `.query()`, `.header()`, `.headers()` on the API group. Path overrides the default path but all other methods are additive - adds to existing query or headers. |
123 | 122 | //! |
124 | | -//! ## Configurable Requests |
125 | | -//! |
126 | | -//! **Individual Request** |
127 | | -//! |
128 | | -//! Certain individual APIs that need additional query or header parameters - these can be provided by chaining `.query()`, `.header()`, `.headers()` on the API group. |
129 | | -//! |
130 | | -//! For example: |
| 123 | +//! For demonstration: |
131 | 124 | //! ``` |
132 | 125 | //! # tokio_test::block_on(async { |
133 | 126 | //! # use async_openai::Client; |
134 | 127 | //! # use async_openai::traits::RequestOptionsBuilder; |
135 | 128 | //! # let client = Client::new(); |
136 | 129 | //! client |
137 | 130 | //! .chat() |
138 | | -//! // query can be a struct or a map too. |
| 131 | +//! // override default path |
| 132 | +//! .path("/v1/messages") |
| 133 | +//! // query can be a struct or a map too - additive |
139 | 134 | //! .query(&[("limit", "10")])? |
140 | | -//! // header for demo |
141 | | -//! .header("key", "value")? |
| 135 | +//! // header for unique id for this API request - additive |
| 136 | +//! .header("x-request-id", "id123")? |
142 | 137 | //! .list() |
143 | 138 | //! .await?; |
144 | 139 | //! # Ok::<(), Box<dyn std::error::Error>>(()) |
145 | 140 | //! # }); |
146 | 141 | //! ``` |
147 | 142 | //! |
148 | | -//! **All Requests** |
| 143 | +//! **Modifying all Requests** |
149 | 144 | //! |
150 | 145 | //! Use `Config`, `OpenAIConfig` etc. for configuring url, headers or query parameters globally for all requests. |
151 | 146 | //! |
152 | | -//! ## OpenAI-compatible Providers |
153 | | -//! |
154 | | -//! Even though the scope of the crate is official OpenAI APIs, it is very configurable to work with compatible providers. |
155 | | -//! |
156 | | -//! **Configurable Path** |
157 | | -//! |
158 | | -//! In addition to `.query()`, `.header()`, `.headers()` a path for individual request can be changed by using `.path()`, method on the API group. |
159 | | -//! |
160 | | -//! For example: |
161 | | -//! ``` |
162 | | -//! # tokio_test::block_on(async { |
163 | | -//! # use async_openai::{Client, types::chat::CreateChatCompletionRequestArgs}; |
164 | | -//! # use async_openai::traits::RequestOptionsBuilder; |
165 | | -//! # let client = Client::new(); |
166 | | -//! # let request = CreateChatCompletionRequestArgs::default() |
167 | | -//! # .model("gpt-4") |
168 | | -//! # .messages([]) |
169 | | -//! # .build() |
170 | | -//! # .unwrap(); |
171 | | -//! client |
172 | | -//! .chat() |
173 | | -//! .path("/v1/messages")? |
174 | | -//! .create(request) |
175 | | -//! .await?; |
176 | | -//! # Ok::<(), Box<dyn std::error::Error>>(()) |
177 | | -//! # }); |
178 | | -//! ``` |
179 | 147 | //! |
180 | 148 | //! **Dynamic Dispatch** |
181 | 149 | //! |
|
199 | 167 | //! } |
200 | 168 | //! ``` |
201 | 169 | //! |
202 | | -//! ## Microsoft Azure |
| 170 | +//! ### Microsoft Azure |
203 | 171 | //! |
204 | 172 | //! ``` |
205 | 173 | //! use async_openai::{Client, config::AzureConfig}; |
|
212 | 180 | //! |
213 | 181 | //! let client = Client::with_config(config); |
214 | 182 | //! |
215 | | -//! // Note that `async-openai` only implements OpenAI spec |
216 | | -//! // and doesn't maintain parity with the spec of Azure OpenAI service. |
217 | 183 | //! |
218 | 184 | //! ``` |
219 | 185 | //! |
220 | 186 | //! |
| 187 | +//! ## Rust Types |
| 188 | +//! |
| 189 | +//! To only use Rust types from the crate - use feature flag `types`. |
| 190 | +//! |
| 191 | +//! There are granular feature flags like `response-types`, `chat-completion-types`, etc. |
| 192 | +//! |
| 193 | +//! These granular types are enabled when the corresponding API feature is enabled - for example `responses` will enable `response-types`. |
| 194 | +//! |
| 195 | +//! ## WASM |
| 196 | +//! WASM is supported for all APIs. |
| 197 | +//! See [examples/wasm-responses](https://github.com/64bit/async-openai/tree/main/examples/wasm-responses) or [examples/tower-wasm](https://github.com/64bit/async-openai/tree/main/examples/tower-wasm). |
| 198 | +//! |
| 199 | +//! |
221 | 200 | //! ## Middleware |
222 | 201 | //! |
223 | 202 | //! Middleware is supported via Tower ecosystem. See [`middleware`] for more detail. |
|
0 commit comments