#![deny(missing_docs)]
mod sha256;
pub fn key(model: &str, messages: &[(&str, &str)], temperature: f32) -> String {
let mut input = String::new();
input.push_str("model=");
input.push_str(model);
input.push('\n');
input.push_str("temp=");
input.push_str(&format!("{:.2}", temperature));
input.push('\n');
for (role, content) in messages {
input.push_str("role=");
input.push_str(role);
input.push('\n');
input.push_str("body=");
input.push_str(&normalize_body(content));
input.push('\n');
}
sha256::hex(input.as_bytes())
}
fn normalize_body(s: &str) -> String {
let s = s.replace("\r\n", "\n").replace('\r', "\n");
s.lines()
.map(|l| l.trim_end_matches(|c: char| c == ' ' || c == '\t'))
.collect::<Vec<_>>()
.join("\n")
}