feat(config): optional provider pricing for cost metrics
This commit is contained in:
parent
11474c080e
commit
115e77ff27
@ -832,6 +832,8 @@ mod tests {
|
||||
token_limit: 4096,
|
||||
workspace_dir: std::env::temp_dir(),
|
||||
input_types: vec!["text".into()],
|
||||
price_input_per_million: None,
|
||||
price_output_per_million: None,
|
||||
},
|
||||
Arc::new(ToolRegistry::new()),
|
||||
None,
|
||||
|
||||
@ -508,6 +508,19 @@ pub struct LLMProviderConfig {
|
||||
pub token_limit: usize,
|
||||
pub workspace_dir: PathBuf,
|
||||
pub input_types: Vec<String>,
|
||||
pub price_input_per_million: Option<f64>,
|
||||
pub price_output_per_million: Option<f64>,
|
||||
}
|
||||
|
||||
impl LLMProviderConfig {
|
||||
pub fn cost_of(&self, prompt_tokens: u32, completion_tokens: u32) -> Option<f64> {
|
||||
match (self.price_input_per_million, self.price_output_per_million) {
|
||||
(Some(pi), Some(po)) => Some(
|
||||
prompt_tokens as f64 / 1e6 * pi + completion_tokens as f64 / 1e6 * po,
|
||||
),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_default_config_path() -> PathBuf {
|
||||
@ -653,6 +666,8 @@ impl Config {
|
||||
token_limit: agent.token_limit,
|
||||
workspace_dir: expand_path(&self.workspace_dir),
|
||||
input_types: model.input_type.clone(),
|
||||
price_input_per_million: None,
|
||||
price_output_per_million: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,6 +225,8 @@ mod tests {
|
||||
token_limit: 8_192,
|
||||
workspace_dir: PathBuf::from("."),
|
||||
input_types: vec!["text".to_string(), "image".to_string()],
|
||||
price_input_per_million: None,
|
||||
price_output_per_million: None,
|
||||
};
|
||||
let session = Arc::new(Mutex::new(
|
||||
Session::new(
|
||||
|
||||
@ -27,6 +27,8 @@ fn load_config() -> Option<LLMProviderConfig> {
|
||||
token_limit: 128_000,
|
||||
workspace_dir: std::path::PathBuf::from("/tmp/test-workspace"),
|
||||
input_types: vec!["text".to_string()],
|
||||
price_input_per_million: None,
|
||||
price_output_per_million: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@ fn load_openai_config() -> Option<LLMProviderConfig> {
|
||||
token_limit: 128_000,
|
||||
workspace_dir: std::path::PathBuf::from("/tmp/test-workspace"),
|
||||
input_types: vec!["text".to_string()],
|
||||
price_input_per_million: None,
|
||||
price_output_per_million: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user