Skip to content

Commit 9b4225b

Browse files
authored
Upgrade dependencies and update doc links (#38)
* upgrade cargo dependencies * update use of base64 crate * update links from beta.openai.com to platform.openai.com
1 parent d96faab commit 9b4225b

File tree

10 files changed

+39
-36
lines changed

10 files changed

+39
-36
lines changed

async-openai/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ repository = "https://github.com/64bit/async-openai"
1717

1818
[dependencies]
1919
backoff = {version = "0.4.0", features = ["tokio"] }
20-
base64 = "0.20.0"
21-
futures = "0.3.25"
20+
base64 = "0.21.0"
21+
futures = "0.3.26"
2222
rand = "0.8.5"
23-
reqwest = { version = "0.11.13", features = ["json", "stream", "multipart"] }
23+
reqwest = { version = "0.11.14", features = ["json", "stream", "multipart"] }
2424
reqwest-eventsource = "0.4.0"
2525
serde = { version = "1.0.152", features = ["derive", "rc"] }
26-
serde_json = "1.0.91"
26+
serde_json = "1.0.93"
2727
thiserror = "1.0.38"
28-
tokio = { version = "1.23.0", features = ["fs", "macros"] }
28+
tokio = { version = "1.25.0", features = ["fs", "macros"] }
2929
tokio-stream = "0.1.11"
30-
tokio-util = { version = "0.7.4", features = ["codec", "io-util"] }
30+
tokio-util = { version = "0.7.7", features = ["codec", "io-util"] }
3131
tracing = "0.1.37"
3232
derive_builder = "0.12.0"
3333

async-openai/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
- [ ] Microsoft Azure Endpoints / AD Authentication (see [issue](https://github.com/64bit/async-openai/issues/32))
3333
- [x] Models
3434
- [x] Moderations
35-
- Non-streaming requests are retried with exponential backoff when [rate limited](https://help.openai.com/en/articles/5955598-is-api-usage-subject-to-any-rate-limits) by the API server.
35+
- Non-streaming requests are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits) by the API server.
3636
- Ergonomic Rust library with builder pattern for all request objects.
3737

3838
*Being a young project there could be rough edges.*
3939

4040
## Usage
4141

42-
The library reads [API key](https://beta.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`.
42+
The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`.
4343

4444
```bash
4545
# On macOS/Linux

async-openai/src/download.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::{Path, PathBuf};
22

3+
use base64::{engine::general_purpose, Engine as _};
34
use rand::{distributions::Alphanumeric, Rng};
45
use reqwest::Url;
56

@@ -69,7 +70,9 @@ pub(crate) async fn save_b64<P: AsRef<Path>>(b64: &str, dir: P) -> Result<PathBu
6970

7071
tokio::fs::write(
7172
path.as_path(),
72-
base64::decode(b64).map_err(|e| OpenAIError::FileSaveError(e.to_string()))?,
73+
general_purpose::STANDARD
74+
.decode(b64)
75+
.map_err(|e| OpenAIError::FileSaveError(e.to_string()))?,
7376
)
7477
.await
7578
.map_err(|e| OpenAIError::FileSaveError(e.to_string()))?;

async-openai/src/embedding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
/// Get a vector representation of a given input that can be easily
88
/// consumed by machine learning models and algorithms.
99
///
10-
/// Related guide: [Embeddings](https://beta.openai.com/docs/guides/embeddings/what-are-embeddings)
10+
/// Related guide: [Embeddings](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings)
1111
pub struct Embeddings<'c> {
1212
client: &'c Client,
1313
}

async-openai/src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
Client,
66
};
77

8-
/// Files are used to upload documents that can be used with features like [Fine-tuning](https://beta.openai.com/docs/api-reference/fine-tunes).
8+
/// Files are used to upload documents that can be used with features like [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tunes).
99
pub struct Files<'c> {
1010
client: &'c Client,
1111
}

async-openai/src/fine_tune.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99

1010
/// Manage fine-tuning jobs to tailor a model to your specific training data.
1111
///
12-
/// Related guide: [Fine-tune models](https://beta.openai.com/docs/guides/fine-tuning)
12+
/// Related guide: [Fine-tune models](https://platform.openai.com/docs/guides/fine-tuning)
1313
pub struct FineTunes<'c> {
1414
client: &'c Client,
1515
}
@@ -23,7 +23,7 @@ impl<'c> FineTunes<'c> {
2323
///
2424
/// Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
2525
///
26-
/// [Learn more about Fine-tuning](https://beta.openai.com/docs/guides/fine-tuning)
26+
/// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
2727
pub async fn create(&self, request: CreateFineTuneRequest) -> Result<FineTune, OpenAIError> {
2828
self.client.post("/fine-tunes", request).await
2929
}
@@ -35,7 +35,7 @@ impl<'c> FineTunes<'c> {
3535

3636
/// Gets info about the fine-tune job.
3737
///
38-
/// [Learn more about Fine-tuning](https://beta.openai.com/docs/guides/fine-tuning)
38+
/// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
3939
pub async fn retrieve(&self, fine_tune_id: &str) -> Result<FineTune, OpenAIError> {
4040
self.client
4141
.get(format!("/fine-tunes/{fine_tune_id}").as_str())

async-openai/src/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99

1010
/// Given a prompt and/or an input image, the model will generate a new image.
1111
///
12-
/// Related guide: [Image generation](https://beta.openai.com/docs/guides/images/introduction)
12+
/// Related guide: [Image generation](https://platform.openai.com/docs/guides/images/introduction)
1313
pub struct Images<'c> {
1414
client: &'c Client,
1515
}

async-openai/src/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
};
66

77
/// List and describe the various models available in the API.
8-
/// You can refer to the [Models](https://beta.openai.com/docs/models) documentation to understand what
8+
/// You can refer to the [Models](https://platform.openai.com/docs/models) documentation to understand what
99
/// models are available and the differences between them.
1010
pub struct Models<'c> {
1111
client: &'c Client,

async-openai/src/moderation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66

77
/// Given a input text, outputs if the model classifies it as violating OpenAI's content policy.
88
///
9-
/// Related guide: [Moderations](https://beta.openai.com/docs/guides/moderation/overview)
9+
/// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation/overview)
1010
pub struct Moderations<'c> {
1111
client: &'c Client,
1212
}

async-openai/src/types/types.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Stop {
4444
#[builder(derive(Debug))]
4545
#[builder(build_fn(error = "OpenAIError"))]
4646
pub struct CreateCompletionRequest {
47-
/// ID of the model to use. You can use the [List models](https://beta.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://beta.openai.com/docs/models/overview) for descriptions of them.
47+
/// ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
4848
pub model: String,
4949

5050
/// The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.
@@ -103,13 +103,13 @@ pub struct CreateCompletionRequest {
103103

104104
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
105105
///
106-
/// [See more information about frequency and presence penalties.](https://beta.openai.com/docs/api-reference/parameter-details)
106+
/// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
107107
#[serde(skip_serializing_if = "Option::is_none")]
108108
pub presence_penalty: Option<f32>, // min: -2.0, max: 2.0, default 0
109109

110110
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
111111
///
112-
/// [See more information about frequency and presence penalties.](https://beta.openai.com/docs/api-reference/parameter-details)
112+
/// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
113113
#[serde(skip_serializing_if = "Option::is_none")]
114114
pub frequency_penalty: Option<f32>, // min: -2.0, max: 2.0, default: 0
115115

@@ -129,7 +129,7 @@ pub struct CreateCompletionRequest {
129129
#[serde(skip_serializing_if = "Option::is_none")]
130130
pub logit_bias: Option<HashMap<String, serde_json::Value>>, // default: null
131131

132-
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://beta.openai.com/docs/usage-policies/end-user-ids).
132+
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids).
133133
#[serde(skip_serializing_if = "Option::is_none")]
134134
pub user: Option<String>,
135135
}
@@ -178,7 +178,7 @@ pub type CompletionResponseStream =
178178
#[builder(derive(Debug))]
179179
#[builder(build_fn(error = "OpenAIError"))]
180180
pub struct CreateEditRequest {
181-
/// ID of the model to use. You can use the [List models](https://beta.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://beta.openai.com/docs/models/overview) for descriptions of them.
181+
/// ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
182182
pub model: String,
183183

184184
/// The input text to use as a starting point for the edit.
@@ -257,7 +257,7 @@ pub struct CreateImageRequest {
257257
#[serde(skip_serializing_if = "Option::is_none")]
258258
pub response_format: Option<ResponseFormat>,
259259

260-
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://beta.openai.com/docs/usage-policies/end-user-ids).
260+
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids).
261261
#[serde(skip_serializing_if = "Option::is_none")]
262262
pub user: Option<String>,
263263
}
@@ -306,7 +306,7 @@ pub struct CreateImageEditRequest {
306306
/// The format in which the generated images are returned. Must be one of `url` or `b64_json`.
307307
pub response_format: Option<ResponseFormat>,
308308

309-
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://beta.openai.com/docs/usage-policies/end-user-ids).
309+
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids).
310310
pub user: Option<String>,
311311
}
312312

@@ -329,7 +329,7 @@ pub struct CreateImageVariationRequest {
329329
/// The format in which the generated images are returned. Must be one of `url` or `b64_json`.
330330
pub response_format: Option<ResponseFormat>,
331331

332-
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://beta.openai.com/docs/usage-policies/end-user-ids).
332+
/// A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids).
333333
pub user: Option<String>,
334334
}
335335

@@ -424,12 +424,12 @@ pub struct FileInput {
424424
pub struct CreateFileRequest {
425425
/// Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded.
426426
///
427-
/// If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your [training examples](https://beta.openai.com/docs/guides/fine-tuning/prepare-training-data).
427+
/// If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your [training examples](https://platform.openai.com/docs/guides/fine-tuning/prepare-training-data).
428428
pub file: FileInput,
429429

430430
/// The intended purpose of the uploaded documents.
431431
///
432-
/// Use "fine-tune" for [Fine-tuning](https://beta.openai.com/docs/api-reference/fine-tunes). This allows us to validate the format of the uploaded file.
432+
/// Use "fine-tune" for [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tunes). This allows us to validate the format of the uploaded file.
433433
pub purpose: String,
434434
}
435435

@@ -467,33 +467,33 @@ pub struct OpenAIFile {
467467
pub struct CreateFineTuneRequest {
468468
/// The ID of an uploaded file that contains training data.
469469
///
470-
/// See [upload file](https://beta.openai.com/docs/api-reference/files/upload) for how to upload a file.
470+
/// See [upload file](https://platform.openai.com/docs/api-reference/files/upload) for how to upload a file.
471471
///
472472
/// Your dataset must be formatted as a JSONL file, where each training
473473
/// example is a JSON object with the keys "prompt" and "completion".
474474
/// Additionally, you must upload your file with the purpose `fine-tune`.
475475
///
476-
/// See the [fine-tuning guide](https://beta.openai.com/docs/guides/fine-tuning/creating-training-data) for more details.
476+
/// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning/creating-training-data) for more details.
477477
pub training_file: String,
478478

479479
/// The ID of an uploaded file that contains validation data.
480480
///
481481
/// If you provide this file, the data is used to generate validation
482482
/// metrics periodically during fine-tuning. These metrics can be viewed in
483-
/// the [fine-tuning results file](https://beta.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model).
483+
/// the [fine-tuning results file](https://platform.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model).
484484
/// Your train and validation data should be mutually exclusive.
485485
///
486486
/// Your dataset must be formatted as a JSONL file, where each validation
487487
/// example is a JSON object with the keys "prompt" and "completion".
488488
/// Additionally, you must upload your file with the purpose `fine-tune`.
489489
///
490-
/// See the [fine-tuning guide](https://beta.openai.com/docs/guides/fine-tuning/creating-training-data) for more details.
490+
/// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning/creating-training-data) for more details.
491491
#[serde(skip_serializing_if = "Option::is_none")]
492492
pub validation_file: Option<String>,
493493

494494
/// The name of the base model to fine-tune. You can select one of "ada",
495495
/// "babbage", "curie", "davinci", or a fine-tuned model created after 2022-04-21.
496-
/// To learn more about these models, see the [Models](https://beta.openai.com/docs/models) documentation.
496+
/// To learn more about these models, see the [Models](https://platform.openai.com/docs/models) documentation.
497497
#[serde(skip_serializing_if = "Option::is_none")]
498498
pub model: Option<String>,
499499

@@ -537,7 +537,7 @@ pub struct CreateFineTuneRequest {
537537

538538
/// If set, we calculate classification-specific metrics such as accuracy
539539
/// and F-1 score using the validation set at the end of every epoch.
540-
/// These metrics can be viewed in the [results file](https://beta.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model).
540+
/// These metrics can be viewed in the [results file](https://platform.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model).
541541
///
542542
/// In order to compute classification metrics, you must provide a
543543
/// `validation_file`. Additionally, you must
@@ -643,9 +643,9 @@ pub enum EmbeddingInput {
643643
#[builder(build_fn(error = "OpenAIError"))]
644644
pub struct CreateEmbeddingRequest {
645645
/// ID of the model to use. You can use the
646-
/// [List models](https://beta.openai.com/docs/api-reference/models/list)
646+
/// [List models](https://platform.openai.com/docs/api-reference/models/list)
647647
/// API to see all of your available models, or see our
648-
/// [Model overview](https://beta.openai.com/docs/models/overview)
648+
/// [Model overview](https://platform.openai.com/docs/models/overview)
649649
/// for descriptions of them.
650650
pub model: String,
651651

@@ -656,7 +656,7 @@ pub struct CreateEmbeddingRequest {
656656
pub input: EmbeddingInput,
657657

658658
/// A unique identifier representing your end-user, which will help OpenAI
659-
/// to monitor and detect abuse. [Learn more](https://beta.openai.com/docs/usage-policies/end-user-ids).
659+
/// to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids).
660660
#[serde(skip_serializing_if = "Option::is_none")]
661661
pub user: Option<String>,
662662
}

0 commit comments

Comments
 (0)