.TH "ttypt/auren.h" 3 "axil-auren" \" -*- nroff -*- .ad l .nh .SH NAME ttypt/auren.h \- Local LLM inference and embeddings (llama\&.cpp), served as an axil module\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBauren_config\fP" .br .ti -1c .RI "struct \fBauren_message\fP" .br .ti -1c .RI "struct \fBauren_media\fP" .br .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBAUREN_CHOICE_MAX\fP 26" .br .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef void(* \fBauren_token_cb\fP) (void *user, const char *chunk, size_t len)" .br .ti -1c .RI "typedef void(* \fBauren_token_full_cb\fP) (void *user, int32_t token, const char *chunk, size_t len)" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "struct auren_context * \fBauren_create\fP (const struct \fBauren_config\fP *cfg)" .br .ti -1c .RI "void \fBauren_free\fP (struct auren_context *ctx)" .br .ti -1c .RI "long \fBauren_generate\fP (struct auren_context *ctx, const char *prompt, char *out, size_t out_size)" .br .ti -1c .RI "int \fBauren_generate_stream\fP (struct auren_context *ctx, const char *prompt, \fBauren_token_cb\fP cb, void *user)" .br .ti -1c .RI "int \fBauren_generate_stream_full\fP (struct auren_context *ctx, const char *prompt, \fBauren_token_full_cb\fP cb, void *user)" .br .ti -1c .RI "int \fBauren_embed\fP (struct auren_context *ctx, const char *text, float *out, size_t out_dim)" .br .ti -1c .RI "int \fBauren_n_embd\fP (struct auren_context *ctx)" .br .ti -1c .RI "int \fBauren_prime\fP (struct auren_context *ctx, const char *prompt)" .br .ti -1c .RI "int \fBauren_prime_block\fP (struct auren_context *ctx, uint64_t block_hash, const char *text)" .br .ti -1c .RI "int \fBauren_n_ctx\fP (struct auren_context *ctx)" .br .ti -1c .RI "void \fBauren_set_seq\fP (struct auren_context *ctx, uint32_t seq_id)" .br .ti -1c .RI "int \fBauren_set_grammar\fP (struct auren_context *ctx, const char *grammar_str)" .br .ti -1c .RI "void \fBauren_set_max_gen\fP (struct auren_context *ctx, int32_t n)" .br .ti -1c .RI "int \fBauren_set_temperature\fP (struct auren_context *ctx, float temperature)" .br .ti -1c .RI "struct llama_sampler * \fBauren_sampler_create\fP (struct auren_context *ctx, const struct \fBauren_config\fP *cfg)" .br .ti -1c .RI "int \fBauren_sampler_add_grammar\fP (struct auren_context *ctx, struct llama_sampler *sampler, const char *grammar_str)" .br .ti -1c .RI "void \fBauren_sampler_free\fP (struct llama_sampler *smpl)" .br .ti -1c .RI "int \fBauren_next\fP (struct auren_context *ctx, struct llama_sampler *sampler, char *out, size_t out_size)" .br .ti -1c .RI "int \fBauren_chat\fP (struct auren_context *ctx, const struct \fBauren_message\fP *msgs, size_t n_msgs, const char *prev_prompt, \fBauren_token_cb\fP cb, void *user)" .br .ti -1c .RI "int \fBauren_has_vision\fP (struct auren_context *ctx)" .br .ti -1c .RI "const char * \fBauren_media_marker\fP (void)" .br .ti -1c .RI "int \fBauren_chat_media\fP (struct auren_context *ctx, const struct \fBauren_message\fP *msgs, size_t n_msgs, const struct \fBauren_media\fP *media, size_t n_media, \fBauren_token_cb\fP cb, void *user)" .br .ti -1c .RI "int \fBauren_render\fP (struct auren_context *ctx, const struct \fBauren_message\fP *msgs, size_t n_msgs, bool add_ass, char **out, size_t *out_len)" .br .ti -1c .RI "void \fBauren_reset\fP (struct auren_context *ctx)" .br .ti -1c .RI "void \fBauren_anchor_start\fP (struct auren_context *ctx)" .br .ti -1c .RI "void \fBauren_anchor_end\fP (struct auren_context *ctx)" .br .ti -1c .RI "void \fBauren_compress\fP (struct auren_context *ctx, uint32_t limit)" .br .ti -1c .RI "void \fBauren_set_eos_bias\fP (struct auren_context *ctx, int32_t start_tokens, float max_bias)" .br .ti -1c .RI "int \fBauren_binary_choice_eval\fP (struct auren_context *ctx, const char *prompt, const char *choice_pos, const char *choice_neg, double *probability_out, double *margin_out, bool *decision_out, double threshold)" .br .ti -1c .RI "int \fBauren_choice_eval\fP (struct auren_context *ctx, const struct \fBauren_message\fP *msgs, size_t n_msgs, int n_options, double *probs_out)" .br .in -1c .SH "Detailed Description" .PP Local LLM inference and embeddings (llama\&.cpp), served as an axil module\&. Wraps llama\&.cpp behind a single C API: generation, streaming, embeddings, conversation history, sliding-window compression and GBNF constrained decoding\&. All functions are extern "C"-safe\&. Formerly known as libqllm (\fBttypt/qllm\&.h\fP)\&. .SH "Macro Definition Documentation" .PP .SS "#define AUREN_CHOICE_MAX 26" Most options a closed choice question may declare (letters A\&.\&.Z)\&. .SH "Typedef Documentation" .PP .SS "typedef void(* auren_token_cb) (void *user, const char *chunk, size_t len)" Streaming callback type\&. \fRchunk\fP is a piece of text from generation\&. \fRlen\fP is the chunk size\&. .SS "typedef void(* auren_token_full_cb) (void *user, int32_t token, const char *chunk, size_t len)" Full streaming callback receiving token ID and UTF-8 chunk\&. .SH "Function Documentation" .PP .SS "void auren_anchor_end (struct auren_context * ctx)" Mark the end of the protected region of the KV cache\&. Call after generation completes\&. .SS "void auren_anchor_start (struct auren_context * ctx)" Mark the start of the protected region of the KV cache\&. Call before priming a prompt so that \fBauren_compress()\fP keeps this region (the current prompt + response) while evicting older tokens\&. .SS "int auren_binary_choice_eval (struct auren_context * ctx, const char * prompt, const char * choice_pos, const char * choice_neg, double * probability_out, double * margin_out, bool * decision_out, double threshold)" Binary decision evaluation using raw next-token logits (zero decode passes)\&. Evaluates the prompt forward pass, extracts logits of the last token, compares affirmative tokens (choice_pos or default "y"/"yes") vs negative tokens (choice_neg or default "n"/"no"), and computes probability = sigmoid(L_pos - L_neg)\&. .PP Returns 0 on success, < 0 on error\&. .SS "int auren_chat (struct auren_context * ctx, const struct \fBauren_message\fP * msgs, size_t n_msgs, const char * prev_prompt, \fBauren_token_cb\fP cb, void * user)" Streaming chat completion\&. Renders the full conversation via the model's chat template, primes the context with only the newly-added increment, then streams via cb()\&. prev_prompt is the previously rendered prompt (or NULL for the first turn)\&. Returns 0 on success, < 0 on error\&. .SS "int auren_chat_media (struct auren_context * ctx, const struct \fBauren_message\fP * msgs, size_t n_msgs, const struct \fBauren_media\fP * media, size_t n_media, \fBauren_token_cb\fP cb, void * user)" Multimodal streaming chat completion\&. Message content strings must contain one \fBauren_media_marker()\fP per entry in media[0\&.\&.n_media-1], in order\&. When n_media == 0, behaves identically to \fBauren_chat()\fP\&. Returns 0 on success, < 0 on error\&. .SS "int auren_choice_eval (struct auren_context * ctx, const struct \fBauren_message\fP * msgs, size_t n_msgs, int n_options, double * probs_out)" Closed multiple-choice evaluation by next-token logits\&. The caller letters its options A, B, C \&.\&.\&. in the prompt messages; this reads the model's first answer token (one forward pass, no sampling) and returns the index of the most likely option letter, with softmax probabilities over the options in probs_out[0\&.\&.n_options-1]\&. Returns the best index (>= 0) or < 0 on error\&. .SS "void auren_compress (struct auren_context * ctx, uint32_t limit)" Sliding-window compression: shrink the KV sequence to \fRlimit\fP tokens, preferring to evict the oldest prefix and the tail beyond the anchored region\&. limit == 0 clears the whole sequence\&. .SS "struct auren_context * auren_create (const struct \fBauren_config\fP * cfg)" Create a new Auren context\&. Returns NULL on failure\&. .SS "int auren_embed (struct auren_context * ctx, const char * text, float * out, size_t out_dim)" Compute embeddings for the entire input text\&. Writes a vector of size >= model embedding dimension\&. .PP Returns: >0 = embedding dimension (success) <0 = error .SS "void auren_free (struct auren_context * ctx)" Free an Auren context\&. .SS "long auren_generate (struct auren_context * ctx, const char * prompt, char * out, size_t out_size)" Non-streaming generation\&. Writes into \fRout\fP (user allocated)\&. Returns number of bytes written, or -1 on error\&. .SS "int auren_generate_stream (struct auren_context * ctx, const char * prompt, \fBauren_token_cb\fP cb, void * user)" Streaming generation\&. Calls cb() for each generated text chunk\&. Returns 0 on success, < 0 on error\&. .SS "int auren_generate_stream_full (struct auren_context * ctx, const char * prompt, \fBauren_token_full_cb\fP cb, void * user)" Streaming generation with full token metadata\&. Calls cb() for each generated token ID and text chunk\&. Returns 0 on success, < 0 on error\&. .SS "int auren_has_vision (struct auren_context * ctx)" Return 1 if the context has a loaded multimodal vision projector (mmproj), 0 otherwise\&. .SS "const char * auren_media_marker (void )" Return the media placeholder marker expected inside message content (e\&.g\&. "<__media__>")\&. .SS "int auren_n_ctx (struct auren_context * ctx)" Get the actual context size used (returns 0 if ctx invalid)\&. .SS "int auren_n_embd (struct auren_context * ctx)" Get the model embedding dimension (returns 0 if ctx invalid)\&. .SS "int auren_next (struct auren_context * ctx, struct llama_sampler * sampler, char * out, size_t out_size)" Generate the next token as text\&. .PP \fRsampler\fP may be NULL, in which case the context's internal sampler chain is used\&. .PP Returns: >0 number of bytes written to 'out' (UTF-8, NUL-terminated) 0 end of generation (EOS/EOG) <0 error .SS "int auren_prime (struct auren_context * ctx, const char * prompt)" Prime the context with a prompt\&. .PP Returns: 0 on success <0 on error .SS "int auren_prime_block (struct auren_context * ctx, uint64_t block_hash, const char * text)" Prime the context with a content-addressed prompt block\&. If block_hash matches a pre-evaluated cached block at the current KV context position, prompt evaluation is bypassed (zero decode cost)\&. .PP Returns: 0 on success <0 on error .SS "int auren_render (struct auren_context * ctx, const struct \fBauren_message\fP * msgs, size_t n_msgs, bool add_ass, char ** out, size_t * out_len)" Render a conversation with the model's chat template\&. add_ass=true appends the assistant prefix (for priming generation); add_ass=false renders the exact conversation state\&. On success *out is malloc'd (caller frees) and *out_len is set\&. Returns 0 on success, < 0 on error\&. .SS "void auren_reset (struct auren_context * ctx)" Reset the context's generation state: clears the KV cache, keeps the loaded model and context alive\&. .SS "int auren_sampler_add_grammar (struct auren_context * ctx, struct llama_sampler * sampler, const char * grammar_str)" Append a GBNF grammar sampler to an existing sampler chain\&. Returns 0 on success, -1 on error\&. .SS "struct llama_sampler * auren_sampler_create (struct auren_context * ctx, const struct \fBauren_config\fP * cfg)" Create a new sampler chain (eos_bias + penalties + top_k/top_p + temp + dist) based on config\&. Returns NULL on failure\&. .SS "void auren_sampler_free (struct llama_sampler * smpl)" Free a sampler chain returned by \fBauren_sampler_create()\fP/ \fBauren_sampler_add_grammar()\fP\&. Safe to call with NULL\&. .SS "void auren_set_eos_bias (struct auren_context * ctx, int32_t start_tokens, float max_bias)" Configure the EOS-bias sampler\&. After \fRstart_tokens\fP have been generated the sampler ramps the end-of-turn token's logit up to \fRmax_bias\fP, so long generations terminate on their own\&. .SS "int auren_set_grammar (struct auren_context * ctx, const char * grammar_str)" Set a GBNF grammar for constrained decoding\&. Pass NULL to disable grammar\&. Returns 0 on success, -1 on error\&. .SS "void auren_set_max_gen (struct auren_context * ctx, int32_t n)" Cap how many tokens a single generate/chat call may produce\&. 0 removes the cap (generation is then bounded only by the context window)\&. Callers that need a short answer (classification, judge) must set this so a runaway generation cannot occupy the engine worker for the whole window\&. .SS "void auren_set_seq (struct auren_context * ctx, uint32_t seq_id)" Set the current sequence ID for generation (multi-sequence support)\&. .SS "int auren_set_temperature (struct auren_context * ctx, float temperature)" Override the sampling temperature on an existing context\&. temperature < 0\&.0f : restore the context's creation-time default temperature temperature == 0\&.0f: deterministic greedy decoding (llama_sampler_init_greedy) temperature > 0\&.0f : temperature + distribution sampling Returns 0 on success, -1 on error\&. .SH "Author" .PP Generated automatically by Doxygen for axil-auren from the source code\&.