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 sendLlmResponse— the expected return value from your implementationparse_llm_json— helper that strips markdown fences and deserialises the LLM’s JSON reply into anLlmResponseMockLlmClassifier— deterministic stub for unit tests (mockfeature)
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§
Structs§
- LlmAlternative
- An alternative HS code suggestion returned by the LLM.
- LlmPrompt
- Input passed to
LlmClassifier::classify. - LlmResponse
- Response that
LlmClassifier::classifymust return.
Traits§
- LlmClassifier
- Trait for LLM-based HS code classification.
Functions§
- parse_
llm_ json - Parse a raw LLM API text response into an
LlmResponse.