|
ailia_llm
1.3.3.0
|
LLM inference library. More...
Go to the source code of this file.
Classes | |
| struct | _AILIALLMChatMessage |
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_UNIMPLEMENTED (-15) |
| Unimplemented error. More... | |
| #define | AILIA_LLM_STATUS_OTHER_ERROR (-128) |
| Unknown error. More... | |
Typedefs | |
| typedef struct _AILIALLMChatMessage | AILIALLMChatMessage |
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 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_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 |
| 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 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 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.
| 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.