feat!: add missing api key error

BREAKING CHANGE: `APIError` is renamed to `ApiError`.
This commit is contained in:
Ivan Gabriele
2024-03-04 04:21:03 +01:00
parent b0a3f10c9f
commit 1deab88251
10 changed files with 64 additions and 47 deletions

View File

@@ -6,12 +6,7 @@ use mistralai_client::v1::{
};
#[test]
fn test_chat_completion() {
extern crate dotenv;
use dotenv::dotenv;
dotenv().ok();
fn test_client_chat() {
let client = Client::new(None, None, None, None);
let model = Model::OpenMistral7b;

View File

@@ -2,12 +2,7 @@ use jrest::expect;
use mistralai_client::v1::{client::Client, constants::EmbedModel};
#[test]
fn test_embeddings() {
extern crate dotenv;
use dotenv::dotenv;
dotenv().ok();
fn test_client_embeddings() {
let client: Client = Client::new(None, None, None, None);
let model = EmbedModel::MistralEmbed;

View File

@@ -2,12 +2,7 @@ use jrest::expect;
use mistralai_client::v1::client::Client;
#[test]
fn test_list_models() {
extern crate dotenv;
use dotenv::dotenv;
dotenv().ok();
fn test_client_list_models() {
let client = Client::new(None, None, None, None);
let response = client.list_models().unwrap();

View File

@@ -4,6 +4,7 @@ use mistralai_client::v1::client::Client;
#[test]
fn test_client_new_with_none_params() {
let maybe_original_mistral_api_key = std::env::var("MISTRAL_API_KEY").ok();
std::env::remove_var("MISTRAL_API_KEY");
std::env::set_var("MISTRAL_API_KEY", "test_api_key_from_env");
let client = Client::new(None, None, None, None);
@@ -24,6 +25,7 @@ fn test_client_new_with_none_params() {
#[test]
fn test_client_new_with_all_params() {
let maybe_original_mistral_api_key = std::env::var("MISTRAL_API_KEY").ok();
std::env::remove_var("MISTRAL_API_KEY");
std::env::set_var("MISTRAL_API_KEY", "test_api_key_from_env");
let api_key = Some("test_api_key_from_param".to_string());
@@ -50,3 +52,19 @@ fn test_client_new_with_all_params() {
None => std::env::remove_var("MISTRAL_API_KEY"),
}
}
#[test]
#[should_panic]
fn test_client_new_with_missing_api_key() {
let maybe_original_mistral_api_key = std::env::var("MISTRAL_API_KEY").ok();
std::env::remove_var("MISTRAL_API_KEY");
let _client = Client::new(None, None, None, None);
match maybe_original_mistral_api_key {
Some(original_mistral_api_key) => {
std::env::set_var("MISTRAL_API_KEY", original_mistral_api_key)
}
None => std::env::remove_var("MISTRAL_API_KEY"),
}
}