gmini 0.1.1

A modular and asynchronous Rust SDK for interacting with the Google Gemini API.
use dotenv;
use std::process::Command;

pub struct EnvVars {
    pub project_id: String,
    pub location_id: String,
    pub api_endpoint: String,
    pub model_id: String,
    pub generate_content_api: String,
}

pub fn load_env_vars() -> Result<EnvVars, Box<dyn std::error::Error>> {
    dotenv::dotenv().ok();

    Ok(EnvVars {
        project_id: std::env::var("PROJECT_ID")?,
        location_id: std::env::var("LOCATION_ID")?,
        api_endpoint: std::env::var("API_ENDPOINT")?,
        model_id: std::env::var("MODEL_ID")?,
        generate_content_api: std::env::var("GENERATE_CONTENT_API")?,
    })
}

pub async fn get_access_token() -> Result<String, Box<dyn std::error::Error>> {
    let access_token_bytes = Command::new("gcloud")
        .args(&["auth", "print-access-token"])
        .output()?
        .stdout;

    Ok(String::from_utf8_lossy(&access_token_bytes)
        .trim()
        .to_string())
}

pub fn build_api_url(env_vars: &EnvVars) -> String {
    format!(
        "https://{}/v1/projects/{}/locations/{}/publishers/google/models/{}:{}",
        env_vars.api_endpoint,
        env_vars.project_id,
        env_vars.location_id,
        env_vars.model_id,
        env_vars.generate_content_api
    )
}