ttypt/auren.h(3)axil-auren

NAME

ttypt/auren.h - Local LLM inference and embeddings (llama.cpp), served as an axil module.

SYNOPSIS

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Data Structures

struct auren_config
struct auren_message
struct auren_media

Macros

#define AUREN_CHOICE_MAX 26

Typedefs

typedef void(* auren_token_cb) (void *user, const char *chunk, size_t len)
typedef void(* auren_token_full_cb) (void *user, int32_t token, const char *chunk, size_t len)

Functions

struct auren_context * auren_create (const struct auren_config *cfg)
void auren_free (struct auren_context *ctx)
long auren_generate (struct auren_context *ctx, const char *prompt, char *out, size_t out_size)
int auren_generate_stream (struct auren_context *ctx, const char *prompt, auren_token_cb cb, void *user)
int auren_generate_stream_full (struct auren_context *ctx, const char *prompt, auren_token_full_cb cb, void *user)
int auren_embed (struct auren_context *ctx, const char *text, float *out, size_t out_dim)
int auren_n_embd (struct auren_context *ctx)
int auren_prime (struct auren_context *ctx, const char *prompt)
int auren_prime_block (struct auren_context *ctx, uint64_t block_hash, const char *text)
int auren_n_ctx (struct auren_context *ctx)
void auren_set_seq (struct auren_context *ctx, uint32_t seq_id)
int auren_set_grammar (struct auren_context *ctx, const char *grammar_str)
void auren_set_max_gen (struct auren_context *ctx, int32_t n)
int auren_set_temperature (struct auren_context *ctx, float temperature)
struct llama_sampler * auren_sampler_create (struct auren_context *ctx, const struct auren_config *cfg)
int auren_sampler_add_grammar (struct auren_context *ctx, struct llama_sampler *sampler, const char *grammar_str)
void auren_sampler_free (struct llama_sampler *smpl)
int auren_next (struct auren_context *ctx, struct llama_sampler *sampler, char *out, size_t out_size)
int auren_chat (struct auren_context *ctx, const struct auren_message *msgs, size_t n_msgs, const char *prev_prompt, auren_token_cb cb, void *user)
int auren_has_vision (struct auren_context *ctx)
const char * auren_media_marker (void)
int auren_chat_media (struct auren_context *ctx, const struct auren_message *msgs, size_t n_msgs, const struct auren_media *media, size_t n_media, auren_token_cb cb, void *user)
int auren_render (struct auren_context *ctx, const struct auren_message *msgs, size_t n_msgs, bool add_ass, char **out, size_t *out_len)
void auren_reset (struct auren_context *ctx)
void auren_anchor_start (struct auren_context *ctx)
void auren_anchor_end (struct auren_context *ctx)
void auren_compress (struct auren_context *ctx, uint32_t limit)
void auren_set_eos_bias (struct auren_context *ctx, int32_t start_tokens, float max_bias)
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)
int auren_choice_eval (struct auren_context *ctx, const struct auren_message *msgs, size_t n_msgs, int n_options, double *probs_out)

Detailed Description

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 (ttypt/qllm.h).

Macro Definition Documentation

#define AUREN_CHOICE_MAX 26

Most options a closed choice question may declare (letters A..Z).

Typedef Documentation

typedef void(* auren_token_cb) (void *user, const char *chunk, size_t len)

Streaming callback type. chunk is a piece of text from generation. len is the chunk size.

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.

Function Documentation

void auren_anchor_end (struct auren_context * ctx)

Mark the end of the protected region of the KV cache. Call after generation completes.

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 auren_compress() keeps this region (the current prompt + response) while evicting older tokens.

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).

Returns 0 on success, < 0 on error.

int auren_chat (struct auren_context * ctx, const struct auren_message * msgs, size_t n_msgs, const char * prev_prompt, auren_token_cb 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.

int auren_chat_media (struct auren_context * ctx, const struct auren_message * msgs, size_t n_msgs, const struct auren_media * media, size_t n_media, auren_token_cb cb, void * user)

Multimodal streaming chat completion. Message content strings must contain one auren_media_marker() per entry in media[0..n_media-1], in order. When n_media == 0, behaves identically to auren_chat(). Returns 0 on success, < 0 on error.

int auren_choice_eval (struct auren_context * ctx, const struct auren_message * 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.

void auren_compress (struct auren_context * ctx, uint32_t limit)

Sliding-window compression: shrink the KV sequence to limit tokens, preferring to evict the oldest prefix and the tail beyond the anchored region. limit == 0 clears the whole sequence.

struct auren_context * auren_create (const struct auren_config * cfg)

Create a new Auren context. Returns NULL on failure.

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.

Returns: >0 = embedding dimension (success) <0 = error

void auren_free (struct auren_context * ctx)

Free an Auren context.

long auren_generate (struct auren_context * ctx, const char * prompt, char * out, size_t out_size)

Non-streaming generation. Writes into out (user allocated). Returns number of bytes written, or -1 on error.

int auren_generate_stream (struct auren_context * ctx, const char * prompt, auren_token_cb cb, void * user)

Streaming generation. Calls cb() for each generated text chunk. Returns 0 on success, < 0 on error.

int auren_generate_stream_full (struct auren_context * ctx, const char * prompt, auren_token_full_cb 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.

int auren_has_vision (struct auren_context * ctx)

Return 1 if the context has a loaded multimodal vision projector (mmproj), 0 otherwise.

const char * auren_media_marker (void )

Return the media placeholder marker expected inside message content (e.g. "<__media__>").

int auren_n_ctx (struct auren_context * ctx)

Get the actual context size used (returns 0 if ctx invalid).

int auren_n_embd (struct auren_context * ctx)

Get the model embedding dimension (returns 0 if ctx invalid).

int auren_next (struct auren_context * ctx, struct llama_sampler * sampler, char * out, size_t out_size)

Generate the next token as text.

sampler may be NULL, in which case the context's internal sampler chain is used.

Returns: >0 number of bytes written to 'out' (UTF-8, NUL-terminated) 0 end of generation (EOS/EOG) <0 error

int auren_prime (struct auren_context * ctx, const char * prompt)

Prime the context with a prompt.

Returns: 0 on success <0 on error

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).

Returns: 0 on success <0 on error

int auren_render (struct auren_context * ctx, const struct auren_message * 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.

void auren_reset (struct auren_context * ctx)

Reset the context's generation state: clears the KV cache, keeps the loaded model and context alive.

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.

struct llama_sampler * auren_sampler_create (struct auren_context * ctx, const struct auren_config * cfg)

Create a new sampler chain (eos_bias + penalties + top_k/top_p + temp + dist) based on config. Returns NULL on failure.

void auren_sampler_free (struct llama_sampler * smpl)

Free a sampler chain returned by auren_sampler_create()/ auren_sampler_add_grammar(). Safe to call with NULL.

void auren_set_eos_bias (struct auren_context * ctx, int32_t start_tokens, float max_bias)

Configure the EOS-bias sampler. After start_tokens have been generated the sampler ramps the end-of-turn token's logit up to max_bias, so long generations terminate on their own.

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.

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.

void auren_set_seq (struct auren_context * ctx, uint32_t seq_id)

Set the current sequence ID for generation (multi-sequence support).

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.

Author

Generated automatically by Doxygen for axil-auren from the source code.