|
1
|
// This file is automatically generated, so please do not edit it. |
|
2
|
// @generated by `flutter_rust_bridge`@ 2.12.0. |
|
3
|
|
|
4
|
// ignore_for_file: type=lint, unused_import, unnecessary_import |
|
5
|
|
|
6
|
// ignore_for_file: invalid_use_of_internal_member |
|
7
|
|
|
8
|
import 'frb_generated.dart'; |
|
9
|
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; |
|
10
|
import 'package:freezed_annotation/freezed_annotation.dart' hide protected; |
|
11
|
part 'api.freezed.dart'; |
|
12
|
|
|
13
|
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_receiver_is_total_eq`, `assert_receiver_is_total_eq`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from`, `from` |
|
14
|
|
|
15
|
/// Return the platform-appropriate default `GgufModelConfig`. |
|
16
|
/// |
|
17
|
/// Selects the 1.5B model on iOS / tvOS / Android and the 3B model on |
|
18
|
/// macOS / Windows / Linux. |
|
19
|
GgufModelConfig defaultModelConfig() => |
|
20
|
RustLib.instance.api.crateApiDefaultModelConfig(); |
|
21
|
|
|
22
|
/// `GgufModelConfig` for Qwen 2.5 1.5B Instruct Q4_K_M (~941 MB). |
|
23
|
GgufModelConfig qwen2515BConfig() => |
|
24
|
RustLib.instance.api.crateApiQwen2515BConfig(); |
|
25
|
|
|
26
|
/// `GgufModelConfig` for Qwen 2.5 3B Instruct Q4_K_M (~1.93 GB). |
|
27
|
GgufModelConfig qwen253BConfig() => |
|
28
|
RustLib.instance.api.crateApiQwen253BConfig(); |
|
29
|
|
|
30
|
/// `GgufModelConfig` for Qwen 2.5 Coder 1.5B Instruct Q4_K_M (~941 MB). |
|
31
|
GgufModelConfig qwen25Coder15BConfig() => |
|
32
|
RustLib.instance.api.crateApiQwen25Coder15BConfig(); |
|
33
|
|
|
34
|
/// `GgufModelConfig` for Qwen 2.5 Coder 3B Instruct Q4_K_M (~1.93 GB). |
|
35
|
GgufModelConfig qwen25Coder3BConfig() => |
|
36
|
RustLib.instance.api.crateApiQwen25Coder3BConfig(); |
|
37
|
|
|
38
|
/// Default sampling config: `temperature=0.7`, `top_p=0.95`, `max_tokens=512`. |
|
39
|
SamplingConfig defaultSamplingConfig() => |
|
40
|
RustLib.instance.api.crateApiDefaultSamplingConfig(); |
|
41
|
|
|
42
|
/// Deterministic sampling config: `temperature=0.0`, greedy, `max_tokens=512`. |
|
43
|
SamplingConfig deterministicSamplingConfig() => |
|
44
|
RustLib.instance.api.crateApiDeterministicSamplingConfig(); |
|
45
|
|
|
46
|
/// Mobile sampling config: `temperature=0.7`, `top_p=0.95`, `max_tokens=128`. |
|
47
|
SamplingConfig mobileSamplingConfig() => |
|
48
|
RustLib.instance.api.crateApiMobileSamplingConfig(); |
|
49
|
|
|
50
|
/// Seed the HuggingFace cache environment for sandboxed platforms. |
|
51
|
/// |
|
52
|
/// On iOS (and Android), the default `~/.cache/huggingface/hub` path is outside |
|
53
|
/// the app sandbox and writes fail with `Operation not permitted (os error 1)`. |
|
54
|
/// |
|
55
|
/// Call this **once** at startup — before any `load_gguf_model` or |
|
56
|
/// `download_model` — with the app's writable data directory. |
|
57
|
/// |
|
58
|
/// # Dart usage |
|
59
|
/// |
|
60
|
/// ```dart |
|
61
|
/// import 'package:path_provider/path_provider.dart'; |
|
62
|
/// |
|
63
|
/// final dir = await getApplicationSupportDirectory(); |
|
64
|
/// configureCacheDir(appDataDir: dir.path); |
|
65
|
/// ``` |
|
66
|
/// |
|
67
|
/// Internally this: |
|
68
|
/// 1. Creates `<app_data_dir>/huggingface/hub/` if it doesn't exist. |
|
69
|
/// 2. Sets the `HF_HOME` and `HF_HUB_CACHE` environment variables. |
|
70
|
/// 3. Seeds `mistralrs_core::GLOBAL_HF_CACHE` so the model loader never |
|
71
|
/// falls back to `Cache::default()`. |
|
72
|
void configureCacheDir({required String appDataDir}) => |
|
73
|
RustLib.instance.api.crateApiConfigureCacheDir(appDataDir: appDataDir); |
|
74
|
|
|
75
|
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<OndeChatEngine>> |
|
76
|
abstract class OndeChatEngine implements RustOpaqueInterface { |
|
77
|
/// Clear the conversation history while keeping the model loaded. |
|
78
|
/// |
|
79
|
/// Returns the number of turns that were removed. |
|
80
|
Future<BigInt> clearHistory(); |
|
81
|
|
|
82
|
/// Clear the current system prompt. |
|
83
|
Future<void> clearSystemPrompt(); |
|
84
|
|
|
85
|
/// One-shot generation from an explicit message list. |
|
86
|
/// |
|
87
|
/// Does **not** modify the conversation history. |
|
88
|
Future<InferenceResult> generate({ |
|
89
|
required List<ChatMessage> messages, |
|
90
|
SamplingConfig? sampling, |
|
91
|
}); |
|
92
|
|
|
93
|
/// Returns a clone of the full conversation history. |
|
94
|
Future<List<ChatMessage>> history(); |
|
95
|
|
|
96
|
/// Returns a point-in-time snapshot of the engine's state. |
|
97
|
Future<EngineInfo> info(); |
|
98
|
|
|
99
|
/// Returns `true` if a model is currently loaded and ready. |
|
100
|
Future<bool> isLoaded(); |
|
101
|
|
|
102
|
/// Load the model assigned to this app via the Onde dashboard. |
|
103
|
/// |
|
104
|
/// The [appId] and [appSecret] identify your app on |
|
105
|
/// [ondeinference.com](https://ondeinference.com). If no model is |
|
106
|
/// assigned, the platform default is loaded instead. |
|
107
|
/// |
|
108
|
/// Returns the wall-clock seconds taken to load the model. |
|
109
|
Future<double> loadAssignedModel({ |
|
110
|
required String appId, |
|
111
|
required String appSecret, |
|
112
|
String? systemPrompt, |
|
113
|
SamplingConfig? sampling, |
|
114
|
}); |
|
115
|
|
|
116
|
/// Load a GGUF model into the engine. |
|
117
|
/// |
|
118
|
/// Returns the load duration in seconds on success. |
|
119
|
Future<double> loadGgufModel({ |
|
120
|
required GgufModelConfig config, |
|
121
|
String? systemPrompt, |
|
122
|
SamplingConfig? sampling, |
|
123
|
}); |
|
124
|
|
|
125
|
/// Create a new engine with no model loaded. |
|
126
|
factory OndeChatEngine() => RustLib.instance.api.crateApiOndeChatEngineNew(); |
|
127
|
|
|
128
|
/// Append a message to history without running inference. |
|
129
|
/// |
|
130
|
/// Useful for restoring a saved conversation or injecting context. |
|
131
|
Future<void> pushHistory({required ChatMessage message}); |
|
132
|
|
|
133
|
/// Send a user message and receive a complete assistant reply. |
|
134
|
/// |
|
135
|
/// Both the user message and assistant reply are appended to the |
|
136
|
/// conversation history on success. |
|
137
|
Future<InferenceResult> sendMessage({required String message}); |
|
138
|
|
|
139
|
/// Replace the sampling configuration used for all subsequent inference. |
|
140
|
Future<void> setSampling({required SamplingConfig sampling}); |
|
141
|
|
|
142
|
/// Set or replace the system prompt. |
|
143
|
/// |
|
144
|
/// The prompt is prepended to every inference request and is **not** |
|
145
|
/// stored in the conversation history. |
|
146
|
Future<void> setSystemPrompt({required String prompt}); |
|
147
|
|
|
148
|
/// Stream a reply token-by-token. |
|
149
|
/// |
|
150
|
/// Each [`StreamChunk`] carries a `delta` string. The final chunk has |
|
151
|
/// `done == true`. The `sink` is closed automatically when the stream |
|
152
|
/// ends or if the receiver is dropped. |
|
153
|
Stream<StreamChunk> streamMessage({required String message}); |
|
154
|
|
|
155
|
/// Unload the current model and release its memory. |
|
156
|
/// |
|
157
|
/// Returns the display name of the model that was unloaded, or `None` |
|
158
|
/// if no model was loaded. |
|
159
|
Future<String?> unloadModel(); |
|
160
|
} |
|
161
|
|
|
162
|
/// A single message in a conversation. |
|
163
|
class ChatMessage { |
|
164
|
final ChatRole role; |
|
165
|
final String content; |
|
166
|
|
|
167
|
const ChatMessage({required this.role, required this.content}); |
|
168
|
|
|
169
|
@override |
|
170
|
int get hashCode => role.hashCode ^ content.hashCode; |
|
171
|
|
|
172
|
@override |
|
173
|
bool operator ==(Object other) => |
|
174
|
identical(this, other) || |
|
175
|
other is ChatMessage && |
|
176
|
runtimeType == other.runtimeType && |
|
177
|
role == other.role && |
|
178
|
content == other.content; |
|
179
|
} |
|
180
|
|
|
181
|
/// Role of a participant in a chat conversation. |
|
182
|
enum ChatRole { system, user, assistant } |
|
183
|
|
|
184
|
/// A point-in-time snapshot of the engine's state. |
|
185
|
class EngineInfo { |
|
186
|
final EngineStatus status; |
|
187
|
|
|
188
|
/// Display name of the currently loaded model, if any. |
|
189
|
final String? modelName; |
|
190
|
|
|
191
|
/// Approximate memory footprint of the loaded model, if any. |
|
192
|
final String? approxMemory; |
|
193
|
|
|
194
|
/// Number of conversation turns in the current history. |
|
195
|
final BigInt historyLength; |
|
196
|
|
|
197
|
const EngineInfo({ |
|
198
|
required this.status, |
|
199
|
this.modelName, |
|
200
|
this.approxMemory, |
|
201
|
required this.historyLength, |
|
202
|
}); |
|
203
|
|
|
204
|
@override |
|
205
|
int get hashCode => |
|
206
|
status.hashCode ^ |
|
207
|
modelName.hashCode ^ |
|
208
|
approxMemory.hashCode ^ |
|
209
|
historyLength.hashCode; |
|
210
|
|
|
211
|
@override |
|
212
|
bool operator ==(Object other) => |
|
213
|
identical(this, other) || |
|
214
|
other is EngineInfo && |
|
215
|
runtimeType == other.runtimeType && |
|
216
|
status == other.status && |
|
217
|
modelName == other.modelName && |
|
218
|
approxMemory == other.approxMemory && |
|
219
|
historyLength == other.historyLength; |
|
220
|
} |
|
221
|
|
|
222
|
/// Lifecycle status of the inference engine. |
|
223
|
enum EngineStatus { unloaded, loading, ready, generating, error } |
|
224
|
|
|
225
|
/// Configuration for loading a pre-quantised GGUF model. |
|
226
|
class GgufModelConfig { |
|
227
|
/// HuggingFace repository ID, e.g. `"bartowski/Qwen2.5-1.5B-Instruct-GGUF"`. |
|
228
|
final String modelId; |
|
229
|
|
|
230
|
/// GGUF filename(s) within the repository. |
|
231
|
final List<String> files; |
|
232
|
|
|
233
|
/// Optional explicit tokenizer model ID (required on Android). |
|
234
|
final String? tokModelId; |
|
235
|
|
|
236
|
/// Human-friendly display name, e.g. `"Qwen 2.5 1.5B"`. |
|
237
|
final String displayName; |
|
238
|
|
|
239
|
/// Approximate memory footprint, e.g. `"~941 MB (GGUF Q4_K_M)"`. |
|
240
|
final String approxMemory; |
|
241
|
|
|
242
|
/// Optional chat template override (Jinja format). |
|
243
|
final String? chatTemplate; |
|
244
|
|
|
245
|
const GgufModelConfig({ |
|
246
|
required this.modelId, |
|
247
|
required this.files, |
|
248
|
this.tokModelId, |
|
249
|
required this.displayName, |
|
250
|
required this.approxMemory, |
|
251
|
this.chatTemplate, |
|
252
|
}); |
|
253
|
|
|
254
|
@override |
|
255
|
int get hashCode => |
|
256
|
modelId.hashCode ^ |
|
257
|
files.hashCode ^ |
|
258
|
tokModelId.hashCode ^ |
|
259
|
displayName.hashCode ^ |
|
260
|
approxMemory.hashCode ^ |
|
261
|
chatTemplate.hashCode; |
|
262
|
|
|
263
|
@override |
|
264
|
bool operator ==(Object other) => |
|
265
|
identical(this, other) || |
|
266
|
other is GgufModelConfig && |
|
267
|
runtimeType == other.runtimeType && |
|
268
|
modelId == other.modelId && |
|
269
|
files == other.files && |
|
270
|
tokModelId == other.tokModelId && |
|
271
|
displayName == other.displayName && |
|
272
|
approxMemory == other.approxMemory && |
|
273
|
chatTemplate == other.chatTemplate; |
|
274
|
} |
|
275
|
|
|
276
|
/// The result of a completed inference request. |
|
277
|
class InferenceResult { |
|
278
|
/// The generated assistant reply text. |
|
279
|
final String text; |
|
280
|
|
|
281
|
/// Wall-clock inference duration in seconds. |
|
282
|
final double durationSecs; |
|
283
|
|
|
284
|
/// Human-readable duration string, e.g. `"4.5s"` or `"2m 3.1s"`. |
|
285
|
final String durationDisplay; |
|
286
|
|
|
287
|
/// Finish reason reported by the model, e.g. `"stop"` or `"length"`. |
|
288
|
final String finishReason; |
|
289
|
|
|
290
|
/// Tool calls requested by the model (empty if none). |
|
291
|
final List<ToolCallInfo> toolCalls; |
|
292
|
|
|
293
|
const InferenceResult({ |
|
294
|
required this.text, |
|
295
|
required this.durationSecs, |
|
296
|
required this.durationDisplay, |
|
297
|
required this.finishReason, |
|
298
|
required this.toolCalls, |
|
299
|
}); |
|
300
|
|
|
301
|
@override |
|
302
|
int get hashCode => |
|
303
|
text.hashCode ^ |
|
304
|
durationSecs.hashCode ^ |
|
305
|
durationDisplay.hashCode ^ |
|
306
|
finishReason.hashCode ^ |
|
307
|
toolCalls.hashCode; |
|
308
|
|
|
309
|
@override |
|
310
|
bool operator ==(Object other) => |
|
311
|
identical(this, other) || |
|
312
|
other is InferenceResult && |
|
313
|
runtimeType == other.runtimeType && |
|
314
|
text == other.text && |
|
315
|
durationSecs == other.durationSecs && |
|
316
|
durationDisplay == other.durationDisplay && |
|
317
|
finishReason == other.finishReason && |
|
318
|
toolCalls == other.toolCalls; |
|
319
|
} |
|
320
|
|
|
321
|
@freezed |
|
322
|
sealed class OndeError with _$OndeError implements FrbException { |
|
323
|
const OndeError._(); |
|
324
|
|
|
325
|
const factory OndeError.noModelLoaded() = OndeError_NoModelLoaded; |
|
326
|
const factory OndeError.alreadyLoaded({required String modelName}) = |
|
327
|
OndeError_AlreadyLoaded; |
|
328
|
const factory OndeError.modelBuild({required String reason}) = |
|
329
|
OndeError_ModelBuild; |
|
330
|
const factory OndeError.inference({required String reason}) = |
|
331
|
OndeError_Inference; |
|
332
|
const factory OndeError.cancelled() = OndeError_Cancelled; |
|
333
|
const factory OndeError.other({required String reason}) = OndeError_Other; |
|
334
|
} |
|
335
|
|
|
336
|
/// Sampling parameters for text generation. All fields are optional — `None` |
|
337
|
/// means "use the engine default". |
|
338
|
class SamplingConfig { |
|
339
|
final double? temperature; |
|
340
|
final double? topP; |
|
341
|
final BigInt? topK; |
|
342
|
final double? minP; |
|
343
|
final BigInt? maxTokens; |
|
344
|
final double? frequencyPenalty; |
|
345
|
final double? presencePenalty; |
|
346
|
|
|
347
|
const SamplingConfig({ |
|
348
|
this.temperature, |
|
349
|
this.topP, |
|
350
|
this.topK, |
|
351
|
this.minP, |
|
352
|
this.maxTokens, |
|
353
|
this.frequencyPenalty, |
|
354
|
this.presencePenalty, |
|
355
|
}); |
|
356
|
|
|
357
|
@override |
|
358
|
int get hashCode => |
|
359
|
temperature.hashCode ^ |
|
360
|
topP.hashCode ^ |
|
361
|
topK.hashCode ^ |
|
362
|
minP.hashCode ^ |
|
363
|
maxTokens.hashCode ^ |
|
364
|
frequencyPenalty.hashCode ^ |
|
365
|
presencePenalty.hashCode; |
|
366
|
|
|
367
|
@override |
|
368
|
bool operator ==(Object other) => |
|
369
|
identical(this, other) || |
|
370
|
other is SamplingConfig && |
|
371
|
runtimeType == other.runtimeType && |
|
372
|
temperature == other.temperature && |
|
373
|
topP == other.topP && |
|
374
|
topK == other.topK && |
|
375
|
minP == other.minP && |
|
376
|
maxTokens == other.maxTokens && |
|
377
|
frequencyPenalty == other.frequencyPenalty && |
|
378
|
presencePenalty == other.presencePenalty; |
|
379
|
} |
|
380
|
|
|
381
|
/// A single streaming token chunk emitted during inference. |
|
382
|
class StreamChunk { |
|
383
|
/// The token text delta (may be empty on the final chunk). |
|
384
|
final String delta; |
|
385
|
|
|
386
|
/// `true` when this is the last chunk in the stream. |
|
387
|
final bool done; |
|
388
|
|
|
389
|
/// Finish reason (set only on the final chunk). |
|
390
|
final String? finishReason; |
|
391
|
|
|
392
|
const StreamChunk({ |
|
393
|
required this.delta, |
|
394
|
required this.done, |
|
395
|
this.finishReason, |
|
396
|
}); |
|
397
|
|
|
398
|
@override |
|
399
|
int get hashCode => delta.hashCode ^ done.hashCode ^ finishReason.hashCode; |
|
400
|
|
|
401
|
@override |
|
402
|
bool operator ==(Object other) => |
|
403
|
identical(this, other) || |
|
404
|
other is StreamChunk && |
|
405
|
runtimeType == other.runtimeType && |
|
406
|
delta == other.delta && |
|
407
|
done == other.done && |
|
408
|
finishReason == other.finishReason; |
|
409
|
} |
|
410
|
|
|
411
|
/// Metadata about a tool call requested by the model. |
|
412
|
class ToolCallInfo { |
|
413
|
/// Unique identifier for this tool call. |
|
414
|
final String id; |
|
415
|
|
|
416
|
/// Name of the function to call. |
|
417
|
final String functionName; |
|
418
|
|
|
419
|
/// JSON-encoded arguments for the function. |
|
420
|
final String arguments; |
|
421
|
|
|
422
|
const ToolCallInfo({ |
|
423
|
required this.id, |
|
424
|
required this.functionName, |
|
425
|
required this.arguments, |
|
426
|
}); |
|
427
|
|
|
428
|
@override |
|
429
|
int get hashCode => id.hashCode ^ functionName.hashCode ^ arguments.hashCode; |
|
430
|
|
|
431
|
@override |
|
432
|
bool operator ==(Object other) => |
|
433
|
identical(this, other) || |
|
434
|
other is ToolCallInfo && |
|
435
|
runtimeType == other.runtimeType && |
|
436
|
id == other.id && |
|
437
|
functionName == other.functionName && |
|
438
|
arguments == other.arguments; |
|
439
|
} |