Skip to main content

hiramu_cli/
config.rs

1// src/config.rs
2use serde::{Deserialize, Serialize};
3use std::fs::File;
4use std::io::Read;
5use std::path::Path;
6use toml;
7
8use crate::provider::Provider;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Config {
12    pub provider: Provider,
13    pub model_name: Option<String>,
14    pub region: Option<String>,
15    pub profile: Option<String>,
16    pub max_token: u32,
17    pub temperature: f32,
18    pub endpoint: Option<String>,
19}
20
21impl Config {
22    pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn std::error::Error>> {
23        let mut file = File::open(path)?;
24        let mut contents = String::new();
25        file.read_to_string(&mut contents)?;
26        let config: Config = toml::from_str(&contents)?;
27        Ok(config)
28    }
29}