diff --git a/async-openai/Cargo.toml b/async-openai/Cargo.toml index 1ebb17f1..a80f9d06 100644 --- a/async-openai/Cargo.toml +++ b/async-openai/Cargo.toml @@ -17,17 +17,17 @@ repository = "https://github.com/64bit/async-openai" [dependencies] backoff = {version = "0.4.0", features = ["tokio"] } -base64 = "0.20.0" -futures = "0.3.25" +base64 = "0.21.0" +futures = "0.3.26" rand = "0.8.5" -reqwest = { version = "0.11.13", features = ["json", "stream", "multipart"] } +reqwest = { version = "0.11.14", features = ["json", "stream", "multipart"] } reqwest-eventsource = "0.4.0" serde = { version = "1.0.152", features = ["derive", "rc"] } -serde_json = "1.0.91" +serde_json = "1.0.93" thiserror = "1.0.38" -tokio = { version = "1.23.0", features = ["fs", "macros"] } +tokio = { version = "1.25.0", features = ["fs", "macros"] } tokio-stream = "0.1.11" -tokio-util = { version = "0.7.4", features = ["codec", "io-util"] } +tokio-util = { version = "0.7.7", features = ["codec", "io-util"] } tracing = "0.1.37" derive_builder = "0.12.0" diff --git a/async-openai/README.md b/async-openai/README.md index b61799e3..8eaf005a 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -32,14 +32,14 @@ - [ ] Microsoft Azure Endpoints / AD Authentication (see [issue](https://github.com/64bit/async-openai/issues/32)) - [x] Models - [x] Moderations -- 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. +- Non-streaming requests are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits) by the API server. - Ergonomic Rust library with builder pattern for all request objects. *Being a young project there could be rough edges.* ## Usage -The library reads [API key](https://beta.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`. +The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`. ```bash # On macOS/Linux diff --git a/async-openai/src/download.rs b/async-openai/src/download.rs index c0029e9a..1b17c856 100644 --- a/async-openai/src/download.rs +++ b/async-openai/src/download.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; +use base64::{engine::general_purpose, Engine as _}; use rand::{distributions::Alphanumeric, Rng}; use reqwest::Url; @@ -69,7 +70,9 @@ pub(crate) async fn save_b64>(b64: &str, dir: P) -> Result { client: &'c Client, } diff --git a/async-openai/src/file.rs b/async-openai/src/file.rs index 23378323..b418f492 100644 --- a/async-openai/src/file.rs +++ b/async-openai/src/file.rs @@ -5,7 +5,7 @@ use crate::{ Client, }; -/// Files are used to upload documents that can be used with features like [Fine-tuning](https://beta.openai.com/docs/api-reference/fine-tunes). +/// Files are used to upload documents that can be used with features like [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tunes). pub struct Files<'c> { client: &'c Client, } diff --git a/async-openai/src/fine_tune.rs b/async-openai/src/fine_tune.rs index b4f0c954..a4a771b9 100644 --- a/async-openai/src/fine_tune.rs +++ b/async-openai/src/fine_tune.rs @@ -9,7 +9,7 @@ use crate::{ /// Manage fine-tuning jobs to tailor a model to your specific training data. /// -/// Related guide: [Fine-tune models](https://beta.openai.com/docs/guides/fine-tuning) +/// Related guide: [Fine-tune models](https://platform.openai.com/docs/guides/fine-tuning) pub struct FineTunes<'c> { client: &'c Client, } @@ -23,7 +23,7 @@ impl<'c> FineTunes<'c> { /// /// Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. /// - /// [Learn more about Fine-tuning](https://beta.openai.com/docs/guides/fine-tuning) + /// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) pub async fn create(&self, request: CreateFineTuneRequest) -> Result { self.client.post("/fine-tunes", request).await } @@ -35,7 +35,7 @@ impl<'c> FineTunes<'c> { /// Gets info about the fine-tune job. /// - /// [Learn more about Fine-tuning](https://beta.openai.com/docs/guides/fine-tuning) + /// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) pub async fn retrieve(&self, fine_tune_id: &str) -> Result { self.client .get(format!("/fine-tunes/{fine_tune_id}").as_str()) diff --git a/async-openai/src/image.rs b/async-openai/src/image.rs index 5c3705d0..f315654d 100644 --- a/async-openai/src/image.rs +++ b/async-openai/src/image.rs @@ -9,7 +9,7 @@ use crate::{ /// Given a prompt and/or an input image, the model will generate a new image. /// -/// Related guide: [Image generation](https://beta.openai.com/docs/guides/images/introduction) +/// Related guide: [Image generation](https://platform.openai.com/docs/guides/images/introduction) pub struct Images<'c> { client: &'c Client, } diff --git a/async-openai/src/model.rs b/async-openai/src/model.rs index 63d9a91c..f040b30f 100644 --- a/async-openai/src/model.rs +++ b/async-openai/src/model.rs @@ -5,7 +5,7 @@ use crate::{ }; /// List and describe the various models available in the API. -/// You can refer to the [Models](https://beta.openai.com/docs/models) documentation to understand what +/// You can refer to the [Models](https://platform.openai.com/docs/models) documentation to understand what /// models are available and the differences between them. pub struct Models<'c> { client: &'c Client, diff --git a/async-openai/src/moderation.rs b/async-openai/src/moderation.rs index 87608ae5..039ce882 100644 --- a/async-openai/src/moderation.rs +++ b/async-openai/src/moderation.rs @@ -6,7 +6,7 @@ use crate::{ /// Given a input text, outputs if the model classifies it as violating OpenAI's content policy. /// -/// Related guide: [Moderations](https://beta.openai.com/docs/guides/moderation/overview) +/// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation/overview) pub struct Moderations<'c> { client: &'c Client, } diff --git a/async-openai/src/types/types.rs b/async-openai/src/types/types.rs index 44b5d4b3..18827a5e 100644 --- a/async-openai/src/types/types.rs +++ b/async-openai/src/types/types.rs @@ -44,7 +44,7 @@ pub enum Stop { #[builder(derive(Debug))] #[builder(build_fn(error = "OpenAIError"))] pub struct CreateCompletionRequest { - /// 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. + /// 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. pub model: String, /// 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 { /// 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. /// - /// [See more information about frequency and presence penalties.](https://beta.openai.com/docs/api-reference/parameter-details) + /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details) #[serde(skip_serializing_if = "Option::is_none")] pub presence_penalty: Option, // min: -2.0, max: 2.0, default 0 /// 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. /// - /// [See more information about frequency and presence penalties.](https://beta.openai.com/docs/api-reference/parameter-details) + /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details) #[serde(skip_serializing_if = "Option::is_none")] pub frequency_penalty: Option, // min: -2.0, max: 2.0, default: 0 @@ -129,7 +129,7 @@ pub struct CreateCompletionRequest { #[serde(skip_serializing_if = "Option::is_none")] pub logit_bias: Option>, // default: null - /// 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). + /// 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). #[serde(skip_serializing_if = "Option::is_none")] pub user: Option, } @@ -178,7 +178,7 @@ pub type CompletionResponseStream = #[builder(derive(Debug))] #[builder(build_fn(error = "OpenAIError"))] pub struct CreateEditRequest { - /// 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. + /// 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. pub model: String, /// The input text to use as a starting point for the edit. @@ -257,7 +257,7 @@ pub struct CreateImageRequest { #[serde(skip_serializing_if = "Option::is_none")] pub response_format: Option, - /// 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). + /// 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). #[serde(skip_serializing_if = "Option::is_none")] pub user: Option, } @@ -306,7 +306,7 @@ pub struct CreateImageEditRequest { /// The format in which the generated images are returned. Must be one of `url` or `b64_json`. pub response_format: Option, - /// 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). + /// 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). pub user: Option, } @@ -329,7 +329,7 @@ pub struct CreateImageVariationRequest { /// The format in which the generated images are returned. Must be one of `url` or `b64_json`. pub response_format: Option, - /// 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). + /// 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). pub user: Option, } @@ -424,12 +424,12 @@ pub struct FileInput { pub struct CreateFileRequest { /// Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. /// - /// 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). + /// 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). pub file: FileInput, /// The intended purpose of the uploaded documents. /// - /// 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. + /// 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. pub purpose: String, } @@ -467,33 +467,33 @@ pub struct OpenAIFile { pub struct CreateFineTuneRequest { /// The ID of an uploaded file that contains training data. /// - /// See [upload file](https://beta.openai.com/docs/api-reference/files/upload) for how to upload a file. + /// See [upload file](https://platform.openai.com/docs/api-reference/files/upload) for how to upload a file. /// /// Your dataset must be formatted as a JSONL file, where each training /// example is a JSON object with the keys "prompt" and "completion". /// Additionally, you must upload your file with the purpose `fine-tune`. /// - /// See the [fine-tuning guide](https://beta.openai.com/docs/guides/fine-tuning/creating-training-data) for more details. + /// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning/creating-training-data) for more details. pub training_file: String, /// The ID of an uploaded file that contains validation data. /// /// If you provide this file, the data is used to generate validation /// metrics periodically during fine-tuning. These metrics can be viewed in - /// the [fine-tuning results file](https://beta.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). + /// the [fine-tuning results file](https://platform.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). /// Your train and validation data should be mutually exclusive. /// /// Your dataset must be formatted as a JSONL file, where each validation /// example is a JSON object with the keys "prompt" and "completion". /// Additionally, you must upload your file with the purpose `fine-tune`. /// - /// See the [fine-tuning guide](https://beta.openai.com/docs/guides/fine-tuning/creating-training-data) for more details. + /// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning/creating-training-data) for more details. #[serde(skip_serializing_if = "Option::is_none")] pub validation_file: Option, /// The name of the base model to fine-tune. You can select one of "ada", /// "babbage", "curie", "davinci", or a fine-tuned model created after 2022-04-21. - /// To learn more about these models, see the [Models](https://beta.openai.com/docs/models) documentation. + /// To learn more about these models, see the [Models](https://platform.openai.com/docs/models) documentation. #[serde(skip_serializing_if = "Option::is_none")] pub model: Option, @@ -537,7 +537,7 @@ pub struct CreateFineTuneRequest { /// If set, we calculate classification-specific metrics such as accuracy /// and F-1 score using the validation set at the end of every epoch. - /// These metrics can be viewed in the [results file](https://beta.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). + /// These metrics can be viewed in the [results file](https://platform.openai.com/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). /// /// In order to compute classification metrics, you must provide a /// `validation_file`. Additionally, you must @@ -643,9 +643,9 @@ pub enum EmbeddingInput { #[builder(build_fn(error = "OpenAIError"))] pub struct CreateEmbeddingRequest { /// ID of the model to use. You can use the - /// [List models](https://beta.openai.com/docs/api-reference/models/list) + /// [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://beta.openai.com/docs/models/overview) + /// [Model overview](https://platform.openai.com/docs/models/overview) /// for descriptions of them. pub model: String, @@ -656,7 +656,7 @@ pub struct CreateEmbeddingRequest { pub input: EmbeddingInput, /// 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). + /// to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/usage-policies/end-user-ids). #[serde(skip_serializing_if = "Option::is_none")] pub user: Option, }