Struct openai_rs_api::core::OpenAI
source · pub struct OpenAI {
pub token: String,
pub oia_org: String,
/* private fields */
}Fields§
§token: String§oia_org: StringImplementations§
source§impl OpenAI
impl OpenAI
sourcepub fn new(token: String, oia_org: String) -> Self
pub fn new(token: String, oia_org: String) -> Self
The function creates a new instance of the OpenAI struct with the provided token and organization, along with an HTTPS client.
Arguments:
token: Thetokenparameter is a string that represents the authentication token used to access the OpenAI API. This token is typically provided by OpenAI when you sign up for their services.oia_org: Theoia_orgparameter represents the OpenAI organization ID. It is used to identify the organization associated with the API token being used.
Returns:
The new function returns an instance of the OpenAI struct.
sourcepub async fn list_models(self) -> Result<ModelList, Box<dyn Error>>
pub async fn list_models(self) -> Result<ModelList, Box<dyn Error>>
The function list_models sends a GET request to the OpenAI API to retrieve a list of models
and returns the parsed response as a ModelList object.
Returns:
a Result object with the type ModelList.
sourcepub async fn retrive_model(self, model: String) -> Result<Model, Box<dyn Error>>
pub async fn retrive_model(self, model: String) -> Result<Model, Box<dyn Error>>
The function retrieves a model from the OpenAI API using an HTTPS client and returns the parsed model response.
Arguments:
model: Themodelparameter is aStringthat represents the name of the model you want to retrieve. It is used to construct the URL for the API request.
Returns:
a Result object with the type Model as the Ok variant and Box
sourcepub async fn create_chat_completions(
self,
parameters: ChatParameters
) -> Result<ChatResponse, Box<dyn Error>>
pub async fn create_chat_completions( self, parameters: ChatParameters ) -> Result<ChatResponse, Box<dyn Error>>
The function create_chat_completions sends a POST request to the OpenAI API to generate chat completions
based on the given parameters.
Arguments:
parameters: Theparametersparameter in thecreate_chat_completionsfunction is of typeChatParameters. It is an input parameter that contains the information required to generate chat completions using the OpenAI API.
Returns:
a Result with a ChatResponse on success or a Box<dyn Error> on failure.
sourcepub async fn create_completions(
self,
parameters: CompletionParameters
) -> Result<CompletionResponse, Box<dyn Error>>
pub async fn create_completions( self, parameters: CompletionParameters ) -> Result<CompletionResponse, Box<dyn Error>>
The function create_completions sends a POST request to the OpenAI API to generate completions
based on the given parameters.
Arguments:
parameters: Theparametersparameter in thecreate_completionsfunction is of typeCompletionParameters. It is an input parameter that contains the information required to generate completions using the OpenAI API.
Returns:
a Result with a CompletionResponse on success or a Box<dyn Error> on failure.
sourcepub async fn create_edit(
self,
parameters: EditParameters
) -> Result<EditResponse, Box<dyn Error>>
pub async fn create_edit( self, parameters: EditParameters ) -> Result<EditResponse, Box<dyn Error>>
The function create_edit sends a POST request to the OpenAI API to create or edit a completion
and returns the response.
Arguments:
parameters: Theparametersparameter in thecreate_editfunction is of typeEditParameters. It is an input parameter that contains the necessary information for creating an edit. The specific fields and their meanings depend on the implementation of theEditParametersstruct. You would need to refer to the definition
Returns:
a Result with the type EditResponse on success or a Box<dyn Error> on failure.
sourcepub async fn create_image(
self,
parameters: ImageCreateParameters
) -> Result<ImageResponse, Box<dyn Error>>
pub async fn create_image( self, parameters: ImageCreateParameters ) -> Result<ImageResponse, Box<dyn Error>>
The create_image function sends a POST request to the OpenAI API to generate an image based on
the provided parameters.
Arguments:
parameters: Theparametersparameter in thecreate_imagefunction is of typeImageCreateParameters. It is an input parameter that contains the necessary information for generating an image.
Returns:
The function create_image returns a Result enum with the success case containing an
ImageResponse and the error case containing a Box<dyn Error>.
sourcepub async fn create_image_edit(
self,
parameters: ImageEditParameters
) -> Result<ImageResponse, Box<dyn Error>>
pub async fn create_image_edit( self, parameters: ImageEditParameters ) -> Result<ImageResponse, Box<dyn Error>>
The function create_image_edit sends a POST request to the OpenAI API to create an image edit,
using the provided parameters, and returns the resulting image response.
Arguments:
parameters: Theparametersparameter in thecreate_image_editfunction is of typeImageEditParameters. It is an input parameter that contains the necessary information for creating an image edit.
Returns:
a Result type with the success variant containing an ImageResponse or the error variant
containing a Box
sourcepub async fn create_image_variations(
self,
parameters: ImageVariationParameters
) -> Result<ImageResponse, Box<dyn Error>>
pub async fn create_image_variations( self, parameters: ImageVariationParameters ) -> Result<ImageResponse, Box<dyn Error>>
The function create_image_variations sends a POST request to the OpenAI API to create image
variations based on the provided parameters.
Arguments:
parameters: Theparametersparameter in thecreate_image_variationsfunction is of typeImageVariationParameters. It is an input parameter that contains the necessary information for creating image variations.
Returns:
a Result object with the type ImageResponse.
sourcepub async fn create_embedding(
self,
parameters: EmbeddingParameters
) -> Result<EmbeddingResponse, Box<dyn Error>>
pub async fn create_embedding( self, parameters: EmbeddingParameters ) -> Result<EmbeddingResponse, Box<dyn Error>>
The function create_embedding sends a POST request to the OpenAI API to create an embedding,
using the provided parameters, and returns the resulting embedding response.
Arguments:
parameters: Theparametersparameter in thecreate_embeddingfunction is of typeEmbeddingParameters. It is an input parameter that contains the necessary information for creating an embedding.
Returns:
a Result type with the success variant containing an EmbeddingResponse or the error variant
containing a Box
sourcepub async fn create_transcription(
self,
parameters: TranscriptionParameters
) -> Result<TextResponse, Box<dyn Error>>
pub async fn create_transcription( self, parameters: TranscriptionParameters ) -> Result<TextResponse, Box<dyn Error>>
The function create_transcription sends a POST request to the OpenAI API to create a transcription,
using the provided parameters, and returns the resulting transcription response.
Arguments:
parameters: Theparametersparameter in thecreate_transcriptionfunction is of typeTranscriptionParameters. It is an input parameter that contains the necessary information for creating a transcription.
Returns:
a Result type with the success variant containing a TextResponse or the error variant
containing a Box
sourcepub async fn create_translation(
self,
parameters: TranslationParameters
) -> Result<TextResponse, Box<dyn Error>>
pub async fn create_translation( self, parameters: TranslationParameters ) -> Result<TextResponse, Box<dyn Error>>
The function create_translation sends a POST request to the OpenAI API to create a translation,
using the provided parameters, and returns the resulting translation response.
Arguments:
parameters: Theparametersparameter in thecreate_translationfunction is of typeTranslationParameters. It is an input parameter that contains the necessary information for creating a translation.
Returns:
a Result type with the success variant containing a TextResponse or the error variant
containing a Box
sourcepub async fn list_files(self) -> Result<FileList, Box<dyn Error>>
pub async fn list_files(self) -> Result<FileList, Box<dyn Error>>
The function list_files makes an asynchronous HTTP GET request to the OpenAI API to retrieve a
list of files and returns the parsed result.
Returns:
The function list_files returns a Result containing either a FileList or a boxed dynamic
error (Box<dyn Error>).
sourcepub async fn upload_files(
self,
parameters: FileUpload
) -> Result<FileData, Box<dyn Error>>
pub async fn upload_files( self, parameters: FileUpload ) -> Result<FileData, Box<dyn Error>>
The upload_files function in Rust uploads files to the OpenAI API and returns the file data.
Arguments:
parameters: Theparametersparameter in theupload_filesfunction is of typeFileUpload. It represents the data that needs to be uploaded to the server. TheFileUploadstruct should contain the necessary information for the file upload, such as the file content, file name, and file type
Returns:
The function upload_files returns a Result containing either a FileData object or an error
(Box<dyn Error>).
sourcepub async fn delete_file(
self,
file_id: String
) -> Result<DeleteResponse, Box<dyn Error>>
pub async fn delete_file( self, file_id: String ) -> Result<DeleteResponse, Box<dyn Error>>
The function delete_file is an asynchronous function in Rust that sends a DELETE request to the
OpenAI API to delete a file.
Arguments:
file_id: Thefile_idparameter is a string that represents the unique identifier of the file you want to delete. It is used to construct the URL for the DELETE request to the OpenAI API.
Returns:
The function delete_file returns a Result containing either a DeleteResponse or a boxed
dynamic error (Box<dyn Error>).
sourcepub async fn retrieve_file(
self,
file_id: String
) -> Result<FileData, Box<dyn Error>>
pub async fn retrieve_file( self, file_id: String ) -> Result<FileData, Box<dyn Error>>
The retrieve_file function retrieves file data from the OpenAI API using the provided file ID.
Arguments:
file_id: Thefile_idparameter is a unique identifier for the file you want to retrieve. It is used to construct the URL for the API request to retrieve the file data.
Returns:
The function retrieve_file returns a Result containing either a FileData object or an
error (Box<dyn Error>).
sourcepub async fn retrieve_file_content(
self,
file_id: String
) -> Result<String, Box<dyn Error>>
pub async fn retrieve_file_content( self, file_id: String ) -> Result<String, Box<dyn Error>>
The function retrieve_file_content retrieves the content of a file from the OpenAI API using a
provided file ID.
Arguments:
file_id: Thefile_idparameter is a unique identifier for the file you want to retrieve the content of. It is used to construct the URL for the API request to fetch the file content.
Returns:
The function retrieve_file_content returns a Result containing a String representing the
content of the file with the given file_id. The Ok variant of the Result contains the file
content as a String, while the Err variant contains a boxed dynamic error (Box<dyn Error>).
sourcepub async fn create_fine_tune(
self,
parameters: CreateFineTuneParameters
) -> Result<FineTuneRetriveData, Box<dyn Error>>
pub async fn create_fine_tune( self, parameters: CreateFineTuneParameters ) -> Result<FineTuneRetriveData, Box<dyn Error>>
The function create_fine_tune sends a POST request to the OpenAI API to create a fine-tuned
model and returns the retrieved data.
Arguments:
parameters: Theparametersparameter in thecreate_fine_tunefunction is of typeCreateFineTuneParameters. It is an input parameter that contains the data required to create a fine-tune task. The specific structure and fields of theCreateFineTuneParameterstype are not
Returns:
a Result object with the type FineTuneRetriveData.
sourcepub async fn list_fine_tunes(self) -> Result<FineTuneList, Box<dyn Error>>
pub async fn list_fine_tunes(self) -> Result<FineTuneList, Box<dyn Error>>
The function list_fine_tunes makes an HTTP GET request to the OpenAI API to retrieve a list of
fine-tuned models.
Returns:
a Result object with the type FineTuneList.
sourcepub async fn retrive_fine_tune(
self,
fine_tune_id: String
) -> Result<FineTuneRetriveData, Box<dyn Error>>
pub async fn retrive_fine_tune( self, fine_tune_id: String ) -> Result<FineTuneRetriveData, Box<dyn Error>>
The function retrieves fine-tune data from the OpenAI API using the provided fine-tune ID.
Arguments:
fine_tune_id: Thefine_tune_idparameter is a unique identifier for a specific fine-tuning job. It is used to retrieve the data associated with that fine-tuning job from the OpenAI API.
Returns:
a Result type with the success variant containing a FineTuneRetriveData object and the error
variant containing a Box<dyn Error> object.
sourcepub async fn cancel_fine_tune(
self,
fine_tune_id: String
) -> Result<FineTuneRetriveData, Box<dyn Error>>
pub async fn cancel_fine_tune( self, fine_tune_id: String ) -> Result<FineTuneRetriveData, Box<dyn Error>>
The cancel_fine_tune function cancels a fine-tuning process by sending a POST request to the
OpenAI API.
Arguments:
fine_tune_id: Thefine_tune_idparameter is a unique identifier for a fine-tuning process. It is used to specify which fine-tuning process you want to cancel.
Returns:
a Result object with the type FineTuneRetriveData.
sourcepub async fn list_fine_tune_events(
self,
fine_tune_id: String
) -> Result<FineTuneEventList, Box<dyn Error>>
pub async fn list_fine_tune_events( self, fine_tune_id: String ) -> Result<FineTuneEventList, Box<dyn Error>>
The function list_fine_tune_events is an asynchronous function in Rust that retrieves a list
of fine-tune events from the OpenAI API.
Arguments:
fine_tune_id: Thefine_tune_idparameter is a unique identifier for a fine-tuning job. It is used to specify which fine-tuning job’s events you want to retrieve.
Returns:
a Result type with the Ok variant containing a FineTuneEventList object and the Err
variant containing a Box<dyn Error> object.
sourcepub async fn delete_fine_tune(
self,
model: String
) -> Result<FineTuneDelete, Box<dyn Error>>
pub async fn delete_fine_tune( self, model: String ) -> Result<FineTuneDelete, Box<dyn Error>>
The function delete_fine_tune sends a DELETE request to the OpenAI API to delete a fine-tuned
model and returns the result as a FineTuneDelete object.
Arguments:
model: Themodelparameter is a string that represents the name or ID of the fine-tuned model that you want to delete.
Returns:
a Result enum with the success variant containing a FineTuneDelete object or the error
variant containing a Box<dyn Error> object.
sourcepub async fn create_moderation(
self,
parameters: TextModerationParameters
) -> Result<TextModerationResult, Box<dyn Error>>
pub async fn create_moderation( self, parameters: TextModerationParameters ) -> Result<TextModerationResult, Box<dyn Error>>
The function create_moderation sends a POST request to the OpenAI API to create a text
moderation task and returns the result.
Arguments:
parameters: Theparametersparameter in thecreate_moderationfunction is of typeTextModerationParameters. It represents the input parameters for the text moderation request. The specific structure and fields of theTextModerationParameterstype are not provided in the code snippet, so it would be
Returns:
a Result type with the success variant containing a TextModerationResult and the error
variant containing a Box<dyn Error>.