Skip to main content

Module llm

Module llm 

Source
Expand description

LLM-based HS code classification — trait hook (v0.4).

hs-predict deliberately does not ship a concrete LLM API client. Instead it defines the LlmClassifier trait, which you implement with whatever HTTP transport, model, and prompt customisation your application requires.

The library provides:

  • LlmPrompt — pre-built system + user text (EN/JA) ready to send
  • LlmResponse — the expected return value from your implementation
  • parse_llm_json — helper that strips markdown fences and deserialises the LLM’s JSON reply into an LlmResponse
  • MockLlmClassifier — deterministic stub for unit tests (mock feature)

Requires the llm Cargo feature.

§Example

use hs_predict::llm::{LlmClassifier, LlmPrompt, LlmResponse, parse_llm_json};
use futures::future::BoxFuture;

struct MyClient { api_key: String }

impl LlmClassifier for MyClient {
    fn classify<'a>(&'a self, prompt: &'a LlmPrompt) -> BoxFuture<'a, hs_predict::Result<LlmResponse>> {
        Box::pin(async move {
            // 1. Call your LLM API using prompt.system_text / prompt.user_text
            let raw_json: String = todo!("send HTTP request, receive text");
            // 2. Parse and return
            parse_llm_json(&raw_json)
        })
    }
}

Re-exports§

pub use mock::MockLlmClassifier;
pub use prompt::PromptBuilder;

Modules§

mock
Mock LLM classifier for unit testing.
prompt
Prompt builder for LLM-based HS code classification.

Structs§

LlmAlternative
An alternative HS code suggestion returned by the LLM.
LlmPrompt
Input passed to LlmClassifier::classify.
LlmResponse
Response that LlmClassifier::classify must return.

Traits§

LlmClassifier
Trait for LLM-based HS code classification.

Functions§

parse_llm_json
Parse a raw LLM API text response into an LlmResponse.