|
ailia_llm
1.4.0.0
|
LLM inference library. More...
#include <wchar.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... | |
LLM inference library.
| #define AILIA_LLM_API __stdcall |
| #define AILIA_LLM_STATUS_BROKEN (-4) |
A corrupt file was passed.
| #define AILIA_LLM_STATUS_CONTEXT_FULL (-8) |
Exceeded the context length.
| #define AILIA_LLM_STATUS_ERROR_BUFFER_API (-9) |
Buffer read failed.
| #define AILIA_LLM_STATUS_ERROR_FILE_API (-2) |
File access failed.
| #define AILIA_LLM_STATUS_INVALID_ARGUMENT (-1) |
Incorrect argument.
| #define AILIA_LLM_STATUS_INVALID_STATE (-7) |
The internal status is incorrect.
| #define AILIA_LLM_STATUS_INVALID_VERSION (-3) |
Incorrect struct version.
| #define AILIA_LLM_STATUS_MEMORY_INSUFFICIENT (-5) |
Insufficient memory.
| #define AILIA_LLM_STATUS_OTHER_ERROR (-128) |
Unknown error.
| #define AILIA_LLM_STATUS_SUCCESS (0) |
Successful.
| #define AILIA_LLM_STATUS_THREAD_ERROR (-6) |
Thread creation failed.
| #define AILIA_LLM_STATUS_UNIMPLEMENTED (-15) |
Unimplemented error.
| 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.
| typedef struct _AILIALLMMultimodalChatMessage AILIALLMMultimodalChatMessage |
Multimodal chat message with media attachments.
| AILIA_LLM_API int ailiaLLMCreate | ( | struct AILIALLM ** | llm | ) |
Creates a LLM instance.
| llm | A pointer to the LLM instance pointer |
Creates a LLM instance.
| AILIA_LLM_API void ailiaLLMDestroy | ( | struct AILIALLM * | llm | ) |
It destroys the LLM instance.
| llm | A LLM instance pointer |
| AILIA_LLM_API int ailiaLLMGenerate | ( | struct AILIALLM * | llm, |
| unsigned int * | done | ||
| ) |
Perform generate.
| llm | A LLM instance pointer |
| done | Generation complete? |
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.
| AILIA_LLM_API int ailiaLLMGetBackendCount | ( | unsigned int * | env_count | ) |
Gets the number of available computational environments (CPU, GPU).
| env_count | The storage location of the number of computational environment information |
| AILIA_LLM_API int ailiaLLMGetBackendName | ( | const char ** | env, |
| unsigned int | env_idx | ||
| ) |
Gets the list of computational environments.
| env | The storage location of the computational environment information (valid until the AILIANetwork instance is destroyed) |
| env_idx | The index of the computational environment information (0 to ailiaLLMGetBackendCount() -1) |
| AILIA_LLM_API int ailiaLLMGetContextSize | ( | struct AILIALLM * | llm, |
| unsigned int * | context_size | ||
| ) |
Gets the size of context.
| llm | A LLM instance pointer |
| len | The length of context |
| AILIA_LLM_API int ailiaLLMGetDeltaText | ( | struct AILIALLM * | llm, |
| char * | text, | ||
| unsigned int | buf_size | ||
| ) |
Gets the decoded text.
| llm | A LLM instance pointer |
| text | Text(UTF8) |
| buf_size | Buffer size |
If ailiaLLMGenerate() is not run at all, the function returns AILIA_LLM_STATUS_INVALID_STATE .
| AILIA_LLM_API int ailiaLLMGetDeltaTextSize | ( | struct AILIALLM * | llm, |
| unsigned int * | buf_size | ||
| ) |
Gets the size of text. (Include null)
| llm | A LLM instance pointer |
| buf_size | The length of text |
| AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount | ( | struct AILIALLM * | llm, |
| unsigned int * | cnt | ||
| ) |
Gets the count of prompt token.
| llm | A LLM instance pointer |
| cnt | The count of generated token |
It can be called after calling ailiaLLMGenerate.
| AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities | ( | struct AILIALLM * | llm, |
| unsigned int * | vision_support, | ||
| unsigned int * | audio_support | ||
| ) |
Check if multimodal features are supported.
| llm | A LLM instance pointer |
| vision_support | Whether image processing is supported |
| audio_support | Whether audio processing is supported |
Can be called after ailiaLLMOpenMultimodalProjectorFile.
| AILIA_LLM_API int ailiaLLMGetPromptTokenCount | ( | struct AILIALLM * | llm, |
| unsigned int * | cnt | ||
| ) |
Gets the count of prompt token.
| llm | A LLM instance pointer |
| cnt | The count of prompt token |
It can be called after calling ailiaLLMSetPrompt.
| AILIA_LLM_API int ailiaLLMGetTokenCount | ( | struct AILIALLM * | llm, |
| unsigned int * | cnt, | ||
| const char * | text | ||
| ) |
Gets the count of token.
| llm | A LLM instance pointer |
| cnt | The count of token |
| text | Text(UTF8) |
| AILIA_LLM_API int ailiaLLMOpenModelFileA | ( | struct AILIALLM * | llm, |
| const char * | path, | ||
| unsigned int | n_ctx | ||
| ) |
Open model file.
| llm | A pointer to the LLM instance pointer |
| path | Path for GGUF |
| n_ctx | Context length for model (0 is model default) |
Open a model file for GGUF.
| AILIA_LLM_API int ailiaLLMOpenModelFileW | ( | struct AILIALLM * | llm, |
| const wchar_t * | path, | ||
| unsigned int | n_ctx | ||
| ) |
| AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA | ( | struct AILIALLM * | llm, |
| const char * | mmproj_path | ||
| ) |
Load multimodal projector file.
| llm | A LLM instance pointer |
| mmproj_path | Path to the MMPROJ file (GGUF format) |
To use multimodal features, you must first load the text model with ailiaLLMOpenModelFile, then load the multimodal projector with this function.
| AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW | ( | struct AILIALLM * | llm, |
| const wchar_t * | mmproj_path | ||
| ) |
| AILIA_LLM_API int ailiaLLMSetMultimodalPrompt | ( | struct AILIALLM * | llm, |
| const AILIALLMMultimodalChatMessage * | message, | ||
| unsigned int | message_cnt | ||
| ) |
Set multimodal prompt.
| llm | A LLM instance pointer |
| message | Array of multimodal messages |
| message_cnt | Number of messages |
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.
| AILIA_LLM_API int ailiaLLMSetPrompt | ( | struct AILIALLM * | llm, |
| const AILIALLMChatMessage * | message, | ||
| unsigned int | message_cnt | ||
| ) |
Set the prompt.
| llm | A pointer to the LLM instance pointer |
| message | Array of messages |
| message_cnt | Number of messages |
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.
| AILIA_LLM_API int ailiaLLMSetSamplingParams | ( | struct AILIALLM * | llm, |
| unsigned int | top_k, | ||
| float | top_p, | ||
| float | temp, | ||
| unsigned int | dist | ||
| ) |
Set the sampling parameter.
| llm | A pointer to the LLM instance pointer |
| top_k | Sampling probability value's top number, default 40 |
| top_p | Sampling probability value range, default 0.9 (0.9 to 1.0) |
| temp | Temperature parameter, default 0.4 |
| dist | Seed, default 1234 |
Set LLM sampling parameters. Must be run before ailiaLLMSetPrompt.