interpolize 5.0.1

a rust program that scrapes discord, learns how your friends talk, and generates new messages in their collective voice. yes, this is what we're doing with our lives.
use anyhow::Result;
use serde::Deserialize;
use std::fs;

#[derive(Deserialize, Clone)]
pub struct Config {
    pub discord: Discord,
    pub embeddings: Embeddings,
    pub retrieval: Retrieval,
    pub channels: Vec<Channel>,
}

#[derive(Deserialize, Clone)]
pub struct Discord {
    pub token: String,
}

#[derive(Deserialize, Clone)]
pub struct Embeddings {
    pub storage_path: String,
    pub vector_dim: usize,
    pub window_size: usize,
}

#[derive(Deserialize, Clone)]
pub struct Retrieval {
    pub style_k: usize,
    pub context_k: usize,
    pub thread_depth: usize,
}

#[derive(Deserialize, Clone)]
pub struct Channel {
    pub id: String,
    pub name: String,
    pub weight: f32,
    pub scrape_limit: usize,
}

impl Config {
    pub fn load(path: &str) -> Result<Self> {
        let raw = fs::read_to_string(path)?;
        let config: Config = toml::from_str(&raw)?;
        Ok(config)
    }

    pub fn normalized_weights(&self) -> Vec<f32> {
        let sum: f32 = self.channels.iter().map(|c| c.weight).sum();
        self.channels.iter().map(|c| c.weight / sum).collect()
    }
}