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: The- tokenparameter 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: The- oia_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: The- modelparameter is a- Stringthat 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: The- parametersparameter in the- create_chat_completionsfunction is of type- ChatParameters. 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: The- parametersparameter in the- create_completionsfunction is of type- CompletionParameters. 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: The- parametersparameter in the- create_editfunction is of type- EditParameters. 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 the- EditParametersstruct. 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: The- parametersparameter in the- create_imagefunction is of type- ImageCreateParameters. 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: The- parametersparameter in the- create_image_editfunction is of type- ImageEditParameters. 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: The- parametersparameter in the- create_image_variationsfunction is of type- ImageVariationParameters. 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: The- parametersparameter in the- create_embeddingfunction is of type- EmbeddingParameters. 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: The- parametersparameter in the- create_transcriptionfunction is of type- TranscriptionParameters. 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: The- parametersparameter in the- create_translationfunction is of type- TranslationParameters. 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: The- parametersparameter in the- upload_filesfunction is of type- FileUpload. It represents the data that needs to be uploaded to the server. The- FileUploadstruct 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: The- file_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: The- file_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: The- file_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>).