Struct OpenAI

Source
pub struct OpenAI {
    pub token: String,
    pub oia_org: String,
    /* private fields */
}

Fields§

§token: String§oia_org: String

Implementations§

Source§

impl OpenAI

Source

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 token parameter 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_org parameter 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.

Source

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.

Source

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 model parameter is a String that 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 as the Err variant.

Source

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 parameters parameter in the create_chat_completions function 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.

Source

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 parameters parameter in the create_completions function 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.

Source

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 parameters parameter in the create_edit function 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 EditParameters struct. You would need to refer to the definition

Returns:

a Result with the type EditResponse on success or a Box<dyn Error> on failure.

Source

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 parameters parameter in the create_image function 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>.

Source

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 parameters parameter in the create_image_edit function 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.

Source

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 parameters parameter in the create_image_variations function 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.

Source

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 parameters parameter in the create_embedding function 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.

Source

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 parameters parameter in the create_transcription function 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.

Source

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 parameters parameter in the create_translation function 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.

Source

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>).

Source

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 parameters parameter in the upload_files function is of type FileUpload. It represents the data that needs to be uploaded to the server. The FileUpload struct 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>).

Source

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_id parameter 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>).

Source

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_id parameter 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>).

Source

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_id parameter 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>).

Source

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: The parameters parameter in the create_fine_tune function is of type CreateFineTuneParameters. It is an input parameter that contains the data required to create a fine-tune task. The specific structure and fields of the CreateFineTuneParameters type are not

Returns:

a Result object with the type FineTuneRetriveData.

Source

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.

Source

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: The fine_tune_id parameter 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.

Source

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: The fine_tune_id parameter 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.

Source

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: The fine_tune_id parameter 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.

Source

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: The model parameter 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.

Source

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: The parameters parameter in the create_moderation function is of type TextModerationParameters. It represents the input parameters for the text moderation request. The specific structure and fields of the TextModerationParameters type 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>.

Trait Implementations§

Source§

impl Clone for OpenAI

Source§

fn clone(&self) -> OpenAI

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for OpenAI

§

impl !RefUnwindSafe for OpenAI

§

impl !Send for OpenAI

§

impl !Sync for OpenAI

§

impl Unpin for OpenAI

§

impl !UnwindSafe for OpenAI

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more