pub trait LlmClassifier: Send + Sync {
// Required method
fn classify<'a>(
&'a self,
prompt: &'a LlmPrompt,
) -> BoxFuture<'a, Result<LlmResponse>>;
}Expand description
Trait for LLM-based HS code classification.
Implement this with your preferred LLM provider (Anthropic Claude,
OpenAI GPT-4o, local Ollama, …) and attach it to the pipeline via
HsPipeline::with_llm.
§Contract
- Must return an
LlmResponsewithhs_codethat is exactly 6 ASCII digits. The pipeline validates this and returnsHsPredictError::ValidationFailedif the code is malformed. confidenceshould follow the guide inLlmPrompt::system_text: ≥ 0.90 for certain sub-heading, ≥ 0.70 for certain heading.- Must be
Send + Sync(required forArc<dyn LlmClassifier>).
§Minimal implementation
use hs_predict::llm::{LlmClassifier, LlmPrompt, LlmResponse, parse_llm_json};
use futures::future::BoxFuture;
struct MyClient;
impl LlmClassifier for MyClient {
fn classify<'a>(&'a self, prompt: &'a LlmPrompt) -> BoxFuture<'a, hs_predict::Result<LlmResponse>> {
Box::pin(async move {
let raw = String::from(r#"{"hs_code":"291511","confidence":0.85,"rationale":"...","alternatives":[]}"#);
parse_llm_json(&raw)
})
}
}Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".