Skip to content

Commit

Permalink
Move model_id out of Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
theoforger committed Sep 25, 2024
1 parent 86a366a commit 0f06867
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub struct Instance {
client: reqwest::Client,
base_url: String,
key: String,
model_id: String,
}

impl Instance {
Expand All @@ -23,13 +22,11 @@ impl Instance {
base_url
};
let key = Self::get_env_var("API_KEY")?;
let model_id = Self::get_env_var("DEFAULT_MODEL_ID")?;

Ok(Self {
client: reqwest::Client::new(),
base_url,
key,
model_id,
})
}

Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use clap::Parser;

use dotenv::dotenv;
use mastermind::api::Instance;
use mastermind::clue::ClueCollection;
use mastermind::json_models::chat_completions::ChatCompletionsResponse;
Expand All @@ -10,6 +11,7 @@ use mastermind::*;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read arguments and environment variables
let args = Args::parse();
dotenv().ok();

// Create an API instance and get all available models
let mut api_instance = Instance::new()?;
Expand All @@ -23,12 +25,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

// If -m is set, use a preferred language model
if let Some(model_id) = args.model {
if model_id == "interactive" {
if let Some(model_ids) = args.model {
if model_ids[0] == "interactive" {
let selected_model = model_collection.prompt_selection()[0].to_string();
api_instance.set_model_id(selected_model).await?;
} else {
api_instance.set_model_id(model_id).await?;
let selected_model = env::var("DEFAULT_MODEL_ID")
.map_err(|_| "Cannot read environment variable: DEFAULT_MODEL_ID".into())?;
api_instance.set_model_id(selected_model).await?;
}
}

Expand Down

0 comments on commit 0f06867

Please sign in to comment.