use serde::{Deserialize, Serialize};
use crate::batch::ExecuteBatch;
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
pub struct CostEstimate {
pub usd: f64,
pub input_tokens: u32,
pub output_tokens_max: u32,
}
pub trait EstimateCost {
fn estimate(&self, batch: &ExecuteBatch) -> CostEstimate;
}
pub fn from_rates(input_per_mtok_usd: f64, output_per_mtok_usd: f64, batch: &ExecuteBatch) -> CostEstimate {
let in_t = batch.estimated_tokens();
let in_share = ((in_t as f64) * 0.8) as u32;
let out_share = in_t - in_share;
let usd = (in_share as f64) * input_per_mtok_usd / 1_000_000.0
+ (out_share as f64) * output_per_mtok_usd / 1_000_000.0;
CostEstimate {
usd,
input_tokens: in_share,
output_tokens_max: out_share,
}
}