ailia_llm  1.4.0.0
Classes | Macros | Typedefs | Functions
ailia_llm.h File Reference

LLM inference library. More...

#include <wchar.h>
Include dependency graph for ailia_llm.h:

Go to the source code of this file.

Classes

struct  _AILIALLMChatMessage
 
struct  _AILIALLMMediaData
 Media data structure for multimodal processing. Audio is currently unsupported and reserved for future implementation. Images can be loaded from file path, encoded buffer (JPG, PNG, etc.), or raw RGB data. Supported encoded buffer formats are JPG, PNG, TGA, BMP, PSD, GIF, HDR, and PIC. More...
 
struct  _AILIALLMMultimodalChatMessage
 Multimodal chat message with media attachments. More...
 

Macros

#define AILIA_LLM_API   __stdcall
 
#define AILIA_LLM_STATUS_SUCCESS   (0)
 Successful. More...
 
#define AILIA_LLM_STATUS_INVALID_ARGUMENT   (-1)
 Incorrect argument. More...
 
#define AILIA_LLM_STATUS_ERROR_FILE_API   (-2)
 File access failed. More...
 
#define AILIA_LLM_STATUS_INVALID_VERSION   (-3)
 Incorrect struct version. More...
 
#define AILIA_LLM_STATUS_BROKEN   (-4)
 A corrupt file was passed. More...
 
#define AILIA_LLM_STATUS_MEMORY_INSUFFICIENT   (-5)
 Insufficient memory. More...
 
#define AILIA_LLM_STATUS_THREAD_ERROR   (-6)
 Thread creation failed. More...
 
#define AILIA_LLM_STATUS_INVALID_STATE   (-7)
 The internal status is incorrect. More...
 
#define AILIA_LLM_STATUS_CONTEXT_FULL   (-8)
 Exceeded the context length. More...
 
#define AILIA_LLM_STATUS_ERROR_BUFFER_API   (-9)
 Buffer read failed. More...
 
#define AILIA_LLM_STATUS_UNIMPLEMENTED   (-15)
 Unimplemented error. More...
 
#define AILIA_LLM_STATUS_OTHER_ERROR   (-128)
 Unknown error. More...
 

Typedefs

typedef struct _AILIALLMChatMessage AILIALLMChatMessage
 
typedef struct _AILIALLMMediaData AILIALLMMediaData
 Media data structure for multimodal processing. Audio is currently unsupported and reserved for future implementation. Images can be loaded from file path, encoded buffer (JPG, PNG, etc.), or raw RGB data. Supported encoded buffer formats are JPG, PNG, TGA, BMP, PSD, GIF, HDR, and PIC. More...
 
typedef struct _AILIALLMMultimodalChatMessage AILIALLMMultimodalChatMessage
 Multimodal chat message with media attachments. More...
 

Functions

AILIA_LLM_API int ailiaLLMGetBackendCount (unsigned int *env_count)
 Gets the number of available computational environments (CPU, GPU). More...
 
AILIA_LLM_API int ailiaLLMGetBackendName (const char **env, unsigned int env_idx)
 Gets the list of computational environments. More...
 
AILIA_LLM_API int ailiaLLMCreate (struct AILIALLM **llm)
 Creates a LLM instance. More...
 
AILIA_LLM_API int ailiaLLMOpenModelFileA (struct AILIALLM *llm, const char *path, unsigned int n_ctx)
 Open model file. More...
 
AILIA_LLM_API int ailiaLLMOpenModelFileW (struct AILIALLM *llm, const wchar_t *path, unsigned int n_ctx)
 
AILIA_LLM_API int ailiaLLMGetContextSize (struct AILIALLM *llm, unsigned int *context_size)
 Gets the size of context. More...
 
AILIA_LLM_API int ailiaLLMSetSamplingParams (struct AILIALLM *llm, unsigned int top_k, float top_p, float temp, unsigned int dist)
 Set the sampling parameter. More...
 
AILIA_LLM_API int ailiaLLMSetPrompt (struct AILIALLM *llm, const AILIALLMChatMessage *message, unsigned int message_cnt)
 Set the prompt. More...
 
AILIA_LLM_API int ailiaLLMGenerate (struct AILIALLM *llm, unsigned int *done)
 Perform generate. More...
 
AILIA_LLM_API int ailiaLLMGetDeltaTextSize (struct AILIALLM *llm, unsigned int *buf_size)
 Gets the size of text. (Include null) More...
 
AILIA_LLM_API int ailiaLLMGetDeltaText (struct AILIALLM *llm, char *text, unsigned int buf_size)
 Gets the decoded text. More...
 
AILIA_LLM_API int ailiaLLMGetTokenCount (struct AILIALLM *llm, unsigned int *cnt, const char *text)
 Gets the count of token. More...
 
AILIA_LLM_API int ailiaLLMGetPromptTokenCount (struct AILIALLM *llm, unsigned int *cnt)
 Gets the count of prompt token. More...
 
AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount (struct AILIALLM *llm, unsigned int *cnt)
 Gets the count of prompt token. More...
 
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA (struct AILIALLM *llm, const char *mmproj_path)
 Load multimodal projector file. More...
 
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW (struct AILIALLM *llm, const wchar_t *mmproj_path)
 
AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities (struct AILIALLM *llm, unsigned int *vision_support, unsigned int *audio_support)
 Check if multimodal features are supported. More...
 
AILIA_LLM_API int ailiaLLMSetMultimodalPrompt (struct AILIALLM *llm, const AILIALLMMultimodalChatMessage *message, unsigned int message_cnt)
 Set multimodal prompt. More...
 
AILIA_LLM_API void ailiaLLMDestroy (struct AILIALLM *llm)
 It destroys the LLM instance. More...
 

Detailed Description

LLM inference library.

Date
January 29, 2026

Macro Definition Documentation

◆ AILIA_LLM_API

#define AILIA_LLM_API   __stdcall

◆ AILIA_LLM_STATUS_BROKEN

#define AILIA_LLM_STATUS_BROKEN   (-4)

A corrupt file was passed.

Remarks
Please check model file are correct or not, and please pass correct model.

◆ AILIA_LLM_STATUS_CONTEXT_FULL

#define AILIA_LLM_STATUS_CONTEXT_FULL   (-8)

Exceeded the context length.

Remarks
Please reduce the context length given to SetPrompt.

◆ AILIA_LLM_STATUS_ERROR_BUFFER_API

#define AILIA_LLM_STATUS_ERROR_BUFFER_API   (-9)

Buffer read failed.

Remarks
Please check that the buffer format and size are correct.

◆ AILIA_LLM_STATUS_ERROR_FILE_API

#define AILIA_LLM_STATUS_ERROR_FILE_API   (-2)

File access failed.

Remarks
Please check file is exist or not, and check access permission.

◆ AILIA_LLM_STATUS_INVALID_ARGUMENT

#define AILIA_LLM_STATUS_INVALID_ARGUMENT   (-1)

Incorrect argument.

Remarks
Please check argument of called API.

◆ AILIA_LLM_STATUS_INVALID_STATE

#define AILIA_LLM_STATUS_INVALID_STATE   (-7)

The internal status is incorrect.

Remarks
Please check API document and API call steps.

◆ AILIA_LLM_STATUS_INVALID_VERSION

#define AILIA_LLM_STATUS_INVALID_VERSION   (-3)

Incorrect struct version.

Remarks
Please check struct version that passed with API and please pass correct struct version.

◆ AILIA_LLM_STATUS_MEMORY_INSUFFICIENT

#define AILIA_LLM_STATUS_MEMORY_INSUFFICIENT   (-5)

Insufficient memory.

Remarks
Please check usage of main memory and VRAM. And please call API after free memory.

◆ AILIA_LLM_STATUS_OTHER_ERROR

#define AILIA_LLM_STATUS_OTHER_ERROR   (-128)

Unknown error.

Remarks
The misc error has been occurred.

◆ AILIA_LLM_STATUS_SUCCESS

#define AILIA_LLM_STATUS_SUCCESS   (0)

Successful.

◆ AILIA_LLM_STATUS_THREAD_ERROR

#define AILIA_LLM_STATUS_THREAD_ERROR   (-6)

Thread creation failed.

Remarks
Please check usage of system resource (e.g. thread). And please call API after release system resources.

◆ AILIA_LLM_STATUS_UNIMPLEMENTED

#define AILIA_LLM_STATUS_UNIMPLEMENTED   (-15)

Unimplemented error.

Remarks
The called API are not available on current environment. Please contact support desk that described on document.

Typedef Documentation

◆ AILIALLMChatMessage

◆ AILIALLMMediaData

Media data structure for multimodal processing. Audio is currently unsupported and reserved for future implementation. Images can be loaded from file path, encoded buffer (JPG, PNG, etc.), or raw RGB data. Supported encoded buffer formats are JPG, PNG, TGA, BMP, PSD, GIF, HDR, and PIC.

◆ AILIALLMMultimodalChatMessage

Multimodal chat message with media attachments.

Function Documentation

◆ ailiaLLMCreate()

AILIA_LLM_API int ailiaLLMCreate ( struct AILIALLM **  llm)

Creates a LLM instance.

Parameters
llmA pointer to the LLM instance pointer
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Creates a LLM instance.

◆ ailiaLLMDestroy()

AILIA_LLM_API void ailiaLLMDestroy ( struct AILIALLM *  llm)

It destroys the LLM instance.

Parameters
llmA LLM instance pointer

◆ ailiaLLMGenerate()

AILIA_LLM_API int ailiaLLMGenerate ( struct AILIALLM *  llm,
unsigned int *  done 
)

Perform generate.

Parameters
llmA LLM instance pointer
doneGeneration complete?
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

The decoded result is obtained through the ailiaLLMGetDeltaText API. Each call to ailiaLLMGenerate decodes one token at a time. The value of done is 0 or 1. If done is 1, the generation is complete.

◆ ailiaLLMGetBackendCount()

AILIA_LLM_API int ailiaLLMGetBackendCount ( unsigned int *  env_count)

Gets the number of available computational environments (CPU, GPU).

Parameters
env_countThe storage location of the number of computational environment information
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

◆ ailiaLLMGetBackendName()

AILIA_LLM_API int ailiaLLMGetBackendName ( const char **  env,
unsigned int  env_idx 
)

Gets the list of computational environments.

Parameters
envThe storage location of the computational environment information (valid until the AILIANetwork instance is destroyed)
env_idxThe index of the computational environment information (0 to ailiaLLMGetBackendCount() -1)
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

◆ ailiaLLMGetContextSize()

AILIA_LLM_API int ailiaLLMGetContextSize ( struct AILIALLM *  llm,
unsigned int *  context_size 
)

Gets the size of context.

Parameters
llmA LLM instance pointer
lenThe length of context
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

◆ ailiaLLMGetDeltaText()

AILIA_LLM_API int ailiaLLMGetDeltaText ( struct AILIALLM *  llm,
char *  text,
unsigned int  buf_size 
)

Gets the decoded text.

Parameters
llmA LLM instance pointer
textText(UTF8)
buf_sizeBuffer size
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

If ailiaLLMGenerate() is not run at all, the function returns AILIA_LLM_STATUS_INVALID_STATE .

◆ ailiaLLMGetDeltaTextSize()

AILIA_LLM_API int ailiaLLMGetDeltaTextSize ( struct AILIALLM *  llm,
unsigned int *  buf_size 
)

Gets the size of text. (Include null)

Parameters
llmA LLM instance pointer
buf_sizeThe length of text
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

◆ ailiaLLMGetGeneratedTokenCount()

AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount ( struct AILIALLM *  llm,
unsigned int *  cnt 
)

Gets the count of prompt token.

Parameters
llmA LLM instance pointer
cntThe count of generated token
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

It can be called after calling ailiaLLMGenerate.

◆ ailiaLLMGetMultimodalCapabilities()

AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities ( struct AILIALLM *  llm,
unsigned int *  vision_support,
unsigned int *  audio_support 
)

Check if multimodal features are supported.

Parameters
llmA LLM instance pointer
vision_supportWhether image processing is supported
audio_supportWhether audio processing is supported
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Can be called after ailiaLLMOpenMultimodalProjectorFile.

◆ ailiaLLMGetPromptTokenCount()

AILIA_LLM_API int ailiaLLMGetPromptTokenCount ( struct AILIALLM *  llm,
unsigned int *  cnt 
)

Gets the count of prompt token.

Parameters
llmA LLM instance pointer
cntThe count of prompt token
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

It can be called after calling ailiaLLMSetPrompt.

◆ ailiaLLMGetTokenCount()

AILIA_LLM_API int ailiaLLMGetTokenCount ( struct AILIALLM *  llm,
unsigned int *  cnt,
const char *  text 
)

Gets the count of token.

Parameters
llmA LLM instance pointer
cntThe count of token
textText(UTF8)
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

◆ ailiaLLMOpenModelFileA()

AILIA_LLM_API int ailiaLLMOpenModelFileA ( struct AILIALLM *  llm,
const char *  path,
unsigned int  n_ctx 
)

Open model file.

Parameters
llmA pointer to the LLM instance pointer
pathPath for GGUF
n_ctxContext length for model (0 is model default)
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Open a model file for GGUF.

◆ ailiaLLMOpenModelFileW()

AILIA_LLM_API int ailiaLLMOpenModelFileW ( struct AILIALLM *  llm,
const wchar_t *  path,
unsigned int  n_ctx 
)

◆ ailiaLLMOpenMultimodalProjectorFileA()

AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA ( struct AILIALLM *  llm,
const char *  mmproj_path 
)

Load multimodal projector file.

Parameters
llmA LLM instance pointer
mmproj_pathPath to the MMPROJ file (GGUF format)
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

To use multimodal features, you must first load the text model with ailiaLLMOpenModelFile, then load the multimodal projector with this function.

◆ ailiaLLMOpenMultimodalProjectorFileW()

AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW ( struct AILIALLM *  llm,
const wchar_t *  mmproj_path 
)

◆ ailiaLLMSetMultimodalPrompt()

AILIA_LLM_API int ailiaLLMSetMultimodalPrompt ( struct AILIALLM *  llm,
const AILIALLMMultimodalChatMessage message,
unsigned int  message_cnt 
)

Set multimodal prompt.

Parameters
llmA LLM instance pointer
messageArray of multimodal messages
message_cntNumber of messages
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Set multimodal prompt. Include <media> placeholders in message content, and set corresponding media data in media_data. Example: "Describe this image: <__media__>" The content of message is copied internally, so it can be freed after the call. Images can be loaded from file path, encoded buffer (JPG, PNG, etc.), or raw RGB data.

◆ ailiaLLMSetPrompt()

AILIA_LLM_API int ailiaLLMSetPrompt ( struct AILIALLM *  llm,
const AILIALLMChatMessage message,
unsigned int  message_cnt 
)

Set the prompt.

Parameters
llmA pointer to the LLM instance pointer
messageArray of messages
message_cntNumber of messages
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Set the prompt to query the LLM. Please include ChatHistory in the message as well. The contents of the message are copied internally, so you can free them after the call.

◆ ailiaLLMSetSamplingParams()

AILIA_LLM_API int ailiaLLMSetSamplingParams ( struct AILIALLM *  llm,
unsigned int  top_k,
float  top_p,
float  temp,
unsigned int  dist 
)

Set the sampling parameter.

Parameters
llmA pointer to the LLM instance pointer
top_kSampling probability value's top number, default 40
top_pSampling probability value range, default 0.9 (0.9 to 1.0)
tempTemperature parameter, default 0.4
distSeed, default 1234
Returns
If this function is successful, it returns AILIA_LLM_STATUS_SUCCESS , or an error code otherwise.

Set LLM sampling parameters. Must be run before ailiaLLMSetPrompt.