Struct openai_rs_api::core::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>).

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

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

§

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