|
1
|
// ── Message role ───────────────────────────────────────────────────────────── |
|
2
|
|
|
3
|
/** Role of a message in a chat conversation. */ |
|
4
|
export type ChatRole = "system" | "user" | "assistant"; |
|
5
|
|
|
6
|
// ── Chat message ───────────────────────────────────────────────────────────── |
|
7
|
|
|
8
|
/** A single message in a conversation. */ |
|
9
|
export interface ChatMessage { |
|
10
|
role: ChatRole; |
|
11
|
content: string; |
|
12
|
} |
|
13
|
|
|
14
|
// ── Sampling configuration ─────────────────────────────────────────────────── |
|
15
|
|
|
16
|
/** |
|
17
|
* Sampling parameters for text generation. |
|
18
|
* All fields are optional — `undefined` means "use the engine default". |
|
19
|
*/ |
|
20
|
export interface SamplingConfig { |
|
21
|
/** Sampling temperature (higher = more random). Typical range: 0.0–2.0. */ |
|
22
|
temperature?: number; |
|
23
|
/** Nucleus (top-p) sampling threshold. Typical value: 0.9–0.95. */ |
|
24
|
topP?: number; |
|
25
|
/** Top-k sampling limit. */ |
|
26
|
topK?: number; |
|
27
|
/** Min-p sampling threshold. */ |
|
28
|
minP?: number; |
|
29
|
/** Maximum number of tokens to generate. */ |
|
30
|
maxTokens?: number; |
|
31
|
/** Frequency penalty (penalise tokens proportional to occurrence count). */ |
|
32
|
frequencyPenalty?: number; |
|
33
|
/** Presence penalty (penalise tokens that appeared at all). */ |
|
34
|
presencePenalty?: number; |
|
35
|
} |
|
36
|
|
|
37
|
// ── Model configuration ────────────────────────────────────────────────────── |
|
38
|
|
|
39
|
/** Configuration for loading a GGUF model. */ |
|
40
|
export interface GgufModelConfig { |
|
41
|
/** HuggingFace model repository ID. */ |
|
42
|
modelId: string; |
|
43
|
/** GGUF filename(s) within the repository. */ |
|
44
|
files: string[]; |
|
45
|
/** Optional: explicit tokenizer model ID (required on Android). */ |
|
46
|
tokModelId?: string; |
|
47
|
/** Human-friendly display name. */ |
|
48
|
displayName: string; |
|
49
|
/** Approximate memory footprint description. */ |
|
50
|
approxMemory: string; |
|
51
|
/** Optional Jinja chat template override. */ |
|
52
|
chatTemplate?: string; |
|
53
|
} |
|
54
|
|
|
55
|
/** Configuration for loading a UQFF model. */ |
|
56
|
export interface UqffModelConfig { |
|
57
|
/** HuggingFace base model repository ID or local model directory. */ |
|
58
|
modelId: string; |
|
59
|
/** UQFF shard filename(s), first shard, or shorthand such as "q4k" / "4". */ |
|
60
|
files: string[]; |
|
61
|
/** Human-friendly display name. */ |
|
62
|
displayName: string; |
|
63
|
/** Approximate memory footprint description. */ |
|
64
|
approxMemory: string; |
|
65
|
/** Optional Jinja chat template override. */ |
|
66
|
chatTemplate?: string; |
|
67
|
} |
|
68
|
|
|
69
|
// ── Inference result ───────────────────────────────────────────────────────── |
|
70
|
|
|
71
|
/** Result of a completed inference request. */ |
|
72
|
export interface InferenceResult { |
|
73
|
/** The generated text. */ |
|
74
|
text: string; |
|
75
|
/** Wall-clock inference duration in seconds. */ |
|
76
|
durationSecs: number; |
|
77
|
/** Human-readable duration string, e.g. "1.23s". */ |
|
78
|
durationDisplay: string; |
|
79
|
/** Finish reason, if available. */ |
|
80
|
finishReason?: string; |
|
81
|
/** Tool calls requested by the model, if any. */ |
|
82
|
toolCalls: ToolCallInfo[]; |
|
83
|
} |
|
84
|
|
|
85
|
/** Metadata about a tool call requested by the model. */ |
|
86
|
export interface ToolCallInfo { |
|
87
|
/** Unique identifier for this tool call. */ |
|
88
|
id: string; |
|
89
|
/** Name of the function to call. */ |
|
90
|
functionName: string; |
|
91
|
/** JSON-encoded arguments for the function. */ |
|
92
|
arguments: string; |
|
93
|
} |
|
94
|
|
|
95
|
// ── Streaming ──────────────────────────────────────────────────────────────── |
|
96
|
|
|
97
|
/** A single streaming token chunk. */ |
|
98
|
export interface StreamChunk { |
|
99
|
/** The token text delta. */ |
|
100
|
delta: string; |
|
101
|
/** Whether this is the final chunk. */ |
|
102
|
done: boolean; |
|
103
|
/** Finish reason (only present on the final chunk). */ |
|
104
|
finishReason?: string; |
|
105
|
} |
|
106
|
|
|
107
|
// ── Engine status ──────────────────────────────────────────────────────────── |
|
108
|
|
|
109
|
/** Current status of the inference engine. */ |
|
110
|
export type EngineStatus = |
|
111
|
| "Unloaded" |
|
112
|
| "Loading" |
|
113
|
| "Ready" |
|
114
|
| "Generating" |
|
115
|
| "Error"; |
|
116
|
|
|
117
|
/** Snapshot of the engine's current state. */ |
|
118
|
export interface EngineInfo { |
|
119
|
/** Current engine status. */ |
|
120
|
status: EngineStatus; |
|
121
|
/** Name of the loaded model, if any. */ |
|
122
|
modelName?: string; |
|
123
|
/** Approximate memory footprint of the loaded model. */ |
|
124
|
approxMemory?: string; |
|
125
|
/** Number of messages in the conversation history. */ |
|
126
|
historyLength: number; |
|
127
|
} |
|
128
|
|
|
129
|
// ── Errors ─────────────────────────────────────────────────────────────────── |
|
130
|
|
|
131
|
/** Error thrown by the Onde inference engine. */ |
|
132
|
export class OndeError extends Error { |
|
133
|
constructor(message: string) { |
|
134
|
super(message); |
|
135
|
this.name = "OndeError"; |
|
136
|
} |
|
137
|
} |