ailia_llm  1.4.0.0
ailia_llm.h
Go to the documentation of this file.
1 
15 #ifndef INCLUDED_AILIA_LLM
16 #define INCLUDED_AILIA_LLM
17 
18 #include <wchar.h>
19 
20 #if defined(_WIN64) || defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) || defined(__APPLE__) || \
21  defined(__ANDROID__) || defined(ANDROID) || defined(__linux__) || defined(NN_NINTENDO_SDK)
22 #define AILIA_LLM_API
23 #else
24 #define AILIA_LLM_API __stdcall
25 #endif
26 
27 /****************************************************************
28  * ライブラリ状態定義
29  **/
30 
40 #define AILIA_LLM_STATUS_SUCCESS (0)
52 #define AILIA_LLM_STATUS_INVALID_ARGUMENT (-1)
64 #define AILIA_LLM_STATUS_ERROR_FILE_API (-2)
76 #define AILIA_LLM_STATUS_INVALID_VERSION (-3)
88 #define AILIA_LLM_STATUS_BROKEN (-4)
100 #define AILIA_LLM_STATUS_MEMORY_INSUFFICIENT (-5)
112 #define AILIA_LLM_STATUS_THREAD_ERROR (-6)
124 #define AILIA_LLM_STATUS_INVALID_STATE (-7)
136 #define AILIA_LLM_STATUS_CONTEXT_FULL (-8)
148 #define AILIA_LLM_STATUS_ERROR_BUFFER_API (-9)
162 #define AILIA_LLM_STATUS_UNIMPLEMENTED (-15)
174 #define AILIA_LLM_STATUS_OTHER_ERROR (-128)
175 
176 /****************************************************************
177  * チャットメッセージ
178  **/
179 
180 typedef struct _AILIALLMChatMessage {
184  const char *role;
188  const char *content;
190 
191 /****************************************************************
192  * マルチモーダル画像/音声データ
193  **/
194 
205 typedef struct _AILIALLMMediaData {
212  const char *media_type;
219  const char *file_path;
230  const unsigned char *data;
237  unsigned int data_size;
244  unsigned int width;
251  unsigned int height;
253 
264  const char *role;
268  const char *content;
276  unsigned int media_count;
278 
279 #ifdef __cplusplus
280 extern "C" {
281 #endif
282 
283 /****************************************************************
284  * LLMオブジェクトのインスタンス
285  **/
286 
287 struct AILIALLM;
288 
289 /****************************************************************
290  * LLM API
291  **/
292 
306 AILIA_LLM_API int ailiaLLMGetBackendCount(unsigned int* env_count);
307 
324 AILIA_LLM_API int ailiaLLMGetBackendName(const char** env, unsigned int env_idx);
325 
343 AILIA_LLM_API int ailiaLLMCreate(struct AILIALLM** llm);
344 
366 AILIA_LLM_API int ailiaLLMOpenModelFileA(struct AILIALLM* llm, const char *path, unsigned int n_ctx);
367 AILIA_LLM_API int ailiaLLMOpenModelFileW(struct AILIALLM* llm, const wchar_t *path, unsigned int n_ctx);
368 
384 AILIA_LLM_API int ailiaLLMGetContextSize(struct AILIALLM* llm, unsigned int *context_size);
385 
411 AILIA_LLM_API int ailiaLLMSetSamplingParams(struct AILIALLM* llm, unsigned int top_k, float top_p, float temp, unsigned int dist);
412 
438 AILIA_LLM_API int ailiaLLMSetPrompt(struct AILIALLM* llm, const AILIALLMChatMessage * message, unsigned int message_cnt);
439 
463 AILIA_LLM_API int ailiaLLMGenerate(struct AILIALLM* llm, unsigned int *done);
464 
480 AILIA_LLM_API int ailiaLLMGetDeltaTextSize(struct AILIALLM* llm, unsigned int *buf_size);
481 
503 AILIA_LLM_API int ailiaLLMGetDeltaText(struct AILIALLM* llm, char * text, unsigned int buf_size);
504 
522 AILIA_LLM_API int ailiaLLMGetTokenCount(struct AILIALLM* llm, unsigned int *cnt, const char* text);
523 
543 AILIA_LLM_API int ailiaLLMGetPromptTokenCount(struct AILIALLM* llm, unsigned int *cnt);
544 
564 AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount(struct AILIALLM* llm, unsigned int *cnt);
565 
566 /****************************************************************
567  * マルチモーダル LLM API
568  **/
569 
591 AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA(struct AILIALLM* llm, const char *mmproj_path);
592 AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW(struct AILIALLM* llm, const wchar_t *mmproj_path);
593 
615 AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities(struct AILIALLM* llm, unsigned int *vision_support, unsigned int *audio_support);
616 
646 AILIA_LLM_API int ailiaLLMSetMultimodalPrompt(struct AILIALLM* llm, const AILIALLMMultimodalChatMessage * message, unsigned int message_cnt);
647 
657 AILIA_LLM_API void ailiaLLMDestroy(struct AILIALLM* llm);
658 
659 #ifdef __cplusplus
660 }
661 #endif
662 
663 #endif // INCLUDED_AILIA_LLM
AILIA_LLM_API int ailiaLLMSetPrompt(struct AILIALLM *llm, const AILIALLMChatMessage *message, unsigned int message_cnt)
Set the prompt.
AILIA_LLM_API int ailiaLLMGetDeltaText(struct AILIALLM *llm, char *text, unsigned int buf_size)
Gets the decoded text.
#define AILIA_LLM_API
Definition: ailia_llm.h:24
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW(struct AILIALLM *llm, const wchar_t *mmproj_path)
struct _AILIALLMChatMessage AILIALLMChatMessage
AILIA_LLM_API int ailiaLLMGetDeltaTextSize(struct AILIALLM *llm, unsigned int *buf_size)
Gets the size of text. (Include null)
AILIA_LLM_API int ailiaLLMGenerate(struct AILIALLM *llm, unsigned int *done)
Perform generate.
AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities(struct AILIALLM *llm, unsigned int *vision_support, unsigned int *audio_support)
Check if multimodal features are supported.
AILIA_LLM_API int ailiaLLMOpenModelFileW(struct AILIALLM *llm, const wchar_t *path, unsigned int n_ctx)
AILIA_LLM_API int ailiaLLMSetMultimodalPrompt(struct AILIALLM *llm, const AILIALLMMultimodalChatMessage *message, unsigned int message_cnt)
Set multimodal prompt.
AILIA_LLM_API int ailiaLLMGetTokenCount(struct AILIALLM *llm, unsigned int *cnt, const char *text)
Gets the count of token.
AILIA_LLM_API int ailiaLLMGetBackendName(const char **env, unsigned int env_idx)
Gets the list of computational environments.
AILIA_LLM_API int ailiaLLMOpenModelFileA(struct AILIALLM *llm, const char *path, unsigned int n_ctx)
Open model file.
AILIA_LLM_API int ailiaLLMCreate(struct AILIALLM **llm)
Creates a LLM instance.
AILIA_LLM_API void ailiaLLMDestroy(struct AILIALLM *llm)
It destroys the LLM instance.
AILIA_LLM_API int ailiaLLMSetSamplingParams(struct AILIALLM *llm, unsigned int top_k, float top_p, float temp, unsigned int dist)
Set the sampling parameter.
struct _AILIALLMMediaData AILIALLMMediaData
Media data structure for multimodal processing. Audio is currently unsupported and reserved for futur...
struct _AILIALLMMultimodalChatMessage AILIALLMMultimodalChatMessage
Multimodal chat message with media attachments.
AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount(struct AILIALLM *llm, unsigned int *cnt)
Gets the count of prompt token.
AILIA_LLM_API int ailiaLLMGetContextSize(struct AILIALLM *llm, unsigned int *context_size)
Gets the size of context.
AILIA_LLM_API int ailiaLLMGetPromptTokenCount(struct AILIALLM *llm, unsigned int *cnt)
Gets the count of prompt token.
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA(struct AILIALLM *llm, const char *mmproj_path)
Load multimodal projector file.
AILIA_LLM_API int ailiaLLMGetBackendCount(unsigned int *env_count)
Gets the number of available computational environments (CPU, GPU).
Definition: ailia_llm.h:180
const char * content
Represent the content of the message.
Definition: ailia_llm.h:188
const char * role
Represent the role. (system, user, assistant)
Definition: ailia_llm.h:184
Media data structure for multimodal processing. Audio is currently unsupported and reserved for futur...
Definition: ailia_llm.h:205
unsigned int data_size
Size of the buffer (used with data parameter)
Definition: ailia_llm.h:237
const char * file_path
Path to the media file (UTF-8). Ignored if data is provided.
Definition: ailia_llm.h:219
const char * media_type
Media type (image, audio). "audio" keywords are reserved for future use, currently unsupported.
Definition: ailia_llm.h:212
unsigned int width
Width for images (pixels). Only specify for raw RGB data. Set to 0 for encoded buffer.
Definition: ailia_llm.h:244
unsigned int height
Height for images (pixels). Only specify for raw RGB data. Set to 0 for encoded buffer.
Definition: ailia_llm.h:251
const unsigned char * data
Optional: Image data from buffer (alternative to file_path). If width/height are 0,...
Definition: ailia_llm.h:230
Multimodal chat message with media attachments.
Definition: ailia_llm.h:260
const AILIALLMMediaData * media_data
Array of media data (images, audio) referenced by <media> markers.
Definition: ailia_llm.h:272
const char * role
Represent the role. (system, user, assistant)
Definition: ailia_llm.h:264
unsigned int media_count
Number of media items in media_data array.
Definition: ailia_llm.h:276
const char * content
Represent the content of the message. Use <media> placeholder for media.
Definition: ailia_llm.h:268