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 provided parameters.
Arguments:
parameters: Theparametersparameter in thecreate_chat_completionsis structChatParameters. It represents the input data for the chat completion API. TheChatParametersstruct 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.
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.