#ifndef LANGDET_H #define LANGDET_H #include #ifdef __cplusplus extern "C" { #endif #define LANGDET_NUM_LABELS 20 #define LANGDET_MAX_TOKENS 512 typedef struct langdet langdet_t; typedef struct { const char *label; float score; int tokens; int truncated; /* Label pointers belong to the detector and remain valid until langdet_free(). * Scores are stored in this result, in the checkpoint's id2label order. */ const char *labels[LANGDET_NUM_LABELS]; float scores[LANGDET_NUM_LABELS]; } langdet_result_t; /* Library calls must not overlap across application threads, even for different * handles. Internal CPU workers cooperate on one prediction at a time. */ /* Load the model, tokenizer, classifier, and labels from model_dir. * n_threads is 1..16, or 0 to detect the CPU count and cap it at 16. * On macOS it sets kernel workers; Accelerate manages its own threads. * On Linux it sets OpenBLAS threads; the auxiliary kernel pool stays serial. * Return NULL on failure. An optional err[errlen] receives a NUL-terminated * message on failure and is cleared on success. Model-file readers may also * write diagnostics to stderr. */ langdet_t *langdet_open(const char *model_dir, int n_threads, char *err, size_t errlen); /* Classify NUL-terminated UTF-8 text. Truncate to 512 tokens, retaining . * Empty text is accepted but does not yield a meaningful language prediction. * Return 0 on success, or -1 with a zeroed result on failure. The optional * error buffer follows the same contract as langdet_open(). */ int langdet_predict(langdet_t *detector, const char *text, langdet_result_t *result, char *err, size_t errlen); /* Release the detector and its resources. NULL is accepted. */ void langdet_free(langdet_t *detector); #ifdef __cplusplus } #endif #endif /* LANGDET_H */