Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(tokenjuice): improve default model resolution in savings

Steven Enamakelaabecfc0cdc8
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index cd50d41141..caf55666f7 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -136,12 +136,13 @@ pub async fn install_from_config(config: &crate::config::Config) -> Result<(), S
log::debug!("[tokenjuice] component disabled; module install skipped");
return Ok(());
}
- savings::configure(
- config
- .default_model
- .clone()
- .unwrap_or_else(|| crate::config::DEFAULT_MODEL.to_string()),
- );
+ if let Some(model) = config.default_model.clone().or_else(|| {
+ crate::inference::registry::provider_default_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ )
+ }) {
+ savings::configure(model);
+ }
// Totals the old build kept in a snapshot file move into the module's
// storage first (once per file, best effort).
crate::modules::import_legacy_tinyjuice_savings(
diff --git a/crates/openhuman-core/src/inference/tokenjuice/savings.rs b/crates/openhuman-core/src/inference/tokenjuice/savings.rs
index 326ccc0345..e140a33aa2 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/savings.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/savings.rs
@@ -17,9 +17,9 @@ use tinyjuice_bus::types::CompressorKind;
const MODULE: &str = "tinyjuice";
/// Model used to price the saved input tokens (the configured default).
-fn model_slot() -> &'static Mutex<String> {
- static SLOT: OnceLock<Mutex<String>> = OnceLock::new();
- SLOT.get_or_init(|| Mutex::new(crate::config::DEFAULT_MODEL.to_string()))
+fn model_slot() -> &'static Mutex<Option<String>> {
+ static SLOT: OnceLock<Mutex<Option<String>>> = OnceLock::new();
+ SLOT.get_or_init(|| Mutex::new(None))
}
/// Install the attribution model (host policy). The module keeps the totals in
@@ -27,12 +27,12 @@ fn model_slot() -> &'static Mutex<String> {
/// [`crate::modules::import_legacy_tinyjuice_savings`].
pub fn configure(attribution_model: String) {
if !attribution_model.trim().is_empty() {
- *model_slot().lock().unwrap_or_else(|p| p.into_inner()) = attribution_model;
+ *model_slot().lock().unwrap_or_else(|p| p.into_inner()) = Some(attribution_model);
}
}
/// The model savings are currently attributed to.
-pub fn attribution_model() -> String {
+pub fn attribution_model() -> Option<String> {
model_slot()
.lock()
.unwrap_or_else(|p| p.into_inner())
@@ -54,7 +54,7 @@ fn request(
compacted_tokens: u64,
) -> Option<RecordSavingsRequest> {
request_for(
- attribution_model(),
+ attribution_model()?,
compressor,
original_tokens,
compacted_tokens,