Skip to content

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

refactor(inference): extract model default application logic

Steven Enamakel824f7efcc452
diff --git a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
index be4ad67fe8..5cf8192f32 100644
--- a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
@@ -216,13 +216,23 @@ impl ModelFactory<()> for OpenHumanModelFactory<'_> {
model: (!route.model.is_empty()).then(|| route.model.clone()),
temperature: request.opts.temperature,
};
- let profile = model.profile().cloned().unwrap_or_default();
- let model = Arc::new(ProfileOverrideModel::new(model, profile).with_defaults(opts))
- as Arc<dyn ChatModel<()>>;
+ let model = with_request_defaults(model, opts);
Ok((model, route))
}
}
+fn with_request_defaults(
+ model: Arc<dyn ChatModel<()>>,
+ defaults: ModelRequestDefaults,
+) -> Arc<dyn ChatModel<()>> {
+ match model.profile().cloned() {
+ Some(profile) => Arc::new(ProfileOverrideModel::new(model, profile).with_defaults(defaults)),
+ None => Arc::new(
+ ProfileOverrideModel::new_preserving_profile(model).with_defaults(defaults),
+ ),
+ }
+}
+
/// Build an `Arc<dyn ChatModel>` for the given workload role, under `ctx`.
///
/// The crate [`ChatModel`] is the model interface for the harness and one-shot
@@ -405,13 +415,10 @@ pub(super) fn with_default_temperature(
model: Arc<dyn ChatModel<()>>,
temperature: f64,
) -> Arc<dyn ChatModel<()>> {
- let profile = model.profile().cloned().unwrap_or_default();
- Arc::new(
- ProfileOverrideModel::new(model, profile).with_defaults(ModelRequestDefaults {
+ with_request_defaults(model, ModelRequestDefaults {
model: None,
temperature: Some(temperature),
- }),
- )
+ })
}
/// Reproduce the legacy provider factory's access gates and diagnostics for a