Skip to content

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

refactor(examples): register a chat model instead of a backend transport

Steven Enamakeldf89c9c571d7
diff --git a/crates/openhuman-embed/examples/profiles.rs b/crates/openhuman-embed/examples/profiles.rs
index e477ee1219..d29c65945d 100644
--- a/crates/openhuman-embed/examples/profiles.rs
+++ b/crates/openhuman-embed/examples/profiles.rs
@@ -12,7 +12,7 @@ fn main() -> anyhow::Result<()> {
}
async fn run(config: openhuman_embed::SaasConfig) -> anyhow::Result<()> {
let provider = support::echo_inference().await;
- support::PointedTransport::install(&provider.uri());
+ support::PointedInference::install(&provider.uri());
// ANCHOR: profiles
let profiles = openhuman_embed::ProfileRuntime::build(config).await?;
let mut handles = Vec::new();
diff --git a/crates/openhuman-embed/examples/support/mod.rs b/crates/openhuman-embed/examples/support/mod.rs
index 9623037d8a..53f0121666 100644
--- a/crates/openhuman-embed/examples/support/mod.rs
+++ b/crates/openhuman-embed/examples/support/mod.rs
@@ -219,75 +219,45 @@ pub async fn eventually<T>(what: &str, mut check: impl FnMut() -> Option<T>) ->
panic!("timed out waiting for {what}");
}
-/// A backend transport that sends managed inference to `base_url` (a mock)
-/// and answers every control-plane call as "no backend". For suites that run
-/// turns through the core's managed-inference path, such as SaaS profiles,
-/// whose configs name no inference endpoint of their own.
-pub struct PointedTransport {
- base_url: String,
- client: reqwest::Client,
-}
-
-impl PointedTransport {
+/// Registers a managed chat-model provider that sends inference to `base_url`
+/// (a mock). For suites that run turns through the core's managed-inference
+/// path, such as SaaS profiles, whose configs name no inference endpoint of
+/// their own. The core carries no hosted provider, so the suite supplies one
+/// through the generic chat-model registry.
+pub struct PointedInference;
+
+impl PointedInference {
pub fn install(base_url: &str) {
- openhuman_embed::install_backend_transport(std::sync::Arc::new(Self {
- base_url: base_url.trim_end_matches('/').to_string(),
- client: reqwest::Client::new(),
- }));
- }
-}
-
-#[async_trait::async_trait]
-impl openhuman_embed::BackendTransport for PointedTransport {
- async fn send_json(
- &self,
- req: openhuman_embed::BackendRequest<'_>,
- ) -> Result<serde_json::Value, openhuman_embed::BackendTransportError> {
- // Forward inference requests to the pointed mock endpoint.
- // This uses the same HTTP client as a real transport would.
- let url = format!("{}/{}", self.base_url, req.path.trim_start_matches('/'));
- let resp = self
- .client
- .post(&url)
- .json(&req.body)
- .send()
- .await
- .map_err(|_| openhuman_embed::BackendTransportError::Unavailable)?;
- resp.json()
- .await
- .map_err(|_| openhuman_embed::BackendTransportError::Unavailable)
- }
-
- async fn send_multipart(
- &self,
- _req: openhuman_embed::BackendRequest<'_>,
- _form: reqwest::multipart::Form,
- ) -> Result<serde_json::Value, openhuman_embed::BackendTransportError> {
- Err(openhuman_embed::BackendTransportError::Unavailable)
- }
-
- fn http_client(&self, _profile: openhuman_embed::TransportProfile) -> reqwest::Client {
- reqwest::Client::new()
- }
-
- fn base_url(
- &self,
- _configured: Option<&str>,
- _purpose: openhuman_embed::BaseUrlPurpose,
- ) -> String {
- self.base_url.clone()
- }
-
- fn product_identity(&self) -> String {
- "openhuman-embed-test".to_string()
- }
-
- fn attribution_headers(&self) -> reqwest::header::HeaderMap {
- reqwest::header::HeaderMap::new()
- }
-
- fn name(&self) -> &'static str {
- "embed-test-pointed"
+ use openhuman_embed::__host::inference_registry::{
+ register_chat_model, ChatModelEntry, ChatModelRequest, PROVIDER_OPENHUMAN,
+ };
+ use tinyinference_llm::providers::openai::OpenAiModel;
+
+ let base_url = base_url.trim_end_matches('/').to_string();
+ let build = move |request: &ChatModelRequest<'_>| {
+ let model = request
+ .model_override
+ .or(request.default_model)
+ .unwrap_or("embed-test-model")
+ .to_string();
+ let wire = OpenAiModel::compatible_provider(
+ "EmbedTest",
+ "embed-test-token".to_string(),
+ base_url.clone(),
+ &model,
+ )
+ .with_native_tool_calling(request.native_tool_calling);
+ let wire: std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>> =
+ std::sync::Arc::new(wire);
+ Ok((wire, model))
+ };
+ register_chat_model(
+ PROVIDER_OPENHUMAN,
+ ChatModelEntry {
+ build: std::sync::Arc::new(build),
+ probe: None,
+ },
+ );
}
}