Skip to content

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

chore: files changed crates/openhuman-core/src/inference/README.md,crates/openhuman-core/src/inferen

Steven Enamakel28f83805ca0e
diff --git a/crates/openhuman-core/src/inference/README.md b/crates/openhuman-core/src/inference/README.md
index d0aee28ae8..9e8b1f6832 100644
--- a/crates/openhuman-core/src/inference/README.md
+++ b/crates/openhuman-core/src/inference/README.md
@@ -57,7 +57,7 @@ The provider-string grammar is documented at the top of `provider/factory.rs`:
```
The optional `@<temp>` suffix pins a temperature for that workload. It is stripped
-(`routing::split_model_and_temperature`) before the model id goes upstream. Unknown slugs and
+(`tinyinference_providers::route::split_model_and_temperature`) before the model id goes upstream. Unknown slugs and
missing credentials produce actionable errors instead of a silent fallback.
Background roles (`vision`, `embeddings`, `memory`, `agentic`, `burst`) fall back to the primary
diff --git a/crates/openhuman-core/src/inference/provider/factory.rs b/crates/openhuman-core/src/inference/provider/factory.rs
index 718bcb55d1..982f4317ff 100644
--- a/crates/openhuman-core/src/inference/provider/factory.rs
+++ b/crates/openhuman-core/src/inference/provider/factory.rs
@@ -90,7 +90,7 @@ use local_runtime::{
pub(crate) use managed_backend::make_openhuman_backend_model_for_thread;
use managed_backend::{resolve_managed_backend, resolve_managed_backend_with_model_override};
use primary_cloud::{legacy_inference_slug, resolve_primary_cloud_provider_string};
-use routing::split_model_and_temperature;
+use tinyinference_providers::route::split_model_and_temperature;
use subprocess_providers::{
prepare_claude_agent_sdk_chat_model, try_create_claude_agent_sdk_chat_model,
try_create_claude_agent_sdk_chat_model_from_string, try_create_claude_code_chat_model,
diff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
index e29bd07884..158d52ff08 100644
--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
@@ -37,7 +37,9 @@ pub(super) fn try_create_local_runtime_chat_model_from_string(
provider: &str,
config: &Config,
) -> OptionalChatModelResult {
- use tinyinference_local::profile::{LOCAL_OPENAI_PROFILE, MLX_PROFILE, OMLX_PROFILE};
+ use tinyinference_local::local_runtime::{
+ LocalRuntimeAuth, LocalRuntimeInputs, resolve_local_runtime,
+ };
// Use the same classifier as privacy and session policy. Canonicalize only
// the provider prefix: model IDs (including tags and temperature suffixes)
@@ -65,132 +67,42 @@ pub(super) fn try_create_local_runtime_chat_model_from_string(
// is the single local chokepoint for every ChatModel/turn entry.
emit_inference_egress(role, &p);
- let unsupported = config.temperature_unsupported_models.clone();
- let empty_model_err = |p: &str, form: &str| {
- anyhow::anyhow!("[chat-factory] provider string '{p}' has an empty model — use '{form}'")
+ // Endpoint, auth, model and `@temp` resolution is the module's pure
+ // `resolve_local_runtime`; the host only supplies config + env.
+ let inputs = LocalRuntimeInputs {
+ base_url: config.local_ai.base_url.as_deref(),
+ api_key: config.local_ai.api_key.as_deref(),
+ num_ctx: config.local_ai.num_ctx,
+ env: host_env,
};
-
- // Resolve the local `api_key` + auth style shared by lmstudio/omlx/local-openai
- // (Bearer when a key is configured, else no auth — same as the host builders).
- let keyed_auth = || {
- let api_key = config.local_ai.api_key.as_deref().unwrap_or("").to_string();
- let auth = if api_key.trim().is_empty() {
- CompatAuthStyle::None
- } else {
- CompatAuthStyle::Bearer
- };
- (api_key, auth)
+ let resolved = match resolve_local_runtime(provider, &inputs)? {
+ Ok(r) => r,
+ Err(e) => return Some(Err(anyhow::anyhow!("{e}"))),
};
- // First env override, else `local_ai.base_url`, else the profile default.
- let env_or_config_url = |env: &str, default: &str| {
- std::env::var("OPENHUMAN_LOCAL_INFERENCE_URL")
- .ok()
- .filter(|s| !s.trim().is_empty())
- .or_else(|| std::env::var(env).ok().filter(|s| !s.trim().is_empty()))
- .or_else(|| config.local_ai.base_url.clone())
- .unwrap_or_else(|| default.to_string())
+ let auth = match resolved.auth {
+ LocalRuntimeAuth::None => CompatAuthStyle::None,
+ LocalRuntimeAuth::Bearer => CompatAuthStyle::Bearer,
};
+ log::debug!(
+ "[chat-factory] local runtime resolved slug={}",
+ resolved.kind.as_str()
+ );
+ let chat = build_local_runtime_chat_model(
+ resolved.kind.as_str(),
+ &resolved.endpoint,
+ &resolved.api_key,
+ auth,
+ &resolved.model,
+ &config.temperature_unsupported_models,
+ resolved.temperature,
+ resolved.num_ctx,
+ );
+ Some(Ok((chat, resolved.model)))
+}
- if let Some(rest) = p.strip_prefix(OLLAMA_PROVIDER_PREFIX) {
- let (model, temp) = split_model_and_temperature(rest);
- if model.is_empty() {
- return Some(Err(empty_model_err(&p, "ollama:<model-id>")));
- }
- // Ollama exposes the OpenAI-compatible endpoint at `/v1`.
- let base_url = tinyinference_local::ollama::ollama_base_url_from_override(
- config.local_ai.base_url.as_deref(),
- );
- let normalized = base_url.trim_end_matches('/').trim_end_matches("/v1");
- let endpoint = format!("{normalized}/v1");
- let chat = build_local_runtime_chat_model(
- "ollama",
- &endpoint,
- "",
- CompatAuthStyle::None,
- &model,
- &unsupported,
- temp,
- config.local_ai.num_ctx,
- );
- return Some(Ok((chat, model)));
- }
- if let Some(rest) = p.strip_prefix(LM_STUDIO_PROVIDER_PREFIX) {
- let (model, temp) = split_model_and_temperature(rest);
- if model.is_empty() {
- return Some(Err(empty_model_err(&p, "lmstudio:<model-id>")));
- }
- let endpoint =
- tinyinference_local::lm_studio::lm_studio_base_url(config.local_ai.base_url.as_deref());
- let (api_key, auth) = keyed_auth();
- let chat = build_local_runtime_chat_model(
- "lmstudio",
- &endpoint,
- &api_key,
- auth,
- &model,
- &unsupported,
- temp,
- None,
- );
- return Some(Ok((chat, model)));
- }
- if let Some(rest) = p.strip_prefix(MLX_PROVIDER_PREFIX) {
- let (model, temp) = split_model_and_temperature(rest);
- if model.is_empty() {
- return Some(Err(empty_model_err(&p, "mlx:<model-id>")));
- }
- let endpoint = env_or_config_url("MLX_SERVER_URL", MLX_PROFILE.default_base_url);
- let chat = build_local_runtime_chat_model(
- "mlx",
- &endpoint,
- "",
- CompatAuthStyle::None,
- &model,
- &unsupported,
- temp,
- None,
- );
- return Some(Ok((chat, model)));
- }
- if let Some(rest) = p.strip_prefix(OMLX_PROVIDER_PREFIX) {
- let (model, temp) = split_model_and_temperature(rest);
- if model.is_empty() {
- return Some(Err(empty_model_err(&p, "omlx:<model-id>")));
- }
- let endpoint = env_or_config_url("OMLX_SERVER_URL", OMLX_PROFILE.default_base_url);
- let (api_key, auth) = keyed_auth();
- let chat = build_local_runtime_chat_model(
- "omlx",
- &endpoint,
- &api_key,
- auth,
- &model,
- &unsupported,
- temp,
- None,
- );
- return Some(Ok((chat, model)));
- }
- if let Some(rest) = p.strip_prefix(LOCAL_OPENAI_PROVIDER_PREFIX) {
- let (model, temp) = split_model_and_temperature(rest);
- if model.is_empty() {
- return Some(Err(empty_model_err(&p, "local-openai:<model-id>")));
- }
- let endpoint = env_or_config_url("LOCAL_OPENAI_URL", LOCAL_OPENAI_PROFILE.default_base_url);
- let (api_key, auth) = keyed_auth();
- let chat = build_local_runtime_chat_model(
- "local-openai",
- &endpoint,
- &api_key,
- auth,
- &model,
- &unsupported,
- temp,
- None,
- );
- return Some(Ok((chat, model)));
- }
- None
+/// Environment lookup handed to the module's pure resolver.
+fn host_env(name: &str) -> Option<String> {
+ std::env::var(name).ok()
}
/// Build a crate-native local-runtime model for setup/probe calls that run
diff --git a/crates/openhuman-core/src/inference/provider/factory/routing.rs b/crates/openhuman-core/src/inference/provider/factory/routing.rs
index d232c3b481..dbb3dd1962 100644
--- a/crates/openhuman-core/src/inference/provider/factory/routing.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/routing.rs
@@ -253,26 +253,6 @@ pub(super) fn route_has_usable_credentials(resolved: &str, config: &Config) -> b
false
}
-/// Parse a `<model>[@<temp>]` tail into `(model, override)`.
-///
-/// Tolerates whitespace around the components. Returns `temperature = None`
-/// when the suffix is absent or unparseable — the model text is taken as-is.
-pub(super) fn split_model_and_temperature(raw: &str) -> (String, Option<f64>) {
- let trimmed = raw.trim();
- if let Some(at_pos) = trimmed.rfind('@') {
- let head = trimmed[..at_pos].trim();
- let tail = trimmed[at_pos + 1..].trim();
- if !head.is_empty() {
- if let Ok(parsed) = tail.parse::<f64>() {
- if parsed.is_finite() {
- return (head.to_string(), Some(parsed));
- }
- }
- }
- }
- (trimmed.to_string(), None)
-}
-
#[cfg(test)]
#[path = "routing_tests.rs"]
mod routing_tests;