use std::sync::Arc;
use ares_types::{AppError, Result};
use cordis::Context;
pub async fn embed_with_llm(
ctx: &Arc<Context>,
inputs: &[String],
) -> Result<Vec<Vec<f32>>> {
let Some(llm) = ctx.get::<ares_llm::Llm>() else {
return Err(AppError::Configuration(
"Llm service is not provided for remote embeddings".into(),
));
};
llm.embed(ctx, inputs).await
}
#[cfg(test)]
mod tests {
use super::*;
use ares_types::AppError;
#[tokio::test]
async fn embed_with_llm_errors_when_llm_missing() {
let ctx = Context::new_root();
let err = embed_with_llm(&ctx, &[String::from("hello")])
.await
.expect_err("missing Llm must fail closed");
match err {
AppError::Configuration(msg) => {
assert_eq!(msg, "Llm service is not provided for remote embeddings");
}
other => panic!("expected Configuration, got {other:?}"),
}
}
}