ailia_llm  1.5.1.0
ailia_llm.h
[詳解]
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)
165 #define AILIA_LLM_STATUS_PARSE_ERROR (-10)
179 #define AILIA_LLM_STATUS_UNIMPLEMENTED (-15)
191 #define AILIA_LLM_STATUS_OTHER_ERROR (-128)
192 
193 /****************************************************************
194  * チャットメッセージ
195  **/
196 
197 typedef struct _AILIALLMChatMessage {
202  const char *role;
207  const char *content;
209 
210 /****************************************************************
211  * マルチモーダル画像/音声データ
212  **/
213 
224 typedef struct _AILIALLMMediaData {
231  const char *media_type;
238  const char *file_path;
251  const unsigned char *data;
258  unsigned int data_size;
265  unsigned int width;
272  unsigned int height;
274 
286  const char *role;
290  const char *content;
298  unsigned int media_count;
300 
301 #ifdef __cplusplus
302 extern "C" {
303 #endif
304 
305 /****************************************************************
306  * LLMオブジェクトのインスタンス
307  **/
308 
309 struct AILIALLM;
310 
311 /****************************************************************
312  * LLM API
313  **/
314 
328 AILIA_LLM_API int ailiaLLMGetBackendCount(unsigned int* env_count);
329 
345 AILIA_LLM_API int ailiaLLMGetBackendName(const char** env, unsigned int env_idx);
346 
360 AILIA_LLM_API int ailiaLLMGetBackendDeviceName(const char** name, unsigned int env_idx);
361 
377 AILIA_LLM_API int ailiaLLMSetBackend(struct AILIALLM* llm, unsigned int backend_idx);
378 
396 AILIA_LLM_API int ailiaLLMSetNumThreads(struct AILIALLM* llm, unsigned int n_threads);
397 
419 AILIA_LLM_API int ailiaLLMCreate(struct AILIALLM** llm);
420 
448 AILIA_LLM_API int ailiaLLMOpenModelFileA(struct AILIALLM* llm, const char *path, unsigned int n_ctx);
449 AILIA_LLM_API int ailiaLLMOpenModelFileW(struct AILIALLM* llm, const wchar_t *path, unsigned int n_ctx);
450 
469 AILIA_LLM_API int ailiaLLMOpenMtpModelFileA(struct AILIALLM* llm, const char *path, unsigned int n_draft);
470 AILIA_LLM_API int ailiaLLMOpenMtpModelFileW(struct AILIALLM* llm, const wchar_t *path, unsigned int n_draft);
471 
472 
488 AILIA_LLM_API int ailiaLLMGetContextSize(struct AILIALLM* llm, unsigned int *context_size);
489 
515 AILIA_LLM_API int ailiaLLMSetSamplingParams(struct AILIALLM* llm, unsigned int top_k, float top_p, float temp, unsigned int dist);
516 
537 AILIA_LLM_API int ailiaLLMSetThinking(struct AILIALLM* llm, unsigned int enable);
538 
568 AILIA_LLM_API int ailiaLLMSetPrompt(struct AILIALLM* llm, const AILIALLMChatMessage * message, unsigned int message_cnt);
569 
593 AILIA_LLM_API int ailiaLLMGenerate(struct AILIALLM* llm, unsigned int *done);
594 
610 AILIA_LLM_API int ailiaLLMGetDeltaTextSize(struct AILIALLM* llm, unsigned int *buf_size);
611 
633 AILIA_LLM_API int ailiaLLMGetDeltaText(struct AILIALLM* llm, char * text, unsigned int buf_size);
634 
652 AILIA_LLM_API int ailiaLLMGetTokenCount(struct AILIALLM* llm, unsigned int *cnt, const char* text);
653 
673 AILIA_LLM_API int ailiaLLMGetPromptTokenCount(struct AILIALLM* llm, unsigned int *cnt);
674 
694 AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount(struct AILIALLM* llm, unsigned int *cnt);
695 
713 AILIA_LLM_API void ailiaLLMDestroy(struct AILIALLM* llm);
714 
715 /****************************************************************
716  * マルチモーダル LLM API
717  **/
718 
745 AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA(struct AILIALLM* llm, const char *mmproj_path);
746 AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW(struct AILIALLM* llm, const wchar_t *mmproj_path);
747 
769 AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities(struct AILIALLM* llm, unsigned int *vision_support, unsigned int *audio_support);
770 
811 AILIA_LLM_API int ailiaLLMSetMultimodalPrompt(struct AILIALLM* llm, const AILIALLMMultimodalChatMessage * message, unsigned int message_cnt);
812 
813 /****************************************************************
814  * TOOL USE API
815  **/
816 
835 AILIA_LLM_API int ailiaLLMSetTools(struct AILIALLM* llm, const char *tools_json);
836 
899 AILIA_LLM_API int ailiaLLMSetPromptJson(struct AILIALLM* llm, const char *messages_json);
900 
913 AILIA_LLM_API int ailiaLLMGetResponseJsonSize(struct AILIALLM* llm, unsigned int *buf_size);
914 
937 AILIA_LLM_API int ailiaLLMGetResponseJson(struct AILIALLM* llm, char *json, unsigned int buf_size);
938 
954 AILIA_LLM_API const char * ailiaLLMGetErrorDetail(struct AILIALLM * llm);
955 
956 /* QNN API */
957 
990 AILIA_LLM_API int ailiaLLMGetQNNModelName(const char** model_name);
991 
992 #ifdef __cplusplus
993 }
994 #endif
995 
996 #endif // INCLUDED_AILIA_LLM
AILIA_LLM_API int ailiaLLMSetPrompt(struct AILIALLM *llm, const AILIALLMChatMessage *message, unsigned int message_cnt)
プロンプトを設定します。
AILIA_LLM_API int ailiaLLMGetResponseJsonSize(struct AILIALLM *llm, unsigned int *buf_size)
SDK内部に蓄積した生成結果のassistant JSONサイズを取得します(NULL文字含む)。
AILIA_LLM_API int ailiaLLMSetBackend(struct AILIALLM *llm, unsigned int backend_idx)
モデルを開く前に、このインスタンスが使用するバックエンドを選択します。
AILIA_LLM_API int ailiaLLMGetQNNModelName(const char **model_name)
現在の端末に対応するQNNモデル名を取得します。
AILIA_LLM_API int ailiaLLMGetDeltaText(struct AILIALLM *llm, char *text, unsigned int buf_size)
テキストを取得します。
AILIA_LLM_API int ailiaLLMGetBackendDeviceName(const char **name, unsigned int env_idx)
指定した計算環境のデバイス名を取得します。
AILIA_LLM_API int ailiaLLMSetThinking(struct AILIALLM *llm, unsigned int enable)
Thinking(推論過程の出力)を有効または無効にします。
#define AILIA_LLM_API
Definition: ailia_llm.h:24
AILIA_LLM_API int ailiaLLMGetResponseJson(struct AILIALLM *llm, char *json, unsigned int buf_size)
SDK内部に蓄積した生成結果を構造化assistant JSONとして取得します。
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileW(struct AILIALLM *llm, const wchar_t *mmproj_path)
AILIA_LLM_API int ailiaLLMSetPromptJson(struct AILIALLM *llm, const char *messages_json)
構造化されたJSON会話履歴からプロンプトを設定します。
struct _AILIALLMChatMessage AILIALLMChatMessage
AILIA_LLM_API int ailiaLLMGetDeltaTextSize(struct AILIALLM *llm, unsigned int *buf_size)
テキストの長さを取得します。(NULL文字含む)
AILIA_LLM_API int ailiaLLMGenerate(struct AILIALLM *llm, unsigned int *done)
生成を行います。
AILIA_LLM_API int ailiaLLMGetMultimodalCapabilities(struct AILIALLM *llm, unsigned int *vision_support, unsigned int *audio_support)
マルチモーダル機能がサポートされているかを確認します。
AILIA_LLM_API int ailiaLLMOpenModelFileW(struct AILIALLM *llm, const wchar_t *path, unsigned int n_ctx)
AILIA_LLM_API int ailiaLLMSetTools(struct AILIALLM *llm, const char *tools_json)
OpenAI互換のツール定義JSON配列を設定します。NULL/空文字列/空配列で解除します。
AILIA_LLM_API int ailiaLLMSetMultimodalPrompt(struct AILIALLM *llm, const AILIALLMMultimodalChatMessage *message, unsigned int message_cnt)
マルチモーダルプロンプトを設定します。
AILIA_LLM_API int ailiaLLMGetTokenCount(struct AILIALLM *llm, unsigned int *cnt, const char *text)
トークンの数を取得します。
AILIA_LLM_API int ailiaLLMGetBackendName(const char **env, unsigned int env_idx)
計算環境の一覧を取得します
AILIA_LLM_API int ailiaLLMOpenModelFileA(struct AILIALLM *llm, const char *path, unsigned int n_ctx)
モデルファイルを読み込みます。
AILIA_LLM_API int ailiaLLMCreate(struct AILIALLM **llm)
LLMオブジェクトを作成します。
AILIA_LLM_API int ailiaLLMOpenMtpModelFileA(struct AILIALLM *llm, const char *path, unsigned int n_draft)
MTPドラフトモデルを開き、生成をドラフト・本体検証経路に切り替えます。
AILIA_LLM_API void ailiaLLMDestroy(struct AILIALLM *llm)
LLMオブジェクトを破棄します。
AILIA_LLM_API int ailiaLLMSetSamplingParams(struct AILIALLM *llm, unsigned int top_k, float top_p, float temp, unsigned int dist)
サンプリングのパラメータを設定します。
struct _AILIALLMMediaData AILIALLMMediaData
マルチモーダル用の画像・音声データ構造体。音声には音声対応プロジェクタが必要です。 画像はファイルパス、エンコード済みバッファ(JPG、PNG等)、またはRaw RGBデータから読み込み可能です。 エン...
AILIA_LLM_API int ailiaLLMOpenMtpModelFileW(struct AILIALLM *llm, const wchar_t *path, unsigned int n_draft)
struct _AILIALLMMultimodalChatMessage AILIALLMMultimodalChatMessage
マルチモーダル対応チャットメッセージ
AILIA_LLM_API int ailiaLLMGetGeneratedTokenCount(struct AILIALLM *llm, unsigned int *cnt)
生成したトークンの数を取得します。
AILIA_LLM_API int ailiaLLMGetContextSize(struct AILIALLM *llm, unsigned int *context_size)
コンテキストの長さを取得します。
AILIA_LLM_API int ailiaLLMGetPromptTokenCount(struct AILIALLM *llm, unsigned int *cnt)
プロンプトトークンの数を取得します。
AILIA_LLM_API int ailiaLLMOpenMultimodalProjectorFileA(struct AILIALLM *llm, const char *mmproj_path)
マルチモーダルプロジェクタファイルを読み込みます。
AILIA_LLM_API const char * ailiaLLMGetErrorDetail(struct AILIALLM *llm)
モデル読み込み・プロンプト設定・推論APIの直近のエラー詳細を返します。
AILIA_LLM_API int ailiaLLMGetBackendCount(unsigned int *env_count)
利用可能な計算環境(CPU, GPU, HTP (QNN))の数を取得します
AILIA_LLM_API int ailiaLLMSetNumThreads(struct AILIALLM *llm, unsigned int n_threads)
モデルを開く前にCPUスレッド数を設定します。
Definition: ailia_llm.h:197
const char * content
Represent the content of the message. For role "tool" the content is the tool result,...
Definition: ailia_llm.h:207
const char * role
Represent the role. (system, user, assistant, tool) "tool" holds a tool result for tool use,...
Definition: ailia_llm.h:202
マルチモーダル用の画像・音声データ構造体。音声には音声対応プロジェクタが必要です。 画像はファイルパス、エンコード済みバッファ(JPG、PNG等)、またはRaw RGBデータから読み込み可能です。 エン...
Definition: ailia_llm.h:224
unsigned int data_size
バッファのサイズ(dataパラメータと共に使用)
Definition: ailia_llm.h:258
const char * file_path
メディアファイルへのパス(UTF-8)。dataが指定されている場合は無視されます。
Definition: ailia_llm.h:238
const char * media_type
メディアタイプ(image, audio)。audioには音声対応mmprojが必要です。
Definition: ailia_llm.h:231
unsigned int width
画像の幅(ピクセル)。Raw RGBデータの場合のみ指定。エンコード済みバッファの場合は0を指定。
Definition: ailia_llm.h:265
unsigned int height
画像の高さ(ピクセル)。Raw RGBデータの場合のみ指定。エンコード済みバッファの場合は0を指定。
Definition: ailia_llm.h:272
const unsigned char * data
オプション:バッファからのメディアデータ(file_pathの代替)。 width/heightが0の場合はエンコード済みファイルバッファ(JPG、PNG等)として扱われます。 width/height...
Definition: ailia_llm.h:251
マルチモーダル対応チャットメッセージ
Definition: ailia_llm.h:281
const AILIALLMMediaData * media_data
Array of media data (images, audio) referenced by <media> markers
Definition: ailia_llm.h:294
const char * role
Represent the role. (system, user, assistant, tool) "tool" holds a tool result for tool use,...
Definition: ailia_llm.h:286
unsigned int media_count
Number of media items in media_data array
Definition: ailia_llm.h:298
const char * content
Represent the content of the message. Use <media> placeholder for media.
Definition: ailia_llm.h:290