@dr33m/react-native-litert-lm 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +22 -1
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLM.kt +133 -43
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/LiteRTLMRegistry.kt +42 -6
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMInitProvider.kt +4 -1
- package/cpp/include/README.md +12 -16
- package/cpp/include/litert_lm_engine.h +1359 -71
- package/ios/HybridLiteRTLM+Streaming.swift +9 -6
- package/ios/HybridLiteRTLM.swift +3 -1
- package/package.json +4 -4
- package/react-native-litert-lm.podspec +4 -0
|
@@ -32,128 +32,771 @@ extern "C" {
|
|
|
32
32
|
#if defined(_WIN32)
|
|
33
33
|
#define LITERT_LM_C_API_EXPORT __declspec(dllexport)
|
|
34
34
|
#else
|
|
35
|
-
|
|
35
|
+
// Ensure symbols are exported when building the shared library with
|
|
36
|
+
// -fvisibility=hidden.
|
|
37
|
+
#define LITERT_LM_C_API_EXPORT __attribute__((visibility("default")))
|
|
36
38
|
#endif
|
|
37
39
|
|
|
38
40
|
// Opaque pointer for the LiteRT LM Engine.
|
|
41
|
+
//
|
|
42
|
+
// Added in version 0.1.0.
|
|
39
43
|
typedef struct LiteRtLmEngine LiteRtLmEngine;
|
|
40
44
|
|
|
41
45
|
// Opaque pointer for the LiteRT LM Session.
|
|
46
|
+
//
|
|
47
|
+
// Added in version 0.1.0.
|
|
42
48
|
typedef struct LiteRtLmSession LiteRtLmSession;
|
|
43
49
|
|
|
44
50
|
// Opaque pointer for the LiteRT LM Responses.
|
|
51
|
+
//
|
|
52
|
+
// Added in version 0.1.0.
|
|
45
53
|
typedef struct LiteRtLmResponses LiteRtLmResponses;
|
|
46
54
|
|
|
47
55
|
// Opaque pointer for the LiteRT LM Engine Settings.
|
|
56
|
+
//
|
|
57
|
+
// Added in version 0.1.0.
|
|
48
58
|
typedef struct LiteRtLmEngineSettings LiteRtLmEngineSettings;
|
|
49
59
|
|
|
50
60
|
// Opaque pointer for the LiteRT LM Benchmark Info.
|
|
61
|
+
//
|
|
62
|
+
// Added in version 0.1.0.
|
|
51
63
|
typedef struct LiteRtLmBenchmarkInfo LiteRtLmBenchmarkInfo;
|
|
52
64
|
|
|
53
65
|
// Opaque pointer for the LiteRT LM Conversation.
|
|
66
|
+
//
|
|
67
|
+
// Added in version 0.1.0.
|
|
54
68
|
typedef struct LiteRtLmConversation LiteRtLmConversation;
|
|
55
69
|
|
|
70
|
+
// Opaque pointer for the LiteRT LM Conversation Optional Args.
|
|
71
|
+
//
|
|
72
|
+
// Added in version 0.1.0.
|
|
73
|
+
typedef struct LiteRtLmConversationOptionalArgs
|
|
74
|
+
LiteRtLmConversationOptionalArgs;
|
|
75
|
+
|
|
76
|
+
// Opaque pointer for the LiteRT LM Repetition Penalty Config.
|
|
77
|
+
//
|
|
78
|
+
// Added in version 0.1.0.
|
|
79
|
+
typedef struct LiteRtLmRepetitionPenaltyConfig LiteRtLmRepetitionPenaltyConfig;
|
|
80
|
+
|
|
81
|
+
// Opaque pointer for the LiteRT LM No Repeat Ngram Config.
|
|
82
|
+
//
|
|
83
|
+
// Added in version 0.1.0.
|
|
84
|
+
typedef struct LiteRtLmNoRepeatNgramConfig LiteRtLmNoRepeatNgramConfig;
|
|
85
|
+
|
|
86
|
+
// Opaque pointer for the LiteRT LM Suppress Tokens Config.
|
|
87
|
+
//
|
|
88
|
+
// Added in version 0.1.0.
|
|
89
|
+
typedef struct LiteRtLmSuppressTokensConfig LiteRtLmSuppressTokensConfig;
|
|
90
|
+
|
|
91
|
+
// Opaque pointer for the LiteRT LM Thinking Config.
|
|
92
|
+
//
|
|
93
|
+
// Added in version 0.1.0.
|
|
94
|
+
typedef struct LiteRtLmThinkingConfig LiteRtLmThinkingConfig;
|
|
95
|
+
|
|
56
96
|
// Opaque pointer for a JSON response.
|
|
97
|
+
//
|
|
98
|
+
// Added in version 0.1.0.
|
|
57
99
|
typedef struct LiteRtLmJsonResponse LiteRtLmJsonResponse;
|
|
58
100
|
|
|
101
|
+
// Opaque pointer for a detokenize result.
|
|
102
|
+
// Use `litert_lm_detokenize_result_delete` to free memory.
|
|
103
|
+
//
|
|
104
|
+
// Added in version 0.1.0.
|
|
105
|
+
typedef struct LiteRtLmDetokenizeResult LiteRtLmDetokenizeResult;
|
|
106
|
+
|
|
107
|
+
// Opaque pointer for a tokenize result.
|
|
108
|
+
// Use `litert_lm_tokenize_result_delete` to free memory.
|
|
109
|
+
//
|
|
110
|
+
// Added in version 0.1.0.
|
|
111
|
+
typedef struct LiteRtLmTokenizeResult LiteRtLmTokenizeResult;
|
|
112
|
+
|
|
113
|
+
// Represents the type of a TokenUnion.
|
|
114
|
+
//
|
|
115
|
+
// Added in version 0.1.0.
|
|
116
|
+
typedef enum {
|
|
117
|
+
kLiteRtLmTokenUnionTypeString = 0,
|
|
118
|
+
kLiteRtLmTokenUnionTypeIds = 1,
|
|
119
|
+
} LiteRtLmTokenUnionType;
|
|
120
|
+
|
|
121
|
+
// Opaque pointer for LiteRT LM Token Union.
|
|
122
|
+
// Represents a single start or stop token, which could be either a string or a
|
|
123
|
+
// sequence of token ids.
|
|
124
|
+
// Use `litert_lm_token_union_delete` to free memory.
|
|
125
|
+
//
|
|
126
|
+
// Added in version 0.1.0.
|
|
127
|
+
typedef struct LiteRtLmTokenUnion LiteRtLmTokenUnion;
|
|
128
|
+
|
|
129
|
+
// Opaque pointer for LiteRT LM Token Unions.
|
|
130
|
+
// Represents a collection of TokenUnion, typically used for model stop
|
|
131
|
+
// conditions.
|
|
132
|
+
// Use `litert_lm_token_unions_delete` to free memory.
|
|
133
|
+
//
|
|
134
|
+
// Added in version 0.1.0.
|
|
135
|
+
typedef struct LiteRtLmTokenUnions LiteRtLmTokenUnions;
|
|
136
|
+
|
|
137
|
+
// Opaque pointer for LiteRT LM Input Data.
|
|
138
|
+
// Use `litert_lm_input_data_delete` to free memory.
|
|
139
|
+
//
|
|
140
|
+
// Added in version 0.1.0.
|
|
141
|
+
typedef struct LiteRtLmInputData LiteRtLmInputData;
|
|
142
|
+
|
|
59
143
|
// Opaque pointer for LiteRT LM Session Config.
|
|
144
|
+
//
|
|
145
|
+
// Added in version 0.1.0.
|
|
60
146
|
typedef struct LiteRtLmSessionConfig LiteRtLmSessionConfig;
|
|
61
147
|
|
|
62
148
|
// Opaque pointer for LiteRT LM Conversation Config.
|
|
149
|
+
//
|
|
150
|
+
// Added in version 0.1.0.
|
|
63
151
|
typedef struct LiteRtLmConversationConfig LiteRtLmConversationConfig;
|
|
64
152
|
|
|
65
153
|
// Represents the type of sampler.
|
|
154
|
+
//
|
|
155
|
+
// Added in version 0.1.0.
|
|
66
156
|
typedef enum {
|
|
67
|
-
kTypeUnspecified = 0,
|
|
68
157
|
// Probabilistically pick among the top k tokens.
|
|
69
|
-
|
|
158
|
+
kLiteRtLmSamplerTypeTopK = 1,
|
|
70
159
|
// Probabilistically pick among the tokens such that the sum is greater
|
|
71
160
|
// than or equal to p tokens after first performing top-k sampling.
|
|
72
|
-
|
|
161
|
+
kLiteRtLmSamplerTypeTopP = 2,
|
|
73
162
|
// Pick the token with maximum logit (i.e., argmax).
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
163
|
+
kLiteRtLmSamplerTypeGreedy = 3,
|
|
164
|
+
} LiteRtLmSamplerType;
|
|
165
|
+
|
|
166
|
+
// Opaque pointer for LiteRT LM Sampler Parameters.
|
|
167
|
+
// Use `litert_lm_sampler_params_delete` to free memory.
|
|
168
|
+
//
|
|
169
|
+
// Added in version 0.1.0.
|
|
170
|
+
typedef struct LiteRtLmSamplerParams LiteRtLmSamplerParams;
|
|
171
|
+
|
|
172
|
+
// Creates LiteRT LM Sampler Parameters with a specific sampler type.
|
|
173
|
+
// The caller is responsible for destroying the parameters using
|
|
174
|
+
// `litert_lm_sampler_params_delete`.
|
|
175
|
+
//
|
|
176
|
+
// @param type The sampler type to use.
|
|
177
|
+
// @return A pointer to the created parameters, or NULL on failure.
|
|
178
|
+
//
|
|
179
|
+
// Added in version 0.1.0.
|
|
180
|
+
LITERT_LM_C_API_EXPORT
|
|
181
|
+
LiteRtLmSamplerParams* litert_lm_sampler_params_create(
|
|
182
|
+
LiteRtLmSamplerType type);
|
|
183
|
+
|
|
184
|
+
// Destroys LiteRT LM Sampler Parameters.
|
|
185
|
+
//
|
|
186
|
+
// @param params The parameters to destroy.
|
|
187
|
+
//
|
|
188
|
+
// Added in version 0.1.0.
|
|
189
|
+
LITERT_LM_C_API_EXPORT
|
|
190
|
+
void litert_lm_sampler_params_delete(LiteRtLmSamplerParams* params);
|
|
191
|
+
|
|
192
|
+
// Sets the top-k value.
|
|
193
|
+
//
|
|
194
|
+
// Added in version 0.1.0.
|
|
195
|
+
LITERT_LM_C_API_EXPORT
|
|
196
|
+
void litert_lm_sampler_params_set_top_k(LiteRtLmSamplerParams* params,
|
|
197
|
+
int32_t top_k);
|
|
198
|
+
|
|
199
|
+
// Sets the top-p value.
|
|
200
|
+
//
|
|
201
|
+
// Added in version 0.1.0.
|
|
202
|
+
LITERT_LM_C_API_EXPORT
|
|
203
|
+
void litert_lm_sampler_params_set_top_p(LiteRtLmSamplerParams* params,
|
|
204
|
+
float top_p);
|
|
205
|
+
|
|
206
|
+
// Sets the temperature.
|
|
207
|
+
//
|
|
208
|
+
// Added in version 0.1.0.
|
|
209
|
+
LITERT_LM_C_API_EXPORT
|
|
210
|
+
void litert_lm_sampler_params_set_temperature(LiteRtLmSamplerParams* params,
|
|
211
|
+
float temperature);
|
|
212
|
+
|
|
213
|
+
// Sets the seed.
|
|
214
|
+
//
|
|
215
|
+
// Added in version 0.1.0.
|
|
216
|
+
LITERT_LM_C_API_EXPORT
|
|
217
|
+
void litert_lm_sampler_params_set_seed(LiteRtLmSamplerParams* params,
|
|
218
|
+
int32_t seed);
|
|
219
|
+
|
|
220
|
+
// Represents the type of constraint for constrained decoding.
|
|
221
|
+
//
|
|
222
|
+
// Added in version 0.1.0.
|
|
223
|
+
typedef enum {
|
|
224
|
+
kLiteRtLmConstraintTypeNone = 0,
|
|
225
|
+
kLiteRtLmConstraintTypeRegex = 1,
|
|
226
|
+
kLiteRtLmConstraintTypeJsonSchema = 2,
|
|
227
|
+
} LiteRtLmConstraintType;
|
|
228
|
+
|
|
229
|
+
// Represents the type of constraint provider.
|
|
230
|
+
//
|
|
231
|
+
// Added in version 0.1.0.
|
|
232
|
+
typedef enum {
|
|
233
|
+
kLiteRtLmConstraintProviderTypeLlGuidance = 1,
|
|
234
|
+
} LiteRtLmConstraintProviderType;
|
|
85
235
|
|
|
86
236
|
// Creates a LiteRT LM Session Config.
|
|
87
237
|
// The caller is responsible for destroying the config using
|
|
88
238
|
// `litert_lm_session_config_delete`.
|
|
89
239
|
// @return A pointer to the created config, or NULL on failure.
|
|
240
|
+
//
|
|
241
|
+
// Added in version 0.1.0.
|
|
90
242
|
LITERT_LM_C_API_EXPORT
|
|
91
243
|
LiteRtLmSessionConfig* litert_lm_session_config_create();
|
|
92
244
|
|
|
93
245
|
// Sets the maximum number of output tokens per decode step for this session.
|
|
94
246
|
// @param config The config to modify.
|
|
95
247
|
// @param max_output_tokens The maximum number of output tokens.
|
|
248
|
+
//
|
|
249
|
+
// Added in version 0.1.0.
|
|
96
250
|
LITERT_LM_C_API_EXPORT
|
|
97
251
|
void litert_lm_session_config_set_max_output_tokens(
|
|
98
252
|
LiteRtLmSessionConfig* config, int max_output_tokens);
|
|
99
253
|
|
|
254
|
+
// Sets whether to apply prompt template for this session.
|
|
255
|
+
// @param config The config to modify.
|
|
256
|
+
// @param apply_prompt_template Whether to apply prompt template.
|
|
257
|
+
//
|
|
258
|
+
// Added in version 0.1.0.
|
|
259
|
+
LITERT_LM_C_API_EXPORT
|
|
260
|
+
void litert_lm_session_config_set_apply_prompt_template(
|
|
261
|
+
LiteRtLmSessionConfig* config, bool apply_prompt_template);
|
|
262
|
+
|
|
100
263
|
// Sets the sampler parameters for this session config.
|
|
101
264
|
// @param config The config to modify.
|
|
102
265
|
// @param sampler_params The sampler parameters to use.
|
|
266
|
+
//
|
|
267
|
+
// Added in version 0.1.0.
|
|
103
268
|
LITERT_LM_C_API_EXPORT
|
|
104
269
|
void litert_lm_session_config_set_sampler_params(
|
|
105
270
|
LiteRtLmSessionConfig* config, const LiteRtLmSamplerParams* sampler_params);
|
|
106
271
|
|
|
107
272
|
// Destroys a LiteRT LM Session Config.
|
|
108
273
|
// @param config The config to destroy.
|
|
274
|
+
//
|
|
275
|
+
// Added in version 0.1.0.
|
|
109
276
|
LITERT_LM_C_API_EXPORT
|
|
110
277
|
void litert_lm_session_config_delete(LiteRtLmSessionConfig* config);
|
|
111
278
|
|
|
279
|
+
// Sets the path to the LoRA weights file.
|
|
280
|
+
// @param config The config to modify.
|
|
281
|
+
// @param lora_path The path to the text LoRA weights file.
|
|
282
|
+
// @return 0 on success, non-zero on failure.
|
|
283
|
+
//
|
|
284
|
+
// Added in version 0.1.0.
|
|
285
|
+
LITERT_LM_C_API_EXPORT
|
|
286
|
+
int litert_lm_session_config_set_lora_path(LiteRtLmSessionConfig* config,
|
|
287
|
+
const char* lora_path);
|
|
288
|
+
|
|
289
|
+
// Sets the path to the Audio LoRA weights file.
|
|
290
|
+
// @param config The config to modify.
|
|
291
|
+
// @param audio_lora_path The path to the audio LoRA weights file.
|
|
292
|
+
// @return 0 on success, non-zero on failure.
|
|
293
|
+
//
|
|
294
|
+
// Added in version 0.1.0.
|
|
295
|
+
LITERT_LM_C_API_EXPORT
|
|
296
|
+
int litert_lm_session_config_set_audio_lora_path(LiteRtLmSessionConfig* config,
|
|
297
|
+
const char* audio_lora_path);
|
|
298
|
+
|
|
112
299
|
// Creates a LiteRT LM Conversation Config.
|
|
113
300
|
// The caller is responsible for destroying the config using
|
|
114
301
|
// `litert_lm_conversation_config_delete`.
|
|
115
|
-
// @
|
|
116
|
-
//
|
|
117
|
-
//
|
|
302
|
+
// @return A pointer to the created config, or NULL on failure.
|
|
303
|
+
//
|
|
304
|
+
// Added in version 0.1.0.
|
|
305
|
+
LITERT_LM_C_API_EXPORT
|
|
306
|
+
LiteRtLmConversationConfig* litert_lm_conversation_config_create();
|
|
307
|
+
|
|
308
|
+
// Sets the session config for this conversation config.
|
|
309
|
+
// @param config The config to modify.
|
|
310
|
+
// @param session_config The session config to use.
|
|
311
|
+
//
|
|
312
|
+
// Added in version 0.1.0.
|
|
313
|
+
LITERT_LM_C_API_EXPORT
|
|
314
|
+
void litert_lm_conversation_config_set_session_config(
|
|
315
|
+
LiteRtLmConversationConfig* config,
|
|
316
|
+
const LiteRtLmSessionConfig* session_config);
|
|
317
|
+
|
|
318
|
+
// Sets the system message for this conversation config.
|
|
319
|
+
// @param config The config to modify.
|
|
118
320
|
// @param system_message_json The system message in JSON format.
|
|
321
|
+
//
|
|
322
|
+
// Added in version 0.1.0.
|
|
323
|
+
LITERT_LM_C_API_EXPORT
|
|
324
|
+
void litert_lm_conversation_config_set_system_message(
|
|
325
|
+
LiteRtLmConversationConfig* config, const char* system_message_json);
|
|
326
|
+
|
|
327
|
+
// Sets the tools for this conversation config.
|
|
328
|
+
// @param config The config to modify.
|
|
119
329
|
// @param tools_json The tools description in JSON array format.
|
|
330
|
+
//
|
|
331
|
+
// Added in version 0.1.0.
|
|
332
|
+
LITERT_LM_C_API_EXPORT
|
|
333
|
+
void litert_lm_conversation_config_set_tools(LiteRtLmConversationConfig* config,
|
|
334
|
+
const char* tools_json);
|
|
335
|
+
|
|
336
|
+
// Sets the initial messages for this conversation config.
|
|
337
|
+
// @param config The config to modify.
|
|
338
|
+
// @param messages_json The initial messages in JSON array format.
|
|
339
|
+
//
|
|
340
|
+
// Added in version 0.1.0.
|
|
341
|
+
LITERT_LM_C_API_EXPORT
|
|
342
|
+
void litert_lm_conversation_config_set_messages(
|
|
343
|
+
LiteRtLmConversationConfig* config, const char* messages_json);
|
|
344
|
+
|
|
345
|
+
// Sets the extra context for the conversation preface.
|
|
346
|
+
// @param config The config to modify.
|
|
347
|
+
// @param extra_context_json A JSON string representing the extra context
|
|
348
|
+
// object.
|
|
349
|
+
//
|
|
350
|
+
// Added in version 0.1.0.
|
|
351
|
+
LITERT_LM_C_API_EXPORT
|
|
352
|
+
void litert_lm_conversation_config_set_extra_context(
|
|
353
|
+
LiteRtLmConversationConfig* config, const char* extra_context_json);
|
|
354
|
+
|
|
355
|
+
// Sets the prompt template for this conversation config.
|
|
356
|
+
// @param config The config to modify.
|
|
357
|
+
// @param prompt_template The prompt template string (e.g. Jinja template). If
|
|
358
|
+
// not set, use the default provided by the model or the engine.
|
|
359
|
+
//
|
|
360
|
+
// Added in version 0.1.0.
|
|
361
|
+
LITERT_LM_C_API_EXPORT
|
|
362
|
+
void litert_lm_conversation_config_set_prompt_template(
|
|
363
|
+
LiteRtLmConversationConfig* config, const char* prompt_template);
|
|
364
|
+
|
|
365
|
+
// Sets whether to enable constrained decoding for this conversation config.
|
|
366
|
+
// @param config The config to modify.
|
|
120
367
|
// @param enable_constrained_decoding Whether to enable constrained decoding.
|
|
368
|
+
//
|
|
369
|
+
// Added in version 0.1.0.
|
|
370
|
+
LITERT_LM_C_API_EXPORT
|
|
371
|
+
void litert_lm_conversation_config_set_enable_constrained_decoding(
|
|
372
|
+
LiteRtLmConversationConfig* config, bool enable_constrained_decoding);
|
|
373
|
+
|
|
374
|
+
// Sets the constraint provider type for this conversation config.
|
|
375
|
+
// @param config The config to modify.
|
|
376
|
+
// @param provider_type The constraint provider type to use, or NULL to unset.
|
|
377
|
+
//
|
|
378
|
+
// Added in version 0.1.0.
|
|
379
|
+
LITERT_LM_C_API_EXPORT
|
|
380
|
+
void litert_lm_conversation_config_set_constraint_provider(
|
|
381
|
+
LiteRtLmConversationConfig* config,
|
|
382
|
+
const LiteRtLmConstraintProviderType* provider_type);
|
|
383
|
+
|
|
384
|
+
// Sets whether to filter channel content from the KV cache.
|
|
385
|
+
// @param config The config to modify.
|
|
386
|
+
// @param filter_channel_content_from_kv_cache Whether to filter channel
|
|
387
|
+
// content.
|
|
388
|
+
//
|
|
389
|
+
// Added in version 0.1.0.
|
|
390
|
+
LITERT_LM_C_API_EXPORT
|
|
391
|
+
void litert_lm_conversation_config_set_filter_channel_content_from_kv_cache(
|
|
392
|
+
LiteRtLmConversationConfig* config,
|
|
393
|
+
bool filter_channel_content_from_kv_cache);
|
|
394
|
+
|
|
395
|
+
// Sets whether to stream tool call tokens.
|
|
396
|
+
// @param config The config to modify.
|
|
397
|
+
// @param stream_tool_calls Whether to stream tool call tokens.
|
|
398
|
+
// @param channel_name The channel name to use for tool call tokens.
|
|
399
|
+
//
|
|
400
|
+
// Added in version 0.1.0.
|
|
401
|
+
LITERT_LM_C_API_EXPORT
|
|
402
|
+
void litert_lm_conversation_config_set_stream_tool_calls(
|
|
403
|
+
LiteRtLmConversationConfig* config, bool stream_tool_calls,
|
|
404
|
+
const char* channel_name);
|
|
405
|
+
|
|
406
|
+
// Creates a default LiteRT LM Thinking Config (enabled with infinite budget
|
|
407
|
+
// -1). The caller is responsible for destroying the config using
|
|
408
|
+
// `litert_lm_thinking_config_delete`.
|
|
121
409
|
// @return A pointer to the created config, or NULL on failure.
|
|
410
|
+
//
|
|
411
|
+
// Added in version 0.1.0.
|
|
412
|
+
LITERT_LM_C_API_EXPORT
|
|
413
|
+
LiteRtLmThinkingConfig* litert_lm_thinking_config_create();
|
|
414
|
+
|
|
415
|
+
// Destroys a LiteRT LM Thinking Config.
|
|
416
|
+
// @param config The config to destroy.
|
|
417
|
+
//
|
|
418
|
+
// Added in version 0.1.0.
|
|
419
|
+
LITERT_LM_C_API_EXPORT
|
|
420
|
+
void litert_lm_thinking_config_delete(LiteRtLmThinkingConfig* config);
|
|
421
|
+
|
|
422
|
+
// Sets whether thinking/reasoning generation is enabled.
|
|
423
|
+
// @param config The config to modify.
|
|
424
|
+
// @param enable_thinking Whether thinking is enabled.
|
|
425
|
+
//
|
|
426
|
+
// Added in version 0.1.0.
|
|
427
|
+
LITERT_LM_C_API_EXPORT
|
|
428
|
+
void litert_lm_thinking_config_set_enable_thinking(
|
|
429
|
+
LiteRtLmThinkingConfig* config, bool enable_thinking);
|
|
430
|
+
|
|
431
|
+
// Sets the thinking token budget.
|
|
432
|
+
// @param config The config to modify.
|
|
433
|
+
// @param thinking_token_budget Budget for token-by-token reasoning generation
|
|
434
|
+
// (-1 for infinite).
|
|
435
|
+
//
|
|
436
|
+
// Added in version 0.1.0.
|
|
437
|
+
LITERT_LM_C_API_EXPORT
|
|
438
|
+
void litert_lm_thinking_config_set_thinking_token_budget(
|
|
439
|
+
LiteRtLmThinkingConfig* config, int thinking_token_budget);
|
|
440
|
+
|
|
441
|
+
// Sets the thinking config for this conversation config.
|
|
442
|
+
// @param config The config to modify.
|
|
443
|
+
// @param thinking_config The thinking config to set. If NULL, clears any
|
|
444
|
+
// previously set thinking config.
|
|
445
|
+
//
|
|
446
|
+
// Added in version 0.1.0.
|
|
122
447
|
LITERT_LM_C_API_EXPORT
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const char* messages_json, bool enable_constrained_decoding);
|
|
448
|
+
void litert_lm_conversation_config_set_thinking_config(
|
|
449
|
+
LiteRtLmConversationConfig* config,
|
|
450
|
+
const LiteRtLmThinkingConfig* thinking_config);
|
|
127
451
|
|
|
128
452
|
// Destroys a LiteRT LM Conversation Config.
|
|
129
453
|
// @param config The config to destroy.
|
|
454
|
+
//
|
|
455
|
+
// Added in version 0.1.0.
|
|
130
456
|
LITERT_LM_C_API_EXPORT
|
|
131
457
|
void litert_lm_conversation_config_delete(LiteRtLmConversationConfig* config);
|
|
132
458
|
|
|
459
|
+
// Creates a LiteRT LM Repetition Penalty Config with default values
|
|
460
|
+
// (`repetition_penalty` = 1.0f, `presence_penalty` = 0.0f,
|
|
461
|
+
// `frequency_penalty` = 0.0f, `window_size` = 0, which means all history with
|
|
462
|
+
// no penalties active).
|
|
463
|
+
//
|
|
464
|
+
// When multiple penalties are configured and active, the order of application
|
|
465
|
+
// to output logits during decoding is:
|
|
466
|
+
// 1. Multiplicative penalty (`repetition_penalty`)
|
|
467
|
+
// 2. Subtractive penalties (`presence_penalty` and `frequency_penalty`)
|
|
468
|
+
//
|
|
469
|
+
// The caller is responsible for destroying the config using
|
|
470
|
+
// `litert_lm_repetition_penalty_config_delete`.
|
|
471
|
+
// @return A pointer to the created config, or NULL on failure.
|
|
472
|
+
//
|
|
473
|
+
// Added in version 0.1.0.
|
|
474
|
+
LITERT_LM_C_API_EXPORT
|
|
475
|
+
LiteRtLmRepetitionPenaltyConfig* litert_lm_repetition_penalty_config_create();
|
|
476
|
+
|
|
477
|
+
// Destroys a LiteRT LM Repetition Penalty Config.
|
|
478
|
+
// @param config The config to destroy.
|
|
479
|
+
//
|
|
480
|
+
// Added in version 0.1.0.
|
|
481
|
+
LITERT_LM_C_API_EXPORT
|
|
482
|
+
void litert_lm_repetition_penalty_config_delete(
|
|
483
|
+
LiteRtLmRepetitionPenaltyConfig* config);
|
|
484
|
+
|
|
485
|
+
// Sets the multiplicative repetition penalty for the repetition penalty config.
|
|
486
|
+
// @param config The config to modify.
|
|
487
|
+
// @param repetition_penalty A multiplicative penalty applied to a token's logit
|
|
488
|
+
// if that token has appeared at least once inside the generated window history
|
|
489
|
+
// (e.g., 1.0 = no penalty, 1.2 = moderate penalty). Positive logits are divided
|
|
490
|
+
// by this parameter, and negative logits are multiplied (HuggingFace style).
|
|
491
|
+
// The parameter must be >= 1.0f; values less than 1.0f are automatically
|
|
492
|
+
// clamped to 1.0f during execution.
|
|
493
|
+
//
|
|
494
|
+
// Added in version 0.1.0.
|
|
495
|
+
LITERT_LM_C_API_EXPORT
|
|
496
|
+
void litert_lm_repetition_penalty_config_set_repetition_penalty(
|
|
497
|
+
LiteRtLmRepetitionPenaltyConfig* config, float repetition_penalty);
|
|
498
|
+
|
|
499
|
+
// Sets the subtractive presence penalty for the repetition penalty config.
|
|
500
|
+
// @param config The config to modify.
|
|
501
|
+
// @param presence_penalty A scalar subtracted from a token's logit if that
|
|
502
|
+
// token has appeared at least once inside the generated window history.
|
|
503
|
+
// Positive values discourage repetition, while negative values reward repeating
|
|
504
|
+
// tokens (OpenAI style). Defaults to 0.0f.
|
|
505
|
+
//
|
|
506
|
+
// Added in version 0.1.0.
|
|
507
|
+
LITERT_LM_C_API_EXPORT
|
|
508
|
+
void litert_lm_repetition_penalty_config_set_presence_penalty(
|
|
509
|
+
LiteRtLmRepetitionPenaltyConfig* config, float presence_penalty);
|
|
510
|
+
|
|
511
|
+
// Sets the subtractive frequency penalty for the repetition penalty config.
|
|
512
|
+
// @param config The config to modify.
|
|
513
|
+
// @param frequency_penalty A scalar subtracted from a token's logit, scaled
|
|
514
|
+
// linearly by the number of times that token has previously appeared inside the
|
|
515
|
+
// generated window history. Positive values discourage repetition, while
|
|
516
|
+
// negative values reward repeating tokens (OpenAI style). Defaults to 0.0f.
|
|
517
|
+
//
|
|
518
|
+
// Added in version 0.1.0.
|
|
519
|
+
LITERT_LM_C_API_EXPORT
|
|
520
|
+
void litert_lm_repetition_penalty_config_set_frequency_penalty(
|
|
521
|
+
LiteRtLmRepetitionPenaltyConfig* config, float frequency_penalty);
|
|
522
|
+
|
|
523
|
+
// Sets the window size for the repetition penalty config.
|
|
524
|
+
// @param config The config to modify.
|
|
525
|
+
// @param window_size The maximum number of recent tokens in generation history
|
|
526
|
+
// to consider when computing penalization. Tokens generated prior to this
|
|
527
|
+
// window are forgotten. A value of 0 means tracking all infinite generation
|
|
528
|
+
// history. Must be >= 0; negative values are clamped to 0 during execution.
|
|
529
|
+
//
|
|
530
|
+
// Added in version 0.1.0.
|
|
531
|
+
LITERT_LM_C_API_EXPORT
|
|
532
|
+
void litert_lm_repetition_penalty_config_set_window_size(
|
|
533
|
+
LiteRtLmRepetitionPenaltyConfig* config, int window_size);
|
|
534
|
+
|
|
535
|
+
// Creates a LiteRT LM No Repeat Ngram Config with default values
|
|
536
|
+
// (`no_repeat_ngram_size` = 0, `window_size` = 0, which means no repeat ngram
|
|
537
|
+
// banning is disabled).
|
|
538
|
+
//
|
|
539
|
+
// When `no_repeat_ngram_size` is set greater than 0, any sequence of tokens (an
|
|
540
|
+
// ngram of that exact length) generated during decoding or present inside the
|
|
541
|
+
// window history can only occur at most once. If generating a candidate token
|
|
542
|
+
// would complete a repeating ngram, that candidate token's logit is set to
|
|
543
|
+
// -inf.
|
|
544
|
+
//
|
|
545
|
+
// The caller is responsible for destroying the config using
|
|
546
|
+
// `litert_lm_no_repeat_ngram_config_delete`.
|
|
547
|
+
// @return A pointer to the created config, or NULL on failure.
|
|
548
|
+
//
|
|
549
|
+
// Added in version 0.1.0.
|
|
550
|
+
LITERT_LM_C_API_EXPORT
|
|
551
|
+
LiteRtLmNoRepeatNgramConfig* litert_lm_no_repeat_ngram_config_create();
|
|
552
|
+
|
|
553
|
+
// Destroys a LiteRT LM No Repeat Ngram Config.
|
|
554
|
+
// @param config The config to destroy.
|
|
555
|
+
//
|
|
556
|
+
// Added in version 0.1.0.
|
|
557
|
+
LITERT_LM_C_API_EXPORT
|
|
558
|
+
void litert_lm_no_repeat_ngram_config_delete(
|
|
559
|
+
LiteRtLmNoRepeatNgramConfig* config);
|
|
560
|
+
|
|
561
|
+
// Sets the no repeat ngram size for the no repeat ngram config.
|
|
562
|
+
// @param config The config to modify.
|
|
563
|
+
// @param no_repeat_ngram_size The size of ngrams (consecutive token sequences)
|
|
564
|
+
// that are banned from repeating within the generation history window. If set
|
|
565
|
+
// > 0, when generating the next token would complete an already observed
|
|
566
|
+
// `no_repeat_ngram_size` sequence, the logit of the candidate token is set to
|
|
567
|
+
// -inf. If set <= 0, no repeat ngram banning is disabled. Negative values are
|
|
568
|
+
// automatically clamped to 0 during execution.
|
|
569
|
+
//
|
|
570
|
+
// Added in version 0.1.0.
|
|
571
|
+
LITERT_LM_C_API_EXPORT
|
|
572
|
+
void litert_lm_no_repeat_ngram_config_set_no_repeat_ngram_size(
|
|
573
|
+
LiteRtLmNoRepeatNgramConfig* config, int no_repeat_ngram_size);
|
|
574
|
+
|
|
575
|
+
// Sets the window size for the no repeat ngram config.
|
|
576
|
+
// @param config The config to modify.
|
|
577
|
+
// @param window_size The maximum number of recent tokens in generation history
|
|
578
|
+
// to consider when checking for repeating ngrams. Tokens generated prior to
|
|
579
|
+
// this window are forgotten. A value of 0 means tracking all infinite
|
|
580
|
+
// generation history. Must be >= 0; negative values are clamped to 0. If
|
|
581
|
+
// `window_size` is greater than 0 but less than `no_repeat_ngram_size`, it is
|
|
582
|
+
// automatically clamped to `no_repeat_ngram_size` so that the ngrams can fit
|
|
583
|
+
// and be tracked.
|
|
584
|
+
//
|
|
585
|
+
// Added in version 0.1.0.
|
|
586
|
+
LITERT_LM_C_API_EXPORT
|
|
587
|
+
void litert_lm_no_repeat_ngram_config_set_window_size(
|
|
588
|
+
LiteRtLmNoRepeatNgramConfig* config, int window_size);
|
|
589
|
+
|
|
590
|
+
// Creates a LiteRT LM Suppress Tokens Config with default values (an empty set
|
|
591
|
+
// of suppressed tokens, which means token suppression is disabled).
|
|
592
|
+
//
|
|
593
|
+
// When `suppress_tokens` is configured with one or more token IDs, the logits
|
|
594
|
+
// corresponding to those exact token IDs will be set directly to -inf during
|
|
595
|
+
// generation. This guarantees that those tokens can never be sampled by the
|
|
596
|
+
// model.
|
|
597
|
+
//
|
|
598
|
+
// The caller is responsible for destroying the config using
|
|
599
|
+
// `litert_lm_suppress_tokens_config_delete`.
|
|
600
|
+
// @return A pointer to the created config, or NULL on failure.
|
|
601
|
+
//
|
|
602
|
+
// Added in version 0.1.0.
|
|
603
|
+
LITERT_LM_C_API_EXPORT
|
|
604
|
+
LiteRtLmSuppressTokensConfig* litert_lm_suppress_tokens_config_create();
|
|
605
|
+
|
|
606
|
+
// Destroys a LiteRT LM Suppress Tokens Config.
|
|
607
|
+
// @param config The config to destroy.
|
|
608
|
+
//
|
|
609
|
+
// Added in version 0.1.0.
|
|
610
|
+
LITERT_LM_C_API_EXPORT
|
|
611
|
+
void litert_lm_suppress_tokens_config_delete(
|
|
612
|
+
LiteRtLmSuppressTokensConfig* config);
|
|
613
|
+
|
|
614
|
+
// Sets the list of token IDs to suppress for the suppress tokens config.
|
|
615
|
+
// @param config The config to modify.
|
|
616
|
+
// @param suppress_tokens An array of integer token IDs that should be banned
|
|
617
|
+
// from generation. During every decode step, each listed token ID's candidate
|
|
618
|
+
// logit will be forced to -inf. If `suppress_tokens` is NULL or `num_tokens` is
|
|
619
|
+
// 0, any previously set suppressed tokens are cleared and token suppression is
|
|
620
|
+
// disabled.
|
|
621
|
+
// @param num_tokens The number of token IDs in the `suppress_tokens` array.
|
|
622
|
+
//
|
|
623
|
+
// Added in version 0.1.0.
|
|
624
|
+
LITERT_LM_C_API_EXPORT
|
|
625
|
+
void litert_lm_suppress_tokens_config_set_suppress_tokens(
|
|
626
|
+
LiteRtLmSuppressTokensConfig* config, const int* suppress_tokens,
|
|
627
|
+
size_t num_tokens);
|
|
628
|
+
|
|
629
|
+
// Creates a LiteRT LM Conversation Optional Args. The caller is responsible
|
|
630
|
+
// for destroying the optional args using
|
|
631
|
+
// `litert_lm_conversation_optional_args_delete`.
|
|
632
|
+
// @return A pointer to the created optional args, or NULL on failure.
|
|
633
|
+
//
|
|
634
|
+
// Added in version 0.1.0.
|
|
635
|
+
LITERT_LM_C_API_EXPORT
|
|
636
|
+
LiteRtLmConversationOptionalArgs* litert_lm_conversation_optional_args_create();
|
|
637
|
+
|
|
638
|
+
// Destroys a LiteRT LM Conversation Optional Args.
|
|
639
|
+
// @param optional_args The optional args to destroy.
|
|
640
|
+
//
|
|
641
|
+
// Added in version 0.1.0.
|
|
642
|
+
LITERT_LM_C_API_EXPORT
|
|
643
|
+
void litert_lm_conversation_optional_args_delete(
|
|
644
|
+
LiteRtLmConversationOptionalArgs* optional_args);
|
|
645
|
+
|
|
646
|
+
// Sets the repetition penalty configuration for the per-turn conversation
|
|
647
|
+
// optional arguments (`OptionalArgs`).
|
|
648
|
+
//
|
|
649
|
+
// The configured penalties (`repetition_penalty`, `presence_penalty`,
|
|
650
|
+
// `frequency_penalty`, `window_size`) apply exclusively to the output sequence
|
|
651
|
+
// generated during the current `send_message` or `send_message_async` call.
|
|
652
|
+
//
|
|
653
|
+
// @param optional_args The optional arguments structure (`OptionalArgs`) to
|
|
654
|
+
// modify.
|
|
655
|
+
// @param repetition_penalty_config The repetition penalty configuration struct
|
|
656
|
+
// (`LiteRtLmRepetitionPenaltyConfig`) created via
|
|
657
|
+
// `litert_lm_repetition_penalty_config_create`. The contents are deep-copied
|
|
658
|
+
// when set. If NULL, clears any previously set repetition penalty config so no
|
|
659
|
+
// penalties apply.
|
|
660
|
+
//
|
|
661
|
+
// Added in version 0.1.0.
|
|
662
|
+
LITERT_LM_C_API_EXPORT
|
|
663
|
+
void litert_lm_conversation_optional_args_set_repetition_penalty_config(
|
|
664
|
+
LiteRtLmConversationOptionalArgs* optional_args,
|
|
665
|
+
const LiteRtLmRepetitionPenaltyConfig* repetition_penalty_config);
|
|
666
|
+
|
|
667
|
+
// Sets the no repeat ngram configuration for the per-turn conversation
|
|
668
|
+
// optional arguments (`OptionalArgs`).
|
|
669
|
+
//
|
|
670
|
+
// The configured parameters (`no_repeat_ngram_size`, `window_size`) apply
|
|
671
|
+
// exclusively to the output sequence generated during the current
|
|
672
|
+
// `send_message` or `send_message_async` call.
|
|
673
|
+
//
|
|
674
|
+
// @param optional_args The optional arguments structure (`OptionalArgs`) to
|
|
675
|
+
// modify.
|
|
676
|
+
// @param no_repeat_ngram_config The no repeat ngram configuration struct
|
|
677
|
+
// (`LiteRtLmNoRepeatNgramConfig`) created via
|
|
678
|
+
// `litert_lm_no_repeat_ngram_config_create`. The contents are deep-copied when
|
|
679
|
+
// set. If NULL, clears any previously set no repeat ngram config so no
|
|
680
|
+
// repeat ngram banning applies.
|
|
681
|
+
//
|
|
682
|
+
// Added in version 0.1.0.
|
|
683
|
+
LITERT_LM_C_API_EXPORT
|
|
684
|
+
void litert_lm_conversation_optional_args_set_no_repeat_ngram_config(
|
|
685
|
+
LiteRtLmConversationOptionalArgs* optional_args,
|
|
686
|
+
const LiteRtLmNoRepeatNgramConfig* no_repeat_ngram_config);
|
|
687
|
+
|
|
688
|
+
// Sets the suppress tokens configuration for the per-turn conversation
|
|
689
|
+
// optional arguments (`OptionalArgs`).
|
|
690
|
+
//
|
|
691
|
+
// The configured list of suppressed tokens applies exclusively to the output
|
|
692
|
+
// sequence generated during the current `send_message` or
|
|
693
|
+
// `send_message_async` call.
|
|
694
|
+
//
|
|
695
|
+
// @param optional_args The optional arguments structure (`OptionalArgs`) to
|
|
696
|
+
// modify.
|
|
697
|
+
// @param suppress_tokens_config The suppress tokens configuration struct
|
|
698
|
+
// (`LiteRtLmSuppressTokensConfig`) created via
|
|
699
|
+
// `litert_lm_suppress_tokens_config_create`. The contents are deep-copied when
|
|
700
|
+
// set. If NULL or if the inner token set is disabled/empty, clears any
|
|
701
|
+
// previously set suppress tokens config so no token suppression applies.
|
|
702
|
+
//
|
|
703
|
+
// Added in version 0.1.0.
|
|
704
|
+
LITERT_LM_C_API_EXPORT
|
|
705
|
+
void litert_lm_conversation_optional_args_set_suppress_tokens_config(
|
|
706
|
+
LiteRtLmConversationOptionalArgs* optional_args,
|
|
707
|
+
const LiteRtLmSuppressTokensConfig* suppress_tokens_config);
|
|
708
|
+
|
|
709
|
+
// Sets the visual token budget for the conversation optional args.
|
|
710
|
+
// @param optional_args The optional args to modify.
|
|
711
|
+
// @param visual_token_budget The visual token budget.
|
|
712
|
+
//
|
|
713
|
+
// Added in version 0.1.0.
|
|
714
|
+
LITERT_LM_C_API_EXPORT
|
|
715
|
+
void litert_lm_conversation_optional_args_set_visual_token_budget(
|
|
716
|
+
LiteRtLmConversationOptionalArgs* optional_args, int visual_token_budget);
|
|
717
|
+
|
|
718
|
+
// Sets the maximum number of output tokens for the conversation optional args.
|
|
719
|
+
// @param optional_args The optional args to modify.
|
|
720
|
+
// @param max_output_tokens The maximum number of output tokens.
|
|
721
|
+
//
|
|
722
|
+
// Added in version 0.1.0.
|
|
723
|
+
LITERT_LM_C_API_EXPORT
|
|
724
|
+
void litert_lm_conversation_optional_args_set_max_output_tokens(
|
|
725
|
+
LiteRtLmConversationOptionalArgs* optional_args, int max_output_tokens);
|
|
726
|
+
|
|
727
|
+
// Sets the thinking config for the conversation optional args.
|
|
728
|
+
// @param optional_args The optional args to modify.
|
|
729
|
+
// @param thinking_config The thinking config to set. If NULL, clears any
|
|
730
|
+
// previously set thinking config.
|
|
731
|
+
//
|
|
732
|
+
// Added in version 0.1.0.
|
|
733
|
+
LITERT_LM_C_API_EXPORT
|
|
734
|
+
void litert_lm_conversation_optional_args_set_thinking_config(
|
|
735
|
+
LiteRtLmConversationOptionalArgs* optional_args,
|
|
736
|
+
const LiteRtLmThinkingConfig* thinking_config);
|
|
737
|
+
|
|
738
|
+
// Sets the constraint for the conversation optional args.
|
|
739
|
+
// @param optional_args The optional args to modify.
|
|
740
|
+
// @param constraint_type The type of constraint.
|
|
741
|
+
// @param constraint_string The constraint pattern/schema/grammar string.
|
|
742
|
+
//
|
|
743
|
+
// Added in version 0.1.0.
|
|
744
|
+
LITERT_LM_C_API_EXPORT
|
|
745
|
+
void litert_lm_conversation_optional_args_set_constraint(
|
|
746
|
+
LiteRtLmConversationOptionalArgs* optional_args,
|
|
747
|
+
LiteRtLmConstraintType constraint_type, const char* constraint_string);
|
|
748
|
+
// Represents the log severity / level.
|
|
749
|
+
//
|
|
750
|
+
// Added in version 0.1.0.
|
|
751
|
+
typedef enum {
|
|
752
|
+
kLiteRtLmLogSeverityVerbose = 0,
|
|
753
|
+
kLiteRtLmLogSeverityDebug = 1,
|
|
754
|
+
kLiteRtLmLogSeverityInfo = 2,
|
|
755
|
+
kLiteRtLmLogSeverityWarning = 3,
|
|
756
|
+
kLiteRtLmLogSeverityError = 4,
|
|
757
|
+
kLiteRtLmLogSeverityFatal = 5,
|
|
758
|
+
kLiteRtLmLogSeveritySilent = 1000,
|
|
759
|
+
} LiteRtLmLogSeverity;
|
|
133
760
|
// Sets the minimum log level for the LiteRT LM library.
|
|
134
|
-
//
|
|
761
|
+
//
|
|
762
|
+
// Added in version 0.1.0.
|
|
135
763
|
LITERT_LM_C_API_EXPORT
|
|
136
|
-
void litert_lm_set_min_log_level(
|
|
764
|
+
void litert_lm_set_min_log_level(LiteRtLmLogSeverity level);
|
|
137
765
|
|
|
138
766
|
// Represents the type of input data.
|
|
767
|
+
//
|
|
768
|
+
// Added in version 0.1.0.
|
|
139
769
|
typedef enum {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
770
|
+
kLiteRtLmInputDataTypeText,
|
|
771
|
+
kLiteRtLmInputDataTypeImage,
|
|
772
|
+
kLiteRtLmInputDataTypeImageEnd,
|
|
773
|
+
kLiteRtLmInputDataTypeAudio,
|
|
774
|
+
kLiteRtLmInputDataTypeAudioEnd,
|
|
775
|
+
} LiteRtLmInputDataType;
|
|
776
|
+
|
|
777
|
+
// Creates a LiteRT LM Input Data. The caller is responsible for destroying
|
|
778
|
+
// the input data using `litert_lm_input_data_delete`.
|
|
779
|
+
//
|
|
780
|
+
// @param type The type of the input data.
|
|
781
|
+
// @param data The data pointer. For kLiteRtLmInputDataTypeText, it's a UTF-8
|
|
782
|
+
// string.
|
|
783
|
+
// For image/audio types, it's a pointer to the raw bytes.
|
|
784
|
+
// The data is copied internally.
|
|
785
|
+
// @param size The size of the data in bytes.
|
|
786
|
+
// @return A pointer to the created input data, or NULL on failure.
|
|
787
|
+
//
|
|
788
|
+
// Added in version 0.1.0.
|
|
789
|
+
LITERT_LM_C_API_EXPORT
|
|
790
|
+
LiteRtLmInputData* litert_lm_input_data_create(LiteRtLmInputDataType type,
|
|
791
|
+
const void* data, size_t size);
|
|
792
|
+
|
|
793
|
+
// Destroys a LiteRT LM Input Data.
|
|
794
|
+
//
|
|
795
|
+
// @param input_data The input data to destroy.
|
|
796
|
+
//
|
|
797
|
+
// Added in version 0.1.0.
|
|
798
|
+
LITERT_LM_C_API_EXPORT
|
|
799
|
+
void litert_lm_input_data_delete(LiteRtLmInputData* input_data);
|
|
157
800
|
|
|
158
801
|
// Creates LiteRT LM Engine Settings. The caller is responsible for destroying
|
|
159
802
|
// the settings using `litert_lm_engine_settings_delete`.
|
|
@@ -163,14 +806,36 @@ typedef struct {
|
|
|
163
806
|
// @param vision_backend_str The vision backend to use, or NULL if not set.
|
|
164
807
|
// @param audio_backend_str The audio backend to use, or NULL if not set.
|
|
165
808
|
// @return A pointer to the created settings, or NULL on failure.
|
|
809
|
+
//
|
|
810
|
+
// Added in version 0.1.0.
|
|
166
811
|
LITERT_LM_C_API_EXPORT
|
|
167
812
|
LiteRtLmEngineSettings* litert_lm_engine_settings_create(
|
|
168
813
|
const char* model_path, const char* backend_str,
|
|
169
814
|
const char* vision_backend_str, const char* audio_backend_str);
|
|
170
815
|
|
|
816
|
+
// Creates LiteRT LM Engine Settings from a raw file descriptor. The engine
|
|
817
|
+
// takes ownership of the file descriptor and will close it when done.
|
|
818
|
+
// The caller is responsible for destroying the settings using
|
|
819
|
+
// `litert_lm_engine_settings_delete`.
|
|
820
|
+
//
|
|
821
|
+
// @param fd The file descriptor of the model.
|
|
822
|
+
// @param backend_str The backend to use (e.g., "cpu", "gpu").
|
|
823
|
+
// @param vision_backend_str The vision backend to use, or NULL if not set.
|
|
824
|
+
// @param audio_backend_str The audio backend to use, or NULL if not set.
|
|
825
|
+
// @return A pointer to the created settings, or NULL on failure.
|
|
826
|
+
//
|
|
827
|
+
// Added in version 0.1.0.
|
|
828
|
+
LITERT_LM_C_API_EXPORT
|
|
829
|
+
LiteRtLmEngineSettings*
|
|
830
|
+
litert_lm_engine_settings_create_from_raw_file_descriptor(
|
|
831
|
+
int fd, const char* backend_str, const char* vision_backend_str,
|
|
832
|
+
const char* audio_backend_str);
|
|
833
|
+
|
|
171
834
|
// Destroys LiteRT LM Engine Settings.
|
|
172
835
|
//
|
|
173
836
|
// @param settings The settings to destroy.
|
|
837
|
+
//
|
|
838
|
+
// Added in version 0.1.0.
|
|
174
839
|
LITERT_LM_C_API_EXPORT
|
|
175
840
|
void litert_lm_engine_settings_delete(LiteRtLmEngineSettings* settings);
|
|
176
841
|
|
|
@@ -178,42 +843,103 @@ void litert_lm_engine_settings_delete(LiteRtLmEngineSettings* settings);
|
|
|
178
843
|
//
|
|
179
844
|
// @param settings The engine settings.
|
|
180
845
|
// @param max_num_tokens The maximum number of tokens.
|
|
846
|
+
//
|
|
847
|
+
// Added in version 0.1.0.
|
|
181
848
|
LITERT_LM_C_API_EXPORT
|
|
182
849
|
void litert_lm_engine_settings_set_max_num_tokens(
|
|
183
850
|
LiteRtLmEngineSettings* settings, int max_num_tokens);
|
|
184
851
|
|
|
852
|
+
// Sets the number of threads for the CPU backend.
|
|
853
|
+
//
|
|
854
|
+
// @param settings The engine settings.
|
|
855
|
+
// @param num_threads The number of threads.
|
|
856
|
+
//
|
|
857
|
+
// Added in version 0.1.0.
|
|
858
|
+
LITERT_LM_C_API_EXPORT
|
|
859
|
+
void litert_lm_engine_settings_set_num_threads(LiteRtLmEngineSettings* settings,
|
|
860
|
+
int num_threads);
|
|
861
|
+
|
|
862
|
+
// Sets the number of threads for the audio CPU backend.
|
|
863
|
+
//
|
|
864
|
+
// @param settings The engine settings.
|
|
865
|
+
// @param num_threads The number of threads.
|
|
866
|
+
//
|
|
867
|
+
// Added in version 0.1.0.
|
|
868
|
+
LITERT_LM_C_API_EXPORT
|
|
869
|
+
void litert_lm_engine_settings_set_audio_num_threads(
|
|
870
|
+
LiteRtLmEngineSettings* settings, int num_threads);
|
|
871
|
+
|
|
185
872
|
// Sets whether the engine should load different sections of the litertlm file
|
|
186
873
|
// in parallel. Defaults to true.
|
|
187
874
|
//
|
|
188
875
|
// @param settings The engine settings.
|
|
189
876
|
// @param parallel_file_section_loading Whether to load in parallel.
|
|
877
|
+
//
|
|
878
|
+
// Added in version 0.1.0.
|
|
879
|
+
LITERT_LM_C_API_EXPORT
|
|
880
|
+
void litert_lm_engine_settings_set_parallel_file_section_loading(
|
|
881
|
+
LiteRtLmEngineSettings* settings, bool parallel_file_section_loading);
|
|
882
|
+
|
|
883
|
+
// Sets the maximum number of images for the engine.
|
|
884
|
+
//
|
|
885
|
+
// This is only used for the legacy implementation of the engine.
|
|
886
|
+
//
|
|
887
|
+
// @param settings The engine settings.
|
|
888
|
+
// @param max_num_images The maximum number of images.
|
|
889
|
+
//
|
|
890
|
+
// Added in version 0.1.0.
|
|
190
891
|
LITERT_LM_C_API_EXPORT
|
|
191
|
-
void
|
|
192
|
-
LiteRtLmEngineSettings* settings,
|
|
892
|
+
void litert_lm_engine_settings_set_max_num_images(
|
|
893
|
+
LiteRtLmEngineSettings* settings, int max_num_images);
|
|
193
894
|
|
|
194
895
|
// Sets the cache directory for the engine.
|
|
195
896
|
//
|
|
196
897
|
// @param settings The engine settings.
|
|
197
898
|
// @param cache_dir The cache directory.
|
|
899
|
+
//
|
|
900
|
+
// Added in version 0.1.0.
|
|
198
901
|
LITERT_LM_C_API_EXPORT
|
|
199
902
|
void litert_lm_engine_settings_set_cache_dir(LiteRtLmEngineSettings* settings,
|
|
200
903
|
const char* cache_dir);
|
|
201
904
|
|
|
905
|
+
// Sets the LiteRT dispatch library directory for NPU backend.
|
|
906
|
+
//
|
|
907
|
+
// @param settings The engine settings.
|
|
908
|
+
// @param lib_dir The dispatch library directory.
|
|
909
|
+
//
|
|
910
|
+
// Added in version 0.1.0.
|
|
911
|
+
LITERT_LM_C_API_EXPORT
|
|
912
|
+
void litert_lm_engine_settings_set_litert_dispatch_lib_dir(
|
|
913
|
+
LiteRtLmEngineSettings* settings, const char* lib_dir);
|
|
914
|
+
|
|
915
|
+
// Represents the activation data type.
|
|
916
|
+
//
|
|
917
|
+
// Added in version 0.1.0.
|
|
918
|
+
typedef enum {
|
|
919
|
+
kLiteRtLmActivationDataTypeFloat32 = 0,
|
|
920
|
+
kLiteRtLmActivationDataTypeFloat16 = 1,
|
|
921
|
+
kLiteRtLmActivationDataTypeInt16 = 2,
|
|
922
|
+
kLiteRtLmActivationDataTypeInt8 = 3,
|
|
923
|
+
} LiteRtLmActivationDataType;
|
|
924
|
+
|
|
202
925
|
// Sets the activation data type.
|
|
203
926
|
//
|
|
204
927
|
// @param settings The engine settings.
|
|
205
|
-
// @param
|
|
206
|
-
//
|
|
207
|
-
//
|
|
928
|
+
// @param activation_data_type The activation data type.
|
|
929
|
+
//
|
|
930
|
+
// Added in version 0.1.0.
|
|
208
931
|
LITERT_LM_C_API_EXPORT
|
|
209
932
|
void litert_lm_engine_settings_set_activation_data_type(
|
|
210
|
-
LiteRtLmEngineSettings* settings,
|
|
933
|
+
LiteRtLmEngineSettings* settings,
|
|
934
|
+
LiteRtLmActivationDataType activation_data_type);
|
|
211
935
|
|
|
212
936
|
// Sets the prefill chunk size for the engine. Only applicable for CPU backend
|
|
213
937
|
// with dynamic models.
|
|
214
938
|
//
|
|
215
939
|
// @param settings The engine settings.
|
|
216
940
|
// @param prefill_chunk_size The prefill chunk size.
|
|
941
|
+
//
|
|
942
|
+
// Added in version 0.1.0.
|
|
217
943
|
LITERT_LM_C_API_EXPORT
|
|
218
944
|
void litert_lm_engine_settings_set_prefill_chunk_size(
|
|
219
945
|
LiteRtLmEngineSettings* settings, int prefill_chunk_size);
|
|
@@ -221,6 +947,8 @@ void litert_lm_engine_settings_set_prefill_chunk_size(
|
|
|
221
947
|
// Enables benchmarking for the engine.
|
|
222
948
|
//
|
|
223
949
|
// @param settings The engine settings.
|
|
950
|
+
//
|
|
951
|
+
// Added in version 0.1.0.
|
|
224
952
|
LITERT_LM_C_API_EXPORT
|
|
225
953
|
void litert_lm_engine_settings_enable_benchmark(
|
|
226
954
|
LiteRtLmEngineSettings* settings);
|
|
@@ -229,6 +957,8 @@ void litert_lm_engine_settings_enable_benchmark(
|
|
|
229
957
|
//
|
|
230
958
|
// @param settings The engine settings.
|
|
231
959
|
// @param num_prefill_tokens The number of prefill tokens.
|
|
960
|
+
//
|
|
961
|
+
// Added in version 0.1.0.
|
|
232
962
|
LITERT_LM_C_API_EXPORT
|
|
233
963
|
void litert_lm_engine_settings_set_num_prefill_tokens(
|
|
234
964
|
LiteRtLmEngineSettings* settings, int num_prefill_tokens);
|
|
@@ -237,26 +967,124 @@ void litert_lm_engine_settings_set_num_prefill_tokens(
|
|
|
237
967
|
//
|
|
238
968
|
// @param settings The engine settings.
|
|
239
969
|
// @param num_decode_tokens The number of decode tokens.
|
|
970
|
+
//
|
|
971
|
+
// Added in version 0.1.0.
|
|
240
972
|
LITERT_LM_C_API_EXPORT
|
|
241
973
|
void litert_lm_engine_settings_set_num_decode_tokens(
|
|
242
974
|
LiteRtLmEngineSettings* settings, int num_decode_tokens);
|
|
243
975
|
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
//
|
|
976
|
+
// Sets whether to enable speculative decoding.
|
|
977
|
+
//
|
|
978
|
+
// @param settings The engine settings.
|
|
979
|
+
// @param enable_speculative_decoding Whether to enable speculative decoding.
|
|
980
|
+
//
|
|
981
|
+
// Added in version 0.1.0.
|
|
982
|
+
LITERT_LM_C_API_EXPORT
|
|
983
|
+
void litert_lm_engine_settings_set_enable_speculative_decoding(
|
|
984
|
+
LiteRtLmEngineSettings* settings, bool enable_speculative_decoding);
|
|
985
|
+
|
|
986
|
+
// Sets the number of decode steps per sync for the GPU backend.
|
|
987
|
+
// Note: This setting is currently only supported for the Artisan GPU
|
|
988
|
+
// backend (Artisan).
|
|
989
|
+
//
|
|
990
|
+
// @param settings The engine settings.
|
|
991
|
+
// @param num_decode_steps_per_sync The number of decode steps per sync.
|
|
992
|
+
//
|
|
993
|
+
// Added in version 0.1.0.
|
|
994
|
+
LITERT_LM_C_API_EXPORT
|
|
995
|
+
void litert_lm_engine_settings_set_gpu_decode_steps_per_sync(
|
|
996
|
+
LiteRtLmEngineSettings* settings, int num_decode_steps_per_sync);
|
|
997
|
+
|
|
998
|
+
// Sets whether to wait for weight uploads for the GPU backend.
|
|
999
|
+
// Note: This setting is currently only supported for the Artisan GPU backend.
|
|
1000
|
+
//
|
|
1001
|
+
// @param settings The engine settings.
|
|
1002
|
+
// @param wait_for_weight_uploads Whether to wait for weight uploads.
|
|
1003
|
+
//
|
|
1004
|
+
// Added in version 0.1.0.
|
|
1005
|
+
LITERT_LM_C_API_EXPORT
|
|
1006
|
+
void litert_lm_engine_settings_set_gpu_wait_for_weight_uploads(
|
|
1007
|
+
LiteRtLmEngineSettings* settings, bool wait_for_weight_uploads);
|
|
1008
|
+
|
|
1009
|
+
// Sets whether to use ringbuffers for local attention KV cache.
|
|
1010
|
+
//
|
|
1011
|
+
// When enabled for supported models, a ringbuffer stores only necessary KV
|
|
1012
|
+
// cache memory for local attention layers, minimizing memory usage. When
|
|
1013
|
+
// disabled, memory is allocated for the full context length, enabling instant
|
|
1014
|
+
// rewinding at the cost of higher memory usage.
|
|
1015
|
+
//
|
|
1016
|
+
// Note: This feature is backend-agnostic in interface design, but currently
|
|
1017
|
+
// only supported by the GPU Artisan backend. Enabling it on unsupported models
|
|
1018
|
+
// or backends will be ignored with a warning.
|
|
1019
|
+
//
|
|
1020
|
+
// @param settings The engine settings.
|
|
1021
|
+
// @param use_ringbuffers_local_attention Whether to use ringbuffers for local
|
|
1022
|
+
// attention.
|
|
1023
|
+
//
|
|
1024
|
+
// Added in version 0.1.0.
|
|
1025
|
+
LITERT_LM_C_API_EXPORT
|
|
1026
|
+
void litert_lm_engine_settings_set_use_ringbuffers_local_attention(
|
|
1027
|
+
LiteRtLmEngineSettings* settings, bool use_ringbuffers_local_attention);
|
|
1028
|
+
|
|
1029
|
+
// Sets the LoRA rank for the engine.
|
|
1030
|
+
//
|
|
1031
|
+
// @param settings The engine settings.
|
|
1032
|
+
// @param lora_rank The LoRA rank.
|
|
1033
|
+
//
|
|
1034
|
+
// Added in version 0.1.0.
|
|
1035
|
+
LITERT_LM_C_API_EXPORT
|
|
1036
|
+
void litert_lm_engine_settings_set_lora_rank(LiteRtLmEngineSettings* settings,
|
|
1037
|
+
int lora_rank);
|
|
1038
|
+
|
|
1039
|
+
// Sets the supported LoRA ranks for the engine.
|
|
1040
|
+
//
|
|
1041
|
+
// @param settings The engine settings.
|
|
1042
|
+
// @param lora_ranks An array of supported LoRA ranks.
|
|
1043
|
+
// @param num_ranks The number of ranks in the array.
|
|
1044
|
+
// @return 0 on success, non-zero on failure.
|
|
1045
|
+
//
|
|
1046
|
+
// Added in version 0.1.0.
|
|
1047
|
+
LITERT_LM_C_API_EXPORT
|
|
1048
|
+
int litert_lm_engine_settings_set_supported_lora_ranks(
|
|
1049
|
+
LiteRtLmEngineSettings* settings, const int* lora_ranks, size_t num_ranks);
|
|
1050
|
+
|
|
1051
|
+
// Sets the Audio LoRA rank for the engine.
|
|
1052
|
+
//
|
|
1053
|
+
// @param settings The engine settings.
|
|
1054
|
+
// @param lora_rank The Audio LoRA rank.
|
|
1055
|
+
//
|
|
1056
|
+
// Added in version 0.1.0.
|
|
1057
|
+
LITERT_LM_C_API_EXPORT
|
|
1058
|
+
void litert_lm_engine_settings_set_audio_lora_rank(
|
|
1059
|
+
LiteRtLmEngineSettings* settings, int lora_rank);
|
|
1060
|
+
|
|
1061
|
+
// Sets the supported Audio LoRA ranks for the engine.
|
|
1062
|
+
//
|
|
1063
|
+
// @param settings The engine settings.
|
|
1064
|
+
// @param lora_ranks An array of supported Audio LoRA ranks.
|
|
1065
|
+
// @param num_ranks The number of ranks in the array.
|
|
1066
|
+
// @return 0 on success, non-zero on failure.
|
|
1067
|
+
//
|
|
1068
|
+
// Added in version 0.1.0.
|
|
247
1069
|
LITERT_LM_C_API_EXPORT
|
|
1070
|
+
int litert_lm_engine_settings_set_supported_audio_lora_ranks(
|
|
1071
|
+
LiteRtLmEngineSettings* settings, const int* lora_ranks, size_t num_ranks);
|
|
248
1072
|
|
|
249
1073
|
// Creates a LiteRT LM Engine from the given settings. The caller is responsible
|
|
250
1074
|
// for destroying the engine using `litert_lm_engine_delete`.
|
|
251
1075
|
//
|
|
252
1076
|
// @param settings The engine settings.
|
|
253
1077
|
// @return A pointer to the created engine, or NULL on failure.
|
|
1078
|
+
//
|
|
1079
|
+
// Added in version 0.1.0.
|
|
254
1080
|
LITERT_LM_C_API_EXPORT
|
|
255
1081
|
LiteRtLmEngine* litert_lm_engine_create(const LiteRtLmEngineSettings* settings);
|
|
256
1082
|
|
|
257
1083
|
// Destroys a LiteRT LM Engine.
|
|
258
1084
|
//
|
|
259
1085
|
// @param engine The engine to destroy.
|
|
1086
|
+
//
|
|
1087
|
+
// Added in version 0.1.0.
|
|
260
1088
|
LITERT_LM_C_API_EXPORT
|
|
261
1089
|
void litert_lm_engine_delete(LiteRtLmEngine* engine);
|
|
262
1090
|
|
|
@@ -267,6 +1095,8 @@ void litert_lm_engine_delete(LiteRtLmEngine* engine);
|
|
|
267
1095
|
// @param config The session config of the session. If NULL, use the default
|
|
268
1096
|
// session config.
|
|
269
1097
|
// @return A pointer to the created session, or NULL on failure.
|
|
1098
|
+
//
|
|
1099
|
+
// Added in version 0.1.0.
|
|
270
1100
|
LITERT_LM_C_API_EXPORT
|
|
271
1101
|
LiteRtLmSession* litert_lm_engine_create_session(LiteRtLmEngine* engine,
|
|
272
1102
|
LiteRtLmSessionConfig* config);
|
|
@@ -274,24 +1104,85 @@ LiteRtLmSession* litert_lm_engine_create_session(LiteRtLmEngine* engine,
|
|
|
274
1104
|
// Destroys a LiteRT LM Session.
|
|
275
1105
|
//
|
|
276
1106
|
// @param session The session to destroy.
|
|
1107
|
+
//
|
|
1108
|
+
// Added in version 0.1.0.
|
|
277
1109
|
LITERT_LM_C_API_EXPORT
|
|
278
1110
|
void litert_lm_session_delete(LiteRtLmSession* session);
|
|
279
1111
|
|
|
280
|
-
//
|
|
1112
|
+
// Cancels the current processing in the session.
|
|
281
1113
|
//
|
|
282
|
-
// @param session The session to
|
|
1114
|
+
// @param session The session to cancel processing on.
|
|
1115
|
+
//
|
|
1116
|
+
// Added in version 0.1.0.
|
|
1117
|
+
LITERT_LM_C_API_EXPORT
|
|
1118
|
+
void litert_lm_session_cancel_process(LiteRtLmSession* session);
|
|
1119
|
+
|
|
1120
|
+
// Adds the input prompt/query to the model for starting the prefilling
|
|
1121
|
+
// process. This is a blocking call and the function will return when the
|
|
1122
|
+
// prefill process is done.
|
|
1123
|
+
//
|
|
1124
|
+
// @param session The session to use.
|
|
283
1125
|
// @param inputs An array of InputData structs representing the multimodal
|
|
284
1126
|
// input.
|
|
285
1127
|
// @param num_inputs The number of InputData structs in the array.
|
|
1128
|
+
// @return 0 on success, non-zero on failure.
|
|
1129
|
+
//
|
|
1130
|
+
// Added in version 0.1.0.
|
|
1131
|
+
LITERT_LM_C_API_EXPORT
|
|
1132
|
+
int litert_lm_session_run_prefill(LiteRtLmSession* session,
|
|
1133
|
+
const LiteRtLmInputData* const* inputs,
|
|
1134
|
+
size_t num_inputs);
|
|
1135
|
+
|
|
1136
|
+
// Starts the decoding process for the model to predict the response based
|
|
1137
|
+
// on the input prompt/query added after using litert_lm_session_run_prefill.
|
|
1138
|
+
// This is a blocking call and the function will return when the decoding
|
|
1139
|
+
// process is done.
|
|
1140
|
+
//
|
|
1141
|
+
// @param session The session to use.
|
|
1142
|
+
// @return A pointer to the responses, or NULL on failure. The caller is
|
|
1143
|
+
// responsible for deleting the responses using `litert_lm_responses_delete`.
|
|
1144
|
+
//
|
|
1145
|
+
// Added in version 0.1.0.
|
|
1146
|
+
LITERT_LM_C_API_EXPORT
|
|
1147
|
+
LiteRtLmResponses* litert_lm_session_run_decode(LiteRtLmSession* session);
|
|
1148
|
+
|
|
1149
|
+
// Scores the target text after the prefill process is done.
|
|
1150
|
+
//
|
|
1151
|
+
// @param session The session to use.
|
|
1152
|
+
// @param target_text An array of target text strings to score.
|
|
1153
|
+
// @param num_targets The number of strings in the target_text array.
|
|
1154
|
+
// @param store_token_lengths Whether to store the token lengths of the target
|
|
1155
|
+
// texts in the responses.
|
|
1156
|
+
// @return A pointer to the responses, or NULL on failure. The caller is
|
|
1157
|
+
// responsible for deleting the responses using `litert_lm_responses_delete`.
|
|
1158
|
+
//
|
|
1159
|
+
// Added in version 0.1.0.
|
|
1160
|
+
LITERT_LM_C_API_EXPORT
|
|
1161
|
+
LiteRtLmResponses* litert_lm_session_run_text_scoring(LiteRtLmSession* session,
|
|
1162
|
+
const char** target_text,
|
|
1163
|
+
size_t num_targets,
|
|
1164
|
+
bool store_token_lengths);
|
|
1165
|
+
|
|
1166
|
+
// Generates content from the input prompt.
|
|
1167
|
+
//
|
|
1168
|
+
// @param session The session to use for generation.
|
|
1169
|
+
// @param inputs An array of LiteRtLmInputData structs representing the
|
|
1170
|
+
// multimodal
|
|
1171
|
+
// input.
|
|
1172
|
+
// @param num_inputs The number of LiteRtLmInputData structs in the array.
|
|
286
1173
|
// @return A pointer to the responses, or NULL on failure. The caller is
|
|
287
1174
|
// responsible for deleting the responses using `litert_lm_responses_delete`.
|
|
1175
|
+
//
|
|
1176
|
+
// Added in version 0.1.0.
|
|
288
1177
|
LITERT_LM_C_API_EXPORT
|
|
289
|
-
LiteRtLmResponses* litert_lm_session_generate_content(
|
|
290
|
-
|
|
291
|
-
|
|
1178
|
+
LiteRtLmResponses* litert_lm_session_generate_content(
|
|
1179
|
+
LiteRtLmSession* session, const LiteRtLmInputData* const* inputs,
|
|
1180
|
+
size_t num_inputs);
|
|
292
1181
|
// Destroys a LiteRT LM Responses object.
|
|
293
1182
|
//
|
|
294
1183
|
// @param responses The responses to destroy.
|
|
1184
|
+
//
|
|
1185
|
+
// Added in version 0.1.0.
|
|
295
1186
|
LITERT_LM_C_API_EXPORT
|
|
296
1187
|
void litert_lm_responses_delete(LiteRtLmResponses* responses);
|
|
297
1188
|
|
|
@@ -299,6 +1190,8 @@ void litert_lm_responses_delete(LiteRtLmResponses* responses);
|
|
|
299
1190
|
//
|
|
300
1191
|
// @param responses The responses object.
|
|
301
1192
|
// @return The number of candidates.
|
|
1193
|
+
//
|
|
1194
|
+
// Added in version 0.1.0.
|
|
302
1195
|
LITERT_LM_C_API_EXPORT
|
|
303
1196
|
int litert_lm_responses_get_num_candidates(const LiteRtLmResponses* responses);
|
|
304
1197
|
|
|
@@ -309,16 +1202,104 @@ int litert_lm_responses_get_num_candidates(const LiteRtLmResponses* responses);
|
|
|
309
1202
|
// @return The response text. The returned string is owned by the `responses`
|
|
310
1203
|
// object and is valid only for its lifetime. Returns NULL if index is out of
|
|
311
1204
|
// bounds.
|
|
1205
|
+
//
|
|
1206
|
+
// Added in version 0.1.0.
|
|
312
1207
|
LITERT_LM_C_API_EXPORT
|
|
313
1208
|
const char* litert_lm_responses_get_response_text_at(
|
|
314
1209
|
const LiteRtLmResponses* responses, int index);
|
|
315
1210
|
|
|
1211
|
+
// Returns whether the response contains a score at the given index.
|
|
1212
|
+
//
|
|
1213
|
+
// @param responses The responses object.
|
|
1214
|
+
// @param index The index of the response.
|
|
1215
|
+
// @return true if the score is available at the given index, false otherwise.
|
|
1216
|
+
//
|
|
1217
|
+
// Added in version 0.1.0.
|
|
1218
|
+
LITERT_LM_C_API_EXPORT
|
|
1219
|
+
bool litert_lm_responses_has_score_at(const LiteRtLmResponses* responses,
|
|
1220
|
+
int index);
|
|
1221
|
+
|
|
1222
|
+
// Returns the score at a given index.
|
|
1223
|
+
//
|
|
1224
|
+
// @param responses The responses object.
|
|
1225
|
+
// @param index The index of the response.
|
|
1226
|
+
// @return The score. Returns 0.0f if index is out of bounds or no score is
|
|
1227
|
+
// present.
|
|
1228
|
+
//
|
|
1229
|
+
// Added in version 0.1.0.
|
|
1230
|
+
LITERT_LM_C_API_EXPORT
|
|
1231
|
+
float litert_lm_responses_get_score_at(const LiteRtLmResponses* responses,
|
|
1232
|
+
int index);
|
|
1233
|
+
|
|
1234
|
+
// Returns whether the response contains a token length at the given index.
|
|
1235
|
+
//
|
|
1236
|
+
// @param responses The responses object.
|
|
1237
|
+
// @param index The index of the response.
|
|
1238
|
+
// @return true if the token length is available at the given index, false
|
|
1239
|
+
// otherwise.
|
|
1240
|
+
//
|
|
1241
|
+
// Added in version 0.1.0.
|
|
1242
|
+
LITERT_LM_C_API_EXPORT
|
|
1243
|
+
bool litert_lm_responses_has_token_length_at(const LiteRtLmResponses* responses,
|
|
1244
|
+
int index);
|
|
1245
|
+
|
|
1246
|
+
// Returns the token length at a given index.
|
|
1247
|
+
//
|
|
1248
|
+
// @param responses The responses object.
|
|
1249
|
+
// @param index The index of the response.
|
|
1250
|
+
// @return The token length. Returns 0 if index is out of bounds or no token
|
|
1251
|
+
// length is present.
|
|
1252
|
+
//
|
|
1253
|
+
// Added in version 0.1.0.
|
|
1254
|
+
LITERT_LM_C_API_EXPORT
|
|
1255
|
+
int litert_lm_responses_get_token_length_at(const LiteRtLmResponses* responses,
|
|
1256
|
+
int index);
|
|
1257
|
+
|
|
1258
|
+
// Returns whether the response contains token scores at the given index.
|
|
1259
|
+
//
|
|
1260
|
+
// @param responses The responses object.
|
|
1261
|
+
// @param index The index of the response.
|
|
1262
|
+
// @return true if token scores are available at the given index, false
|
|
1263
|
+
// otherwise.
|
|
1264
|
+
//
|
|
1265
|
+
// Added in version 0.1.0.
|
|
1266
|
+
LITERT_LM_C_API_EXPORT
|
|
1267
|
+
bool litert_lm_responses_has_token_scores_at(const LiteRtLmResponses* responses,
|
|
1268
|
+
int index);
|
|
1269
|
+
|
|
1270
|
+
// Returns the number of tokens for which scores are present at a given index.
|
|
1271
|
+
//
|
|
1272
|
+
// @param responses The responses object.
|
|
1273
|
+
// @param index The index of the response.
|
|
1274
|
+
// @return The number of token scores. Returns 0 if index is out of bounds or no
|
|
1275
|
+
// token scores are present.
|
|
1276
|
+
//
|
|
1277
|
+
// Added in version 0.1.0.
|
|
1278
|
+
LITERT_LM_C_API_EXPORT
|
|
1279
|
+
int litert_lm_responses_get_num_token_scores_at(
|
|
1280
|
+
const LiteRtLmResponses* responses, int index);
|
|
1281
|
+
|
|
1282
|
+
// Returns the token scores at a given index.
|
|
1283
|
+
//
|
|
1284
|
+
// @param responses The responses object.
|
|
1285
|
+
// @param index The index of the response.
|
|
1286
|
+
// @return A pointer to the internal array of token scores. Returns NULL if
|
|
1287
|
+
// index
|
|
1288
|
+
// is out of bounds or no token scores are present.
|
|
1289
|
+
//
|
|
1290
|
+
// Added in version 0.1.0.
|
|
1291
|
+
LITERT_LM_C_API_EXPORT
|
|
1292
|
+
const float* litert_lm_responses_get_token_scores_at(
|
|
1293
|
+
const LiteRtLmResponses* responses, int index);
|
|
1294
|
+
|
|
316
1295
|
// Retrieves the benchmark information from the session. The caller is
|
|
317
1296
|
// responsible for destroying the benchmark info using
|
|
318
1297
|
// `litert_lm_benchmark_info_delete`.
|
|
319
1298
|
//
|
|
320
1299
|
// @param session The session to get the benchmark info from.
|
|
321
1300
|
// @return A pointer to the benchmark info, or NULL on failure.
|
|
1301
|
+
//
|
|
1302
|
+
// Added in version 0.1.0.
|
|
322
1303
|
LITERT_LM_C_API_EXPORT
|
|
323
1304
|
LiteRtLmBenchmarkInfo* litert_lm_session_get_benchmark_info(
|
|
324
1305
|
LiteRtLmSession* session);
|
|
@@ -326,6 +1307,8 @@ LiteRtLmBenchmarkInfo* litert_lm_session_get_benchmark_info(
|
|
|
326
1307
|
// Destroys a LiteRT LM Benchmark Info object.
|
|
327
1308
|
//
|
|
328
1309
|
// @param benchmark_info The benchmark info to destroy.
|
|
1310
|
+
//
|
|
1311
|
+
// Added in version 0.1.0.
|
|
329
1312
|
LITERT_LM_C_API_EXPORT
|
|
330
1313
|
void litert_lm_benchmark_info_delete(LiteRtLmBenchmarkInfo* benchmark_info);
|
|
331
1314
|
|
|
@@ -337,6 +1320,8 @@ void litert_lm_benchmark_info_delete(LiteRtLmBenchmarkInfo* benchmark_info);
|
|
|
337
1320
|
//
|
|
338
1321
|
// @param benchmark_info The benchmark info object.
|
|
339
1322
|
// @return The time to the first token in seconds.
|
|
1323
|
+
//
|
|
1324
|
+
// Added in version 0.1.0.
|
|
340
1325
|
LITERT_LM_C_API_EXPORT
|
|
341
1326
|
double litert_lm_benchmark_info_get_time_to_first_token(
|
|
342
1327
|
const LiteRtLmBenchmarkInfo* benchmark_info);
|
|
@@ -345,6 +1330,8 @@ double litert_lm_benchmark_info_get_time_to_first_token(
|
|
|
345
1330
|
//
|
|
346
1331
|
// @param benchmark_info The benchmark info object.
|
|
347
1332
|
// @return The total initialization time in seconds.
|
|
1333
|
+
//
|
|
1334
|
+
// Added in version 0.1.0.
|
|
348
1335
|
LITERT_LM_C_API_EXPORT
|
|
349
1336
|
double litert_lm_benchmark_info_get_total_init_time_in_second(
|
|
350
1337
|
const LiteRtLmBenchmarkInfo* benchmark_info);
|
|
@@ -353,6 +1340,8 @@ double litert_lm_benchmark_info_get_total_init_time_in_second(
|
|
|
353
1340
|
//
|
|
354
1341
|
// @param benchmark_info The benchmark info object.
|
|
355
1342
|
// @return The number of prefill turns.
|
|
1343
|
+
//
|
|
1344
|
+
// Added in version 0.1.0.
|
|
356
1345
|
LITERT_LM_C_API_EXPORT
|
|
357
1346
|
int litert_lm_benchmark_info_get_num_prefill_turns(
|
|
358
1347
|
const LiteRtLmBenchmarkInfo* benchmark_info);
|
|
@@ -361,6 +1350,8 @@ int litert_lm_benchmark_info_get_num_prefill_turns(
|
|
|
361
1350
|
//
|
|
362
1351
|
// @param benchmark_info The benchmark info object.
|
|
363
1352
|
// @return The number of decode turns.
|
|
1353
|
+
//
|
|
1354
|
+
// Added in version 0.1.0.
|
|
364
1355
|
LITERT_LM_C_API_EXPORT
|
|
365
1356
|
int litert_lm_benchmark_info_get_num_decode_turns(
|
|
366
1357
|
const LiteRtLmBenchmarkInfo* benchmark_info);
|
|
@@ -370,6 +1361,8 @@ int litert_lm_benchmark_info_get_num_decode_turns(
|
|
|
370
1361
|
// @param benchmark_info The benchmark info object.
|
|
371
1362
|
// @param index The index of the prefill turn.
|
|
372
1363
|
// @return The prefill token count.
|
|
1364
|
+
//
|
|
1365
|
+
// Added in version 0.1.0.
|
|
373
1366
|
LITERT_LM_C_API_EXPORT
|
|
374
1367
|
int litert_lm_benchmark_info_get_prefill_token_count_at(
|
|
375
1368
|
const LiteRtLmBenchmarkInfo* benchmark_info, int index);
|
|
@@ -379,6 +1372,8 @@ int litert_lm_benchmark_info_get_prefill_token_count_at(
|
|
|
379
1372
|
// @param benchmark_info The benchmark info object.
|
|
380
1373
|
// @param index The index of the decode turn.
|
|
381
1374
|
// @return The decode token count.
|
|
1375
|
+
//
|
|
1376
|
+
// Added in version 0.1.0.
|
|
382
1377
|
LITERT_LM_C_API_EXPORT
|
|
383
1378
|
int litert_lm_benchmark_info_get_decode_token_count_at(
|
|
384
1379
|
const LiteRtLmBenchmarkInfo* benchmark_info, int index);
|
|
@@ -388,6 +1383,8 @@ int litert_lm_benchmark_info_get_decode_token_count_at(
|
|
|
388
1383
|
// @param benchmark_info The benchmark info object.
|
|
389
1384
|
// @param index The index of the prefill turn.
|
|
390
1385
|
// @return The prefill tokens per second.
|
|
1386
|
+
//
|
|
1387
|
+
// Added in version 0.1.0.
|
|
391
1388
|
LITERT_LM_C_API_EXPORT
|
|
392
1389
|
double litert_lm_benchmark_info_get_prefill_tokens_per_sec_at(
|
|
393
1390
|
const LiteRtLmBenchmarkInfo* benchmark_info, int index);
|
|
@@ -397,37 +1394,86 @@ double litert_lm_benchmark_info_get_prefill_tokens_per_sec_at(
|
|
|
397
1394
|
// @param benchmark_info The benchmark info object.
|
|
398
1395
|
// @param index The index of the decode turn.
|
|
399
1396
|
// @return The decode tokens per second.
|
|
1397
|
+
//
|
|
1398
|
+
// Added in version 0.1.0.
|
|
400
1399
|
LITERT_LM_C_API_EXPORT
|
|
401
1400
|
double litert_lm_benchmark_info_get_decode_tokens_per_sec_at(
|
|
402
1401
|
const LiteRtLmBenchmarkInfo* benchmark_info, int index);
|
|
403
1402
|
|
|
1403
|
+
// Opaque pointer for LiteRT LM Stream Chunk.
|
|
1404
|
+
// This object represents a single chunk of data returned during streaming.
|
|
1405
|
+
// It is owned by the library and is only valid for the duration of the
|
|
1406
|
+
// callback.
|
|
1407
|
+
//
|
|
1408
|
+
// Added in version 0.1.0.
|
|
1409
|
+
typedef struct LiteRtLmStreamChunk LiteRtLmStreamChunk;
|
|
1410
|
+
|
|
1411
|
+
// Gets the text content of the chunk.
|
|
1412
|
+
// The returned string is owned by the chunk and is only valid as long as the
|
|
1413
|
+
// chunk is valid. Returns NULL if there is no text content in this chunk (e.g.
|
|
1414
|
+
// if it is an error or metadata-only chunk).
|
|
1415
|
+
//
|
|
1416
|
+
// Added in version 0.1.0.
|
|
1417
|
+
LITERT_LM_C_API_EXPORT
|
|
1418
|
+
const char* litert_lm_stream_chunk_get_text(const LiteRtLmStreamChunk* chunk);
|
|
1419
|
+
|
|
1420
|
+
// Returns true if this is the final chunk of the stream.
|
|
1421
|
+
//
|
|
1422
|
+
// Added in version 0.1.0.
|
|
1423
|
+
LITERT_LM_C_API_EXPORT
|
|
1424
|
+
bool litert_lm_stream_chunk_is_final(const LiteRtLmStreamChunk* chunk);
|
|
1425
|
+
|
|
1426
|
+
// Gets the error message associated with this chunk, if any.
|
|
1427
|
+
// Returns NULL if there is no error.
|
|
1428
|
+
//
|
|
1429
|
+
// Added in version 0.1.0.
|
|
1430
|
+
LITERT_LM_C_API_EXPORT
|
|
1431
|
+
const char* litert_lm_stream_chunk_get_error(const LiteRtLmStreamChunk* chunk);
|
|
1432
|
+
|
|
404
1433
|
// Callback for streaming responses.
|
|
405
1434
|
// `callback_data` is a pointer to user-defined data passed to the stream
|
|
406
|
-
// function. `chunk` is
|
|
407
|
-
// the duration of the call.
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
typedef void (*LiteRtLmStreamCallback)(void* callback_data,
|
|
411
|
-
|
|
1435
|
+
// function. `chunk` is a pointer to the stream chunk object. It's only valid
|
|
1436
|
+
// for the duration of the call.
|
|
1437
|
+
//
|
|
1438
|
+
// Added in version 0.1.0.
|
|
1439
|
+
typedef void (*LiteRtLmStreamCallback)(void* callback_data,
|
|
1440
|
+
const LiteRtLmStreamChunk* chunk);
|
|
1441
|
+
|
|
1442
|
+
// Starts the decoding process for the model to predict the response based
|
|
1443
|
+
// on the input prompt/query added after using litert_lm_session_run_prefill.
|
|
1444
|
+
// This is a non-blocking call that will stream responses via a callback.
|
|
1445
|
+
//
|
|
1446
|
+
// @param session The session to use.
|
|
1447
|
+
// @param callback The callback function to receive response chunks.
|
|
1448
|
+
// @param callback_data A pointer to user data that will be passed to the
|
|
1449
|
+
// callback.
|
|
1450
|
+
// @return 0 on success, non-zero on failure.
|
|
1451
|
+
//
|
|
1452
|
+
// Added in version 0.1.0.
|
|
1453
|
+
LITERT_LM_C_API_EXPORT
|
|
1454
|
+
int litert_lm_session_run_decode_async(LiteRtLmSession* session,
|
|
1455
|
+
LiteRtLmStreamCallback callback,
|
|
1456
|
+
void* callback_data);
|
|
412
1457
|
|
|
413
1458
|
// Generates content from the input prompt and streams the response via a
|
|
414
1459
|
// callback. This is a non-blocking call that will invoke the callback from a
|
|
415
1460
|
// background thread for each chunk.
|
|
416
1461
|
//
|
|
417
1462
|
// @param session The session to use for generation.
|
|
418
|
-
// @param inputs An array of
|
|
1463
|
+
// @param inputs An array of LiteRtLmInputData structs representing the
|
|
1464
|
+
// multimodal
|
|
419
1465
|
// input.
|
|
420
|
-
// @param num_inputs The number of
|
|
1466
|
+
// @param num_inputs The number of LiteRtLmInputData structs in the array.
|
|
421
1467
|
// @param callback The callback function to receive response chunks.
|
|
422
1468
|
// @param callback_data A pointer to user data that will be passed to the
|
|
423
1469
|
// callback.
|
|
424
1470
|
// @return 0 on success, non-zero on failure to start the stream.
|
|
1471
|
+
//
|
|
1472
|
+
// Added in version 0.1.0.
|
|
425
1473
|
LITERT_LM_C_API_EXPORT
|
|
426
|
-
int litert_lm_session_generate_content_stream(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
LiteRtLmStreamCallback callback,
|
|
430
|
-
void* callback_data);
|
|
1474
|
+
int litert_lm_session_generate_content_stream(
|
|
1475
|
+
LiteRtLmSession* session, const LiteRtLmInputData* const* inputs,
|
|
1476
|
+
size_t num_inputs, LiteRtLmStreamCallback callback, void* callback_data);
|
|
431
1477
|
|
|
432
1478
|
// Creates a LiteRT LM Conversation. The caller is responsible for destroying
|
|
433
1479
|
// the conversation using `litert_lm_conversation_delete`.
|
|
@@ -436,6 +1482,8 @@ int litert_lm_session_generate_content_stream(LiteRtLmSession* session,
|
|
|
436
1482
|
// @param config The conversation config to use. If NULL, the default config
|
|
437
1483
|
// will be used.
|
|
438
1484
|
// @return A pointer to the created conversation, or NULL on failure.
|
|
1485
|
+
//
|
|
1486
|
+
// Added in version 0.1.0.
|
|
439
1487
|
LITERT_LM_C_API_EXPORT
|
|
440
1488
|
LiteRtLmConversation* litert_lm_conversation_create(
|
|
441
1489
|
LiteRtLmEngine* engine, LiteRtLmConversationConfig* config);
|
|
@@ -443,26 +1491,46 @@ LiteRtLmConversation* litert_lm_conversation_create(
|
|
|
443
1491
|
// Destroys a LiteRT LM Conversation.
|
|
444
1492
|
//
|
|
445
1493
|
// @param conversation The conversation to destroy.
|
|
1494
|
+
//
|
|
1495
|
+
// Added in version 0.1.0.
|
|
446
1496
|
LITERT_LM_C_API_EXPORT
|
|
447
1497
|
void litert_lm_conversation_delete(LiteRtLmConversation* conversation);
|
|
448
1498
|
|
|
1499
|
+
// Clones a LiteRT LM Conversation, duplicating its prefilled state.
|
|
1500
|
+
// The caller is responsible for destroying the cloned conversation using
|
|
1501
|
+
// `litert_lm_conversation_delete`.
|
|
1502
|
+
//
|
|
1503
|
+
// @param conversation The conversation to clone.
|
|
1504
|
+
// @return A pointer to the cloned conversation, or NULL on failure.
|
|
1505
|
+
//
|
|
1506
|
+
// Added in version 0.1.0.
|
|
1507
|
+
LITERT_LM_C_API_EXPORT
|
|
1508
|
+
LiteRtLmConversation* litert_lm_conversation_clone(
|
|
1509
|
+
LiteRtLmConversation* conversation);
|
|
1510
|
+
|
|
449
1511
|
// Sends a message to the conversation and returns the response.
|
|
450
1512
|
// This is a blocking call.
|
|
451
1513
|
//
|
|
452
1514
|
// @param conversation The conversation to use.
|
|
453
1515
|
// @param message_json A JSON string representing the message to send.
|
|
454
1516
|
// @param extra_context A JSON string representing the extra context to use.
|
|
1517
|
+
// @param optional_args A pointer to the optional arguments to use.
|
|
455
1518
|
// @return A pointer to the JSON response, or NULL on failure. The caller is
|
|
456
1519
|
// responsible for deleting the response using
|
|
457
1520
|
// `litert_lm_json_response_delete`.
|
|
1521
|
+
//
|
|
1522
|
+
// Added in version 0.1.0.
|
|
458
1523
|
LITERT_LM_C_API_EXPORT
|
|
459
1524
|
LiteRtLmJsonResponse* litert_lm_conversation_send_message(
|
|
460
1525
|
LiteRtLmConversation* conversation, const char* message_json,
|
|
461
|
-
const char* extra_context
|
|
1526
|
+
const char* extra_context,
|
|
1527
|
+
const LiteRtLmConversationOptionalArgs* optional_args);
|
|
462
1528
|
|
|
463
1529
|
// Destroys a LiteRT LM Json Response object.
|
|
464
1530
|
//
|
|
465
1531
|
// @param response The response to destroy.
|
|
1532
|
+
//
|
|
1533
|
+
// Added in version 0.1.0.
|
|
466
1534
|
LITERT_LM_C_API_EXPORT
|
|
467
1535
|
void litert_lm_json_response_delete(LiteRtLmJsonResponse* response);
|
|
468
1536
|
|
|
@@ -472,6 +1540,8 @@ void litert_lm_json_response_delete(LiteRtLmJsonResponse* response);
|
|
|
472
1540
|
// @return The response JSON string. The returned string is owned by the
|
|
473
1541
|
// `response` object and is valid only for its lifetime. Returns NULL if
|
|
474
1542
|
// response is NULL.
|
|
1543
|
+
//
|
|
1544
|
+
// Added in version 0.1.0.
|
|
475
1545
|
LITERT_LM_C_API_EXPORT
|
|
476
1546
|
const char* litert_lm_json_response_get_string(
|
|
477
1547
|
const LiteRtLmJsonResponse* response);
|
|
@@ -483,19 +1553,55 @@ const char* litert_lm_json_response_get_string(
|
|
|
483
1553
|
// @param conversation The conversation to use.
|
|
484
1554
|
// @param message_json A JSON string representing the message to send.
|
|
485
1555
|
// @param extra_context A JSON string representing the extra context to use.
|
|
1556
|
+
// @param optional_args A pointer to the optional arguments to use.
|
|
486
1557
|
// @param callback The callback function to receive response chunks.
|
|
487
1558
|
// @param callback_data A pointer to user data that will be passed to the
|
|
488
1559
|
// callback.
|
|
489
1560
|
// @return 0 on success, non-zero on failure to start the stream.
|
|
1561
|
+
//
|
|
1562
|
+
// Added in version 0.1.0.
|
|
490
1563
|
LITERT_LM_C_API_EXPORT
|
|
491
1564
|
int litert_lm_conversation_send_message_stream(
|
|
492
1565
|
LiteRtLmConversation* conversation, const char* message_json,
|
|
493
|
-
const char* extra_context,
|
|
494
|
-
|
|
1566
|
+
const char* extra_context,
|
|
1567
|
+
const LiteRtLmConversationOptionalArgs* optional_args,
|
|
1568
|
+
LiteRtLmStreamCallback callback, void* callback_data);
|
|
1569
|
+
|
|
1570
|
+
// Renders the message into a string according to the template.
|
|
1571
|
+
//
|
|
1572
|
+
// This function does not need to be called for actual message sending, as the
|
|
1573
|
+
// `litert_lm_conversation_send_message` and
|
|
1574
|
+
// `litert_lm_conversation_send_message_stream` functions will handle rendering
|
|
1575
|
+
// internally.
|
|
1576
|
+
//
|
|
1577
|
+
// @param conversation The conversation instance.
|
|
1578
|
+
// @param message_json A JSON string representing the message to render.
|
|
1579
|
+
// @return A pointer to the rendered string, or NULL on failure. The returned
|
|
1580
|
+
// string is owned by the `conversation` object and is valid until the next
|
|
1581
|
+
// call to this function or until the conversation is deleted.
|
|
1582
|
+
//
|
|
1583
|
+
// Added in version 0.1.0.
|
|
1584
|
+
LITERT_LM_C_API_EXPORT
|
|
1585
|
+
const char* litert_lm_conversation_render_message_to_string(
|
|
1586
|
+
LiteRtLmConversation* conversation, const char* message_json);
|
|
1587
|
+
|
|
1588
|
+
// Renders the preface into a string according to the template.
|
|
1589
|
+
//
|
|
1590
|
+
// @param conversation The conversation instance.
|
|
1591
|
+
// @return A pointer to the rendered string, or NULL on failure. The returned
|
|
1592
|
+
// string is owned by the `conversation` object and is valid until the next
|
|
1593
|
+
// call to this function or until the conversation is deleted.
|
|
1594
|
+
//
|
|
1595
|
+
// Added in version 0.1.0.
|
|
1596
|
+
LITERT_LM_C_API_EXPORT
|
|
1597
|
+
const char* litert_lm_conversation_render_preface_to_string(
|
|
1598
|
+
LiteRtLmConversation* conversation);
|
|
495
1599
|
|
|
496
1600
|
// Cancels the ongoing inference process, for asynchronous inference.
|
|
497
1601
|
//
|
|
498
1602
|
// @param conversation The conversation to cancel the inference for.
|
|
1603
|
+
//
|
|
1604
|
+
// Added in version 0.1.0.
|
|
499
1605
|
LITERT_LM_C_API_EXPORT
|
|
500
1606
|
void litert_lm_conversation_cancel_process(LiteRtLmConversation* conversation);
|
|
501
1607
|
|
|
@@ -505,10 +1611,192 @@ void litert_lm_conversation_cancel_process(LiteRtLmConversation* conversation);
|
|
|
505
1611
|
//
|
|
506
1612
|
// @param conversation The conversation to get the benchmark info from.
|
|
507
1613
|
// @return A pointer to the benchmark info, or NULL on failure.
|
|
1614
|
+
//
|
|
1615
|
+
// Added in version 0.1.0.
|
|
508
1616
|
LITERT_LM_C_API_EXPORT
|
|
509
1617
|
LiteRtLmBenchmarkInfo* litert_lm_conversation_get_benchmark_info(
|
|
510
1618
|
LiteRtLmConversation* conversation);
|
|
511
1619
|
|
|
1620
|
+
// Gets the number of tokens in the conversation KV Cache (prefill + decode).
|
|
1621
|
+
// Returns the number of tokens, or a negative value on failure.
|
|
1622
|
+
//
|
|
1623
|
+
// Added in version 0.1.0.
|
|
1624
|
+
LITERT_LM_C_API_EXPORT
|
|
1625
|
+
int litert_lm_conversation_get_token_count(LiteRtLmConversation* conversation);
|
|
1626
|
+
|
|
1627
|
+
// Tokenizes text using the engine's tokenizer.
|
|
1628
|
+
//
|
|
1629
|
+
// @param engine The engine instance.
|
|
1630
|
+
// @param text The UTF-8 string to tokenize.
|
|
1631
|
+
// @return A pointer to the tokenize result, or NULL on failure.
|
|
1632
|
+
// The caller is responsible for deleting the result using
|
|
1633
|
+
// `litert_lm_tokenize_result_delete`.
|
|
1634
|
+
//
|
|
1635
|
+
// Added in version 0.1.0.
|
|
1636
|
+
LITERT_LM_C_API_EXPORT
|
|
1637
|
+
LiteRtLmTokenizeResult* litert_lm_engine_tokenize(LiteRtLmEngine* engine,
|
|
1638
|
+
const char* text);
|
|
1639
|
+
|
|
1640
|
+
// Destroys a LiteRT LM Tokenize Result.
|
|
1641
|
+
//
|
|
1642
|
+
// @param result The tokenize result to destroy.
|
|
1643
|
+
//
|
|
1644
|
+
// Added in version 0.1.0.
|
|
1645
|
+
LITERT_LM_C_API_EXPORT
|
|
1646
|
+
void litert_lm_tokenize_result_delete(LiteRtLmTokenizeResult* result);
|
|
1647
|
+
|
|
1648
|
+
// Returns the token ids from a tokenize result.
|
|
1649
|
+
//
|
|
1650
|
+
// @param result The tokenize result.
|
|
1651
|
+
// @return A pointer to the internal array of token ids. The returned pointer
|
|
1652
|
+
// is valid only for the lifetime of the `result` object.
|
|
1653
|
+
//
|
|
1654
|
+
// Added in version 0.1.0.
|
|
1655
|
+
LITERT_LM_C_API_EXPORT
|
|
1656
|
+
const int* litert_lm_tokenize_result_get_tokens(
|
|
1657
|
+
const LiteRtLmTokenizeResult* result);
|
|
1658
|
+
|
|
1659
|
+
// Returns the number of token ids from a tokenize result.
|
|
1660
|
+
//
|
|
1661
|
+
// @param result The tokenize result.
|
|
1662
|
+
// @return The number of token ids.
|
|
1663
|
+
//
|
|
1664
|
+
// Added in version 0.1.0.
|
|
1665
|
+
LITERT_LM_C_API_EXPORT
|
|
1666
|
+
size_t litert_lm_tokenize_result_get_num_tokens(
|
|
1667
|
+
const LiteRtLmTokenizeResult* result);
|
|
1668
|
+
|
|
1669
|
+
// Detokenizes token ids using the engine's tokenizer.
|
|
1670
|
+
//
|
|
1671
|
+
// @param engine The engine instance.
|
|
1672
|
+
// @param tokens An array of token ids to detokenize.
|
|
1673
|
+
// @param num_tokens The number of token ids in the array.
|
|
1674
|
+
// @return A pointer to the detokenize result, or NULL on failure.
|
|
1675
|
+
// The caller is responsible for deleting the result using
|
|
1676
|
+
// `litert_lm_detokenize_result_delete`.
|
|
1677
|
+
//
|
|
1678
|
+
// Added in version 0.1.0.
|
|
1679
|
+
LITERT_LM_C_API_EXPORT
|
|
1680
|
+
LiteRtLmDetokenizeResult* litert_lm_engine_detokenize(LiteRtLmEngine* engine,
|
|
1681
|
+
const int* tokens,
|
|
1682
|
+
size_t num_tokens);
|
|
1683
|
+
|
|
1684
|
+
// Destroys a LiteRT LM Detokenize Result.
|
|
1685
|
+
//
|
|
1686
|
+
// @param result The detokenize result to destroy.
|
|
1687
|
+
//
|
|
1688
|
+
// Added in version 0.1.0.
|
|
1689
|
+
LITERT_LM_C_API_EXPORT
|
|
1690
|
+
void litert_lm_detokenize_result_delete(LiteRtLmDetokenizeResult* result);
|
|
1691
|
+
|
|
1692
|
+
// Returns the string from a detokenize result.
|
|
1693
|
+
//
|
|
1694
|
+
// @param result The detokenize result.
|
|
1695
|
+
// @return The detokenized UTF-8 string. The returned string is owned by the
|
|
1696
|
+
// `result` object and is valid only for its lifetime.
|
|
1697
|
+
//
|
|
1698
|
+
// Added in version 0.1.0.
|
|
1699
|
+
LITERT_LM_C_API_EXPORT
|
|
1700
|
+
const char* litert_lm_detokenize_result_get_string(
|
|
1701
|
+
const LiteRtLmDetokenizeResult* result);
|
|
1702
|
+
|
|
1703
|
+
// Destroys a LiteRT LM Token Union.
|
|
1704
|
+
//
|
|
1705
|
+
// @param token_union The token union to destroy.
|
|
1706
|
+
//
|
|
1707
|
+
// Added in version 0.1.0.
|
|
1708
|
+
LITERT_LM_C_API_EXPORT
|
|
1709
|
+
void litert_lm_token_union_delete(LiteRtLmTokenUnion* token_union);
|
|
1710
|
+
|
|
1711
|
+
// Returns the type of the token union.
|
|
1712
|
+
//
|
|
1713
|
+
// @param token_union The token union.
|
|
1714
|
+
// @return The type of the token union.
|
|
1715
|
+
//
|
|
1716
|
+
// Added in version 0.1.0.
|
|
1717
|
+
LITERT_LM_C_API_EXPORT
|
|
1718
|
+
LiteRtLmTokenUnionType litert_lm_token_union_get_type(
|
|
1719
|
+
const LiteRtLmTokenUnion* token_union);
|
|
1720
|
+
|
|
1721
|
+
// Returns the string value from a token union.
|
|
1722
|
+
//
|
|
1723
|
+
// @param token_union The token union.
|
|
1724
|
+
// @return The string value, or NULL if the type is not
|
|
1725
|
+
// kLiteRtLmTokenUnionTypeString. The returned string is owned by the
|
|
1726
|
+
// `token_union` object and is valid only for its lifetime.
|
|
1727
|
+
//
|
|
1728
|
+
// Added in version 0.1.0.
|
|
1729
|
+
LITERT_LM_C_API_EXPORT
|
|
1730
|
+
const char* litert_lm_token_union_get_string(
|
|
1731
|
+
const LiteRtLmTokenUnion* token_union);
|
|
1732
|
+
|
|
1733
|
+
// Returns the token ids from a token union.
|
|
1734
|
+
//
|
|
1735
|
+
// @param token_union The token union.
|
|
1736
|
+
// @param out_tokens A pointer to receive the internal array of token ids.
|
|
1737
|
+
// The received pointer is valid only for the lifetime of the `token_union`
|
|
1738
|
+
// object.
|
|
1739
|
+
// @param out_num_tokens A pointer to receive the number of token ids.
|
|
1740
|
+
// @return 0 on success, non-zero if the type is not kLiteRtLmTokenUnionTypeIds.
|
|
1741
|
+
//
|
|
1742
|
+
// Added in version 0.1.0.
|
|
1743
|
+
LITERT_LM_C_API_EXPORT
|
|
1744
|
+
int litert_lm_token_union_get_ids(const LiteRtLmTokenUnion* token_union,
|
|
1745
|
+
const int** out_tokens,
|
|
1746
|
+
size_t* out_num_tokens);
|
|
1747
|
+
|
|
1748
|
+
// Destroys a LiteRT LM Token Unions object.
|
|
1749
|
+
//
|
|
1750
|
+
// @param tokens The token unions object to destroy.
|
|
1751
|
+
//
|
|
1752
|
+
// Added in version 0.1.0.
|
|
1753
|
+
LITERT_LM_C_API_EXPORT
|
|
1754
|
+
void litert_lm_token_unions_delete(LiteRtLmTokenUnions* tokens);
|
|
1755
|
+
|
|
1756
|
+
// Returns the number of token unions in the collection.
|
|
1757
|
+
//
|
|
1758
|
+
// @param tokens The token unions object.
|
|
1759
|
+
// @return The number of token unions.
|
|
1760
|
+
//
|
|
1761
|
+
// Added in version 0.1.0.
|
|
1762
|
+
LITERT_LM_C_API_EXPORT
|
|
1763
|
+
size_t litert_lm_token_unions_get_num_tokens(const LiteRtLmTokenUnions* tokens);
|
|
1764
|
+
|
|
1765
|
+
// Returns the token union at a given index from a collection.
|
|
1766
|
+
//
|
|
1767
|
+
// @param tokens The token unions collection.
|
|
1768
|
+
// @param index The index of the token union.
|
|
1769
|
+
// @return A pointer to the token union at the given index, or NULL if the index
|
|
1770
|
+
// is out of bounds. The caller is responsible for deleting the result using
|
|
1771
|
+
// `litert_lm_token_union_delete`.
|
|
1772
|
+
//
|
|
1773
|
+
// Added in version 0.1.0.
|
|
1774
|
+
LITERT_LM_C_API_EXPORT
|
|
1775
|
+
LiteRtLmTokenUnion* litert_lm_token_unions_get_token_at(
|
|
1776
|
+
const LiteRtLmTokenUnions* tokens, size_t index);
|
|
1777
|
+
|
|
1778
|
+
// Returns the configured start token (BOS), if any.
|
|
1779
|
+
//
|
|
1780
|
+
// @param engine The engine instance.
|
|
1781
|
+
// @return A pointer to the start token, or NULL if none configured. The caller
|
|
1782
|
+
// is responsible for deleting the result using
|
|
1783
|
+
// `litert_lm_token_union_delete`.
|
|
1784
|
+
//
|
|
1785
|
+
// Added in version 0.1.0.
|
|
1786
|
+
LITERT_LM_C_API_EXPORT
|
|
1787
|
+
LiteRtLmTokenUnion* litert_lm_engine_get_start_token(LiteRtLmEngine* engine);
|
|
1788
|
+
|
|
1789
|
+
// Returns the configured stop tokens (EOS).
|
|
1790
|
+
//
|
|
1791
|
+
// @param engine The engine instance.
|
|
1792
|
+
// @return A pointer to the stop tokens collection, or NULL if none configured.
|
|
1793
|
+
// The caller is responsible for deleting the result using
|
|
1794
|
+
// `litert_lm_token_unions_delete`.
|
|
1795
|
+
//
|
|
1796
|
+
// Added in version 0.1.0.
|
|
1797
|
+
LITERT_LM_C_API_EXPORT
|
|
1798
|
+
LiteRtLmTokenUnions* litert_lm_engine_get_stop_tokens(LiteRtLmEngine* engine);
|
|
1799
|
+
|
|
512
1800
|
#ifdef __cplusplus
|
|
513
1801
|
} // extern "C"
|
|
514
1802
|
#endif
|