Skip to main content

LlmClassifier

Trait LlmClassifier 

Source
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 LlmResponse with hs_code that is exactly 6 ASCII digits. The pipeline validates this and returns HsPredictError::ValidationFailed if the code is malformed.
  • confidence should follow the guide in LlmPrompt::system_text: ≥ 0.90 for certain sub-heading, ≥ 0.70 for certain heading.
  • Must be Send + Sync (required for Arc<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§

Source

fn classify<'a>( &'a self, prompt: &'a LlmPrompt, ) -> BoxFuture<'a, Result<LlmResponse>>

Classify the product described in prompt and return an HS code prediction.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§