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 provided parameters.

Arguments:

  • parameters: The parameters parameter in the create_chat_completions is struct ChatParameters. It represents the input data for the chat completion API. The ChatParameters struct contains the following fields:
 model: String,
 messages: Vec<Message>,

Returns:

a Result type with the Ok variant containing a ChatResponse object if the operation is successful, or the Err variant containing a Box<dyn Error> if an error occurs.

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.

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