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
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
: Thetoken
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
: Theoia_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.
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
: Themodel
parameter is aString
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
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
: Theparameters
parameter in thecreate_chat_completions
is structChatParameters
. It represents the input data for the chat completion API. TheChatParameters
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.
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
: Theparameters
parameter in thecreate_completions
function 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
: Theparameters
parameter in thecreate_edit
function 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 theEditParameters
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.