ailia_llm  1.3.3.0
API Usage

Overview of ailia LLM API

Basic usage

This is an example of using ailia LLM.

#include "ailia_llm.h"
int main(int argc, char *argv[]){
struct AILIALLM* llm;
unsigned int n_ctx = 512;
ailiaLLMOpenModelFileA(llm, "../models/gemma-2-2b-it-Q4_K_M.gguf", n_ctx);
std::vector<AILIALLMChatMessage> messages;
message.role = "system";
message.content = "語尾に「くま」をつけて回答してください。";
messages.push_back(message);
message.role = "user";
message.content = "こんにちは。";
messages.push_back(message);
ailiaLLMSetPrompt(llm, &messages[0], messages.size());
std::string text = "";
while(true) {
unsigned int done = 0;
int status = ailiaLLMGenerate(llm, &done);
if (done == 1 || status != AILIA_LLM_STATUS_SUCCESS){
break;
}
unsigned int size = 0;
std::vector<char> delta(size);
ailiaLLMGetDeltaText(llm, &delta[0], delta.size());
text = text + std::string(&delta[0]);
}
return 0;
}
LLM inference library.
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.
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.
#define AILIA_LLM_STATUS_SUCCESS
Successful.
Definition: ailia_llm.h:38
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.
Definition: ailia_llm.h:166
const char * content
Represent the content of the message.
Definition: ailia_llm.h:174
const char * role
Represent the role. (system, user, assistant)
Definition: ailia_llm.h:170