@qvac/sdk 0.8.2 → 0.9.0
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/NOTICE +267 -63
- package/README.md +2 -0
- package/dist/client/api/diffusion.d.ts +32 -0
- package/dist/client/api/diffusion.js +103 -0
- package/dist/client/api/embed.d.ts +9 -3
- package/dist/client/api/embed.js +4 -1
- package/dist/client/api/finetune.d.ts +69 -0
- package/dist/client/api/finetune.js +139 -0
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.js +4 -0
- package/dist/client/api/rag.d.ts +1 -1
- package/dist/client/api/rag.js +1 -1
- package/dist/client/api/resume.d.ts +14 -0
- package/dist/client/api/resume.js +20 -0
- package/dist/client/api/suspend.d.ts +13 -0
- package/dist/client/api/suspend.js +19 -0
- package/dist/client/api/transcribe.d.ts +25 -17
- package/dist/client/api/transcribe.js +115 -35
- package/dist/client/rpc/bare-client.d.ts +5 -1
- package/dist/client/rpc/bare-client.js +70 -57
- package/dist/client/rpc/expo-rpc-client.d.ts +4 -0
- package/dist/client/rpc/expo-rpc-client.js +8 -0
- package/dist/client/rpc/node-rpc-client.d.ts +4 -0
- package/dist/client/rpc/node-rpc-client.js +8 -0
- package/dist/client/rpc/rpc-client.d.ts +13 -0
- package/dist/client/rpc/rpc-client.js +131 -1
- package/dist/examples/delegated-inference/composite.d.ts +2 -0
- package/dist/examples/delegated-inference/composite.js +99 -0
- package/dist/examples/diffusion-flux2-klein.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein.js +46 -0
- package/dist/examples/diffusion-simple.d.ts +2 -0
- package/dist/examples/diffusion-simple.js +17 -0
- package/dist/examples/diffusion-txt2img.d.ts +2 -0
- package/dist/examples/diffusion-txt2img.js +40 -0
- package/dist/examples/embed-p2p.js +2 -2
- package/dist/examples/finetune/llamacpp-finetune.d.ts +2 -0
- package/dist/examples/finetune/llamacpp-finetune.js +78 -0
- package/dist/examples/logging-streaming.js +1 -1
- package/dist/examples/mcp-websearch.js +2 -0
- package/dist/examples/ocr-fasttext.js +11 -0
- package/dist/examples/profiling/per-call.js +3 -3
- package/dist/examples/rag/rag-chromadb.js +2 -2
- package/dist/examples/rag/rag-hyperdb/pipeline.js +1 -1
- package/dist/examples/rag/rag-lancedb.js +2 -2
- package/dist/examples/rag/rag-sqlite.js +2 -2
- package/dist/examples/suspend-resume.d.ts +2 -0
- package/dist/examples/suspend-resume.js +52 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +3 -5
- package/dist/examples/transcription/parakeet-microphone-record.js +42 -33
- package/dist/examples/transcription/parakeet-sortformer.js +13 -3
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +5 -7
- package/dist/examples/transcription/whispercpp-filesystem-streaming.d.ts +2 -0
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +99 -0
- package/dist/examples/transcription/whispercpp-microphone-record.js +78 -299
- package/dist/examples/transcription/whispercpp-prompt.js +11 -0
- package/dist/examples/translation/translation-llm.js +2 -2
- package/dist/examples/tts/supertonic-multilingual.d.ts +2 -0
- package/dist/examples/tts/supertonic-multilingual.js +56 -0
- package/dist/examples/tts/supertonic.js +12 -7
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/logging/utils.js +1 -1
- package/dist/models/registry/models.d.ts +15176 -4264
- package/dist/models/registry/models.js +18657 -7404
- package/dist/models/update-models/codegen.js +2 -2
- package/dist/models/update-models/naming.js +26 -0
- package/dist/pear/pre.js +2 -0
- package/dist/polyfills/bare-globals.d.ts +2 -0
- package/dist/polyfills/bare-globals.js +4 -0
- package/dist/polyfills/bare-globals.noop.d.ts +2 -0
- package/dist/polyfills/bare-globals.noop.js +1 -0
- package/dist/profiling/exporters.js +16 -11
- package/dist/profiling/model-execution.d.ts +16 -0
- package/dist/profiling/model-execution.js +33 -0
- package/dist/schemas/common.d.ts +967 -198
- package/dist/schemas/common.js +16 -1
- package/dist/schemas/completion-stream.d.ts +14 -6
- package/dist/schemas/completion-stream.js +4 -3
- package/dist/schemas/download-asset.d.ts +7 -3
- package/dist/schemas/embed.d.ts +19 -0
- package/dist/schemas/embed.js +7 -0
- package/dist/schemas/engine-addon-map.js +4 -1
- package/dist/schemas/finetune.d.ts +620 -0
- package/dist/schemas/finetune.js +161 -0
- package/dist/schemas/get-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.js +1 -0
- package/dist/schemas/index.d.ts +5 -1
- package/dist/schemas/index.js +5 -1
- package/dist/schemas/llamacpp-config.d.ts +26 -6
- package/dist/schemas/llamacpp-config.js +12 -0
- package/dist/schemas/load-model.d.ts +4005 -1400
- package/dist/schemas/load-model.js +34 -1
- package/dist/schemas/model-src-utils.d.ts +10 -2
- package/dist/schemas/model-types.d.ts +19 -1
- package/dist/schemas/model-types.js +11 -0
- package/dist/schemas/ocr.d.ts +2 -0
- package/dist/schemas/plugin.d.ts +24 -3
- package/dist/schemas/plugin.js +14 -0
- package/dist/schemas/profiling.d.ts +4 -0
- package/dist/schemas/profiling.js +4 -0
- package/dist/schemas/registry.d.ts +18 -0
- package/dist/schemas/registry.js +2 -0
- package/dist/schemas/reload-config.d.ts +9 -1
- package/dist/schemas/resume.d.ts +10 -0
- package/dist/schemas/resume.js +7 -0
- package/dist/schemas/sdcpp-config.d.ts +327 -0
- package/dist/schemas/sdcpp-config.js +102 -0
- package/dist/schemas/sdk-config.d.ts +1225 -235
- package/dist/schemas/sdk-config.js +4 -0
- package/dist/schemas/sdk-errors-server.d.ts +2 -0
- package/dist/schemas/sdk-errors-server.js +12 -0
- package/dist/schemas/suspend.d.ts +10 -0
- package/dist/schemas/suspend.js +7 -0
- package/dist/schemas/text-to-speech.d.ts +187 -10
- package/dist/schemas/text-to-speech.js +12 -4
- package/dist/schemas/transcription-config.d.ts +16 -56
- package/dist/schemas/transcription-config.js +0 -2
- package/dist/schemas/transcription.d.ts +66 -6
- package/dist/schemas/transcription.js +29 -7
- package/dist/schemas/translate.d.ts +14 -4
- package/dist/schemas/translate.js +10 -2
- package/dist/schemas/translation-config.d.ts +30 -10
- package/dist/server/bare/delegate-rpc-client.js +3 -3
- package/dist/server/bare/hyperswarm.js +15 -3
- package/dist/server/bare/ops/embed.d.ts +8 -4
- package/dist/server/bare/ops/embed.js +15 -4
- package/dist/server/bare/ops/transcribe.d.ts +6 -2
- package/dist/server/bare/ops/transcribe.js +53 -1
- package/dist/server/bare/ops/translate.d.ts +4 -1
- package/dist/server/bare/ops/translate.js +28 -65
- package/dist/server/bare/ops/unload-model.js +2 -0
- package/dist/server/bare/plugins/index.d.ts +1 -0
- package/dist/server/bare/plugins/index.js +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.d.ts +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +3 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +3 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +57 -11
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.d.ts +11 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +112 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +175 -5
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +45 -35
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +11 -1
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +9 -4
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +17 -2
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +16 -15
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.d.ts +5 -7
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.js +11 -3
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +2 -0
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +24 -19
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +7 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +22 -97
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +98 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.js +85 -46
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +30 -60
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +49 -37
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +51 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +278 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +70 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +38 -2
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +43 -22
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +2 -1
- package/dist/server/bare/rag-hyperdb/handlers/search.js +2 -1
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +7 -0
- package/dist/server/bare/registry/model-config-utils.js +3 -0
- package/dist/server/bare/registry/model-registry.d.ts +2 -2
- package/dist/server/bare/registry/model-registry.js +1 -1
- package/dist/server/bare/registry/registry-client.js +21 -0
- package/dist/server/bare/runtime-lifecycle.d.ts +28 -0
- package/dist/server/bare/runtime-lifecycle.js +132 -0
- package/dist/server/bare/types/addon-responses.d.ts +62 -0
- package/dist/server/bare/types/addon-responses.js +1 -0
- package/dist/server/env.js +3 -1
- package/dist/server/rpc/delegate-transport.js +1 -1
- package/dist/server/rpc/handle-request.js +50 -4
- package/dist/server/rpc/handler-registry.js +20 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -3
- package/dist/server/rpc/handler-utils.js +52 -50
- package/dist/server/rpc/handlers/delete-cache.js +3 -0
- package/dist/server/rpc/handlers/diffusion-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/diffusion-stream.js +4 -0
- package/dist/server/rpc/handlers/finetune.d.ts +3 -0
- package/dist/server/rpc/handlers/finetune.js +16 -0
- package/dist/server/rpc/handlers/index.d.ts +10 -0
- package/dist/server/rpc/handlers/index.js +10 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +24 -9
- package/dist/server/rpc/handlers/load-model/registry.d.ts +11 -0
- package/dist/server/rpc/handlers/load-model/registry.js +31 -4
- package/dist/server/rpc/handlers/plugin-dispatch.d.ts +1 -13
- package/dist/server/rpc/handlers/plugin-dispatch.js +21 -21
- package/dist/server/rpc/handlers/resume.d.ts +3 -0
- package/dist/server/rpc/handlers/resume.js +11 -0
- package/dist/server/rpc/handlers/suspend.d.ts +3 -0
- package/dist/server/rpc/handlers/suspend.js +11 -0
- package/dist/server/rpc/handlers/transcribe-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +2 -2
- package/dist/server/rpc/handlers/transcribe.d.ts +3 -0
- package/dist/server/rpc/handlers/transcribe.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.js +107 -16
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +1 -1
- package/dist/server/rpc/profiling/operation-wrappers.js +51 -19
- package/dist/server/rpc/progress-throttle.d.ts +8 -0
- package/dist/server/rpc/progress-throttle.js +47 -0
- package/dist/server/rpc/rpc-utils.d.ts +5 -0
- package/dist/server/rpc/rpc-utils.js +11 -0
- package/dist/server/utils/path-security.js +1 -1
- package/dist/server/utils/tool-integration.js +10 -0
- package/dist/server/utils/tool-parser.js +9 -5
- package/dist/server/worker-core.d.ts +2 -0
- package/dist/server/worker-core.js +26 -23
- package/dist/server/worker.js +2 -1
- package/dist/utils/encoding.d.ts +9 -0
- package/dist/utils/encoding.js +14 -0
- package/dist/utils/errors-server.d.ts +6 -0
- package/dist/utils/errors-server.js +11 -0
- package/package.json +81 -25
- package/dist/server/rpc/delegate-utils.d.ts +0 -2
- package/dist/server/rpc/delegate-utils.js +0 -5
|
@@ -5,3 +5,4 @@ export { parakeetPlugin } from "./parakeet-transcription/plugin.js";
|
|
|
5
5
|
export { nmtPlugin } from "./nmtcpp-translation/plugin.js";
|
|
6
6
|
export { ttsPlugin } from "./onnx-tts/plugin.js";
|
|
7
7
|
export { ocrPlugin } from "./onnx-ocr/plugin.js";
|
|
8
|
+
export { diffusionPlugin } from "./sdcpp-generation/plugin.js";
|
|
@@ -3,4 +3,5 @@ export declare function logCacheInit(cacheKey: string, systemPrompt: string, too
|
|
|
3
3
|
export declare function logMessagesToAddon(messages: unknown[], phase?: "CACHE_INIT" | "PROMPT_SEND" | "NO_CACHE"): void;
|
|
4
4
|
export declare function logCacheDisabled(): void;
|
|
5
5
|
export declare function logCacheSave(sessionPath: string): void;
|
|
6
|
+
export declare function logCacheSaveError(sessionPath: string, err: unknown): void;
|
|
6
7
|
//# sourceMappingURL=cache-logger.d.ts.map
|
|
@@ -32,3 +32,6 @@ export function logCacheDisabled() {
|
|
|
32
32
|
export function logCacheSave(sessionPath) {
|
|
33
33
|
logger.debug(`[kv-cache] Saving session: ...${sessionPath.slice(-20)}`);
|
|
34
34
|
}
|
|
35
|
+
export function logCacheSaveError(sessionPath, err) {
|
|
36
|
+
logger.warn(`[kv-cache] Failed to save session: ...${sessionPath.slice(-20)} — ${err instanceof Error ? err.message : String(err)}`);
|
|
37
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CompletionParams, CompletionStats, GenerationParams, Tool, ToolCall, ToolCallEvent } from "../../../../../schemas/index";
|
|
2
|
+
export declare function clearCachedMessageCounts(cachePath?: string): void;
|
|
2
3
|
export declare function completion(params: CompletionParams & {
|
|
3
4
|
tools?: Tool[];
|
|
4
5
|
generationParams?: GenerationParams;
|
|
@@ -6,7 +7,8 @@ export declare function completion(params: CompletionParams & {
|
|
|
6
7
|
token: string;
|
|
7
8
|
toolCallEvent?: ToolCallEvent;
|
|
8
9
|
}, {
|
|
9
|
-
|
|
10
|
+
modelExecutionMs: number;
|
|
11
|
+
stats?: CompletionStats;
|
|
10
12
|
toolCalls: ToolCall[];
|
|
11
13
|
}, unknown>;
|
|
12
14
|
//# sourceMappingURL=completion-stream.d.ts.map
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import { logCacheDisabled, logCacheInit, logCacheSave, logCacheStatus, logMessagesToAddon, } from "./cache-logger.js";
|
|
1
|
+
import { logCacheDisabled, logCacheInit, logCacheSave, logCacheSaveError, logCacheStatus, logMessagesToAddon, } from "./cache-logger.js";
|
|
2
2
|
import { customCacheExists, extractSystemPrompt, findMatchingCache, generateConfigHash, getCacheFilePath, getCurrentCacheInfo, markCacheInitialized, renameCacheFile, } from "../../../ops/kv-cache-utils.js";
|
|
3
3
|
import { getModel, getModelConfig, } from "../../../registry/model-registry.js";
|
|
4
4
|
import { checkForToolEvents, insertToolsIntoHistory, setupToolGrammar, } from "../../../../utils/tool-integration.js";
|
|
5
5
|
import { parseToolCalls } from "../../../../utils/tool-parser.js";
|
|
6
6
|
import { AttachmentNotFoundError } from "../../../../../utils/errors-server.js";
|
|
7
|
+
import { nowMs } from "../../../../../profiling/index.js";
|
|
8
|
+
import { buildStreamResult, hasDefinedValues, } from "../../../../../profiling/model-execution.js";
|
|
7
9
|
import fs from "bare-fs";
|
|
10
|
+
const cachedMessageCounts = new Map();
|
|
11
|
+
export function clearCachedMessageCounts(cachePath) {
|
|
12
|
+
if (cachePath) {
|
|
13
|
+
cachedMessageCounts.delete(cachePath);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
cachedMessageCounts.clear();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
8
19
|
function transformMessage(message) {
|
|
9
20
|
const transformed = [];
|
|
10
21
|
// Check if it's a tool definition (has type: "function")
|
|
@@ -64,11 +75,18 @@ async function initSystemPromptCache(model, cachePathToUse, systemPromptToUse, c
|
|
|
64
75
|
}
|
|
65
76
|
function prepareMessagesForCache(cachePathToUse, cacheExists, history) {
|
|
66
77
|
if (cacheExists && history.length > 0) {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
78
|
+
const savedCount = cachedMessageCounts.get(cachePathToUse) ?? 0;
|
|
79
|
+
const canSlice = savedCount > 0 && savedCount <= history.length;
|
|
80
|
+
const newMessages = canSlice
|
|
81
|
+
? history.slice(savedCount)
|
|
82
|
+
: history.filter((msg) => msg.role !== "system");
|
|
83
|
+
if (!canSlice && savedCount > 0) {
|
|
84
|
+
cachedMessageCounts.delete(cachePathToUse);
|
|
85
|
+
}
|
|
86
|
+
const transformedNewMessages = transformMessages(newMessages);
|
|
69
87
|
return [
|
|
70
88
|
{ role: "session", content: cachePathToUse },
|
|
71
|
-
...
|
|
89
|
+
...transformedNewMessages,
|
|
72
90
|
];
|
|
73
91
|
}
|
|
74
92
|
const historyWithoutSystem = history.filter((msg) => msg.role !== "system");
|
|
@@ -81,6 +99,7 @@ function prepareMessagesForCache(cachePathToUse, cacheExists, history) {
|
|
|
81
99
|
async function* processModelResponse(model, messagesToSend, shouldSaveCache, tools, generationParams) {
|
|
82
100
|
const runFn = model.run.bind(model);
|
|
83
101
|
const runOptions = generationParams ? { generationParams } : undefined;
|
|
102
|
+
const modelStart = nowMs();
|
|
84
103
|
const response = await runFn(messagesToSend, runOptions);
|
|
85
104
|
let accumulatedText = "";
|
|
86
105
|
const emittedToolCallPositions = new Set();
|
|
@@ -96,6 +115,7 @@ async function* processModelResponse(model, messagesToSend, shouldSaveCache, too
|
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
}
|
|
118
|
+
const modelExecutionMs = nowMs() - modelStart;
|
|
99
119
|
if (tools && tools.length > 0) {
|
|
100
120
|
const { toolCalls } = parseToolCalls(accumulatedText, tools);
|
|
101
121
|
toolCallsResult = toolCalls;
|
|
@@ -104,16 +124,38 @@ async function* processModelResponse(model, messagesToSend, shouldSaveCache, too
|
|
|
104
124
|
const sessionMsg = messagesToSend.find((m) => m.role === "session");
|
|
105
125
|
if (sessionMsg?.content) {
|
|
106
126
|
logCacheSave(sessionMsg.content);
|
|
127
|
+
const cachePath = sessionMsg.content;
|
|
128
|
+
const saveResp = await model.run([
|
|
129
|
+
{ role: "session", content: cachePath },
|
|
130
|
+
{ role: "session", content: "save" },
|
|
131
|
+
]);
|
|
132
|
+
try {
|
|
133
|
+
await saveResp.await();
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logCacheSaveError(cachePath, err);
|
|
137
|
+
}
|
|
107
138
|
}
|
|
108
|
-
await model.run([{ role: "session", content: "save" }]);
|
|
109
139
|
}
|
|
110
140
|
const responseWithStats = response;
|
|
111
141
|
const stats = {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
...(responseWithStats.stats?.TTFT !== undefined && {
|
|
143
|
+
timeToFirstToken: responseWithStats.stats.TTFT,
|
|
144
|
+
}),
|
|
145
|
+
...(responseWithStats.stats?.TPS !== undefined && {
|
|
146
|
+
tokensPerSecond: responseWithStats.stats.TPS,
|
|
147
|
+
}),
|
|
148
|
+
...(responseWithStats.stats?.CacheTokens !== undefined && {
|
|
149
|
+
cacheTokens: responseWithStats.stats.CacheTokens,
|
|
150
|
+
}),
|
|
151
|
+
...(responseWithStats.stats?.backendDevice !== undefined && {
|
|
152
|
+
backendDevice: responseWithStats.stats.backendDevice,
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
...buildStreamResult(modelExecutionMs, hasDefinedValues(stats) ? stats : undefined),
|
|
157
|
+
toolCalls: toolCallsResult,
|
|
115
158
|
};
|
|
116
|
-
return { stats, toolCalls: toolCallsResult };
|
|
117
159
|
}
|
|
118
160
|
export async function* completion(params) {
|
|
119
161
|
const { history, modelId, kvCache, tools, generationParams } = params;
|
|
@@ -145,7 +187,9 @@ export async function* completion(params) {
|
|
|
145
187
|
}
|
|
146
188
|
const messagesToSend = prepareMessagesForCache(cachePathToUse, cacheExists, history);
|
|
147
189
|
logMessagesToAddon(messagesToSend, "PROMPT_SEND");
|
|
148
|
-
|
|
190
|
+
const result = yield* processModelResponse(model, messagesToSend, true, tools, generationParams);
|
|
191
|
+
cachedMessageCounts.set(cachePathToUse, history.length + 1);
|
|
192
|
+
return result;
|
|
149
193
|
}
|
|
150
194
|
else {
|
|
151
195
|
// Auto-generate cache key based on conversation history
|
|
@@ -170,9 +214,11 @@ export async function* completion(params) {
|
|
|
170
214
|
const messagesToSend = prepareMessagesForCache(cachePathToUse, cacheExists, history);
|
|
171
215
|
logMessagesToAddon(messagesToSend, "PROMPT_SEND");
|
|
172
216
|
const result = yield* processModelResponse(model, messagesToSend, true, tools, generationParams);
|
|
173
|
-
|
|
217
|
+
cachedMessageCounts.set(cachePathToUse, history.length + 1);
|
|
174
218
|
if (existingCache !== null &&
|
|
175
219
|
existingCache.cachePath !== currentCacheInfo.cachePath) {
|
|
220
|
+
cachedMessageCounts.delete(existingCache.cachePath);
|
|
221
|
+
cachedMessageCounts.set(currentCacheInfo.cachePath, history.length + 1);
|
|
176
222
|
await renameCacheFile(existingCache.cachePath, currentCacheInfo.cachePath);
|
|
177
223
|
}
|
|
178
224
|
return result;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FinetuneRunParams, FinetuneRunRequest, FinetuneProgress, FinetuneRequest, FinetuneResult, FinetuneStatus, FinetuneGetStateRequest } from "../../../../../schemas/index";
|
|
2
|
+
type FinetuneOptions = FinetuneRunParams["options"];
|
|
3
|
+
export declare function clearFinetuneRuntimeState(modelId: string): void;
|
|
4
|
+
export declare function getFinetuneStateFromCheckpoints(options: FinetuneOptions): FinetuneStatus;
|
|
5
|
+
export declare function startFinetune(request: FinetuneRunRequest, onProgress?: (progress: FinetuneProgress) => void): Promise<FinetuneResult>;
|
|
6
|
+
export declare function pauseFinetune(modelId: string): Promise<FinetuneResult>;
|
|
7
|
+
export declare function cancelFinetune(modelId: string): Promise<FinetuneResult>;
|
|
8
|
+
export declare function getFinetuneState(params: FinetuneGetStateRequest): FinetuneResult;
|
|
9
|
+
export declare function finetune(request: FinetuneRequest, onProgress?: (progress: FinetuneProgress) => void): Promise<FinetuneResult>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=finetune.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "bare-fs";
|
|
2
|
+
import { getModel, } from "../../../registry/model-registry.js";
|
|
3
|
+
import { CompletionFailedError, } from "../../../../../utils/errors-server.js";
|
|
4
|
+
const PAUSE_CHECKPOINT_PREFIX = "pause_checkpoint_step_";
|
|
5
|
+
const finetuneRuntimeState = new Set();
|
|
6
|
+
function getRunningFinetuneState(modelId) {
|
|
7
|
+
return finetuneRuntimeState.has(modelId);
|
|
8
|
+
}
|
|
9
|
+
function registerRunningFinetune(modelId) {
|
|
10
|
+
finetuneRuntimeState.add(modelId);
|
|
11
|
+
}
|
|
12
|
+
export function clearFinetuneRuntimeState(modelId) {
|
|
13
|
+
finetuneRuntimeState.delete(modelId);
|
|
14
|
+
}
|
|
15
|
+
export function getFinetuneStateFromCheckpoints(options) {
|
|
16
|
+
const checkpointDirectory = options.checkpointSaveDir ?? "./checkpoints";
|
|
17
|
+
if (!fs.existsSync(checkpointDirectory)) {
|
|
18
|
+
return "IDLE";
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const entries = fs.readdirSync(checkpointDirectory);
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
if (typeof entry !== "string") {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (entry.startsWith(PAUSE_CHECKPOINT_PREFIX)) {
|
|
27
|
+
return "PAUSED";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new CompletionFailedError(`Failed to inspect finetune checkpoints in "${checkpointDirectory}"`, error);
|
|
33
|
+
}
|
|
34
|
+
return "IDLE";
|
|
35
|
+
}
|
|
36
|
+
function validateExplicitFinetuneOperation(request) {
|
|
37
|
+
if (!request.operation) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const state = getFinetuneStateFromCheckpoints(request.options);
|
|
41
|
+
if (request.operation === "start" && state === "PAUSED") {
|
|
42
|
+
throw new CompletionFailedError(`Model "${request.modelId}" has a paused finetune checkpoint; resume it or cancel it before starting from scratch`);
|
|
43
|
+
}
|
|
44
|
+
if (request.operation === "resume" && state === "IDLE") {
|
|
45
|
+
throw new CompletionFailedError(`Model "${request.modelId}" has no paused finetune checkpoint to resume`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function startFinetune(request, onProgress) {
|
|
49
|
+
const model = getModel(request.modelId);
|
|
50
|
+
validateExplicitFinetuneOperation(request);
|
|
51
|
+
registerRunningFinetune(request.modelId);
|
|
52
|
+
try {
|
|
53
|
+
const handle = await model.finetune(request.options);
|
|
54
|
+
if (onProgress) {
|
|
55
|
+
handle.on("stats", onProgress);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const result = await handle.await();
|
|
59
|
+
return {
|
|
60
|
+
type: "finetune",
|
|
61
|
+
status: result.status,
|
|
62
|
+
stats: result.stats,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (onProgress) {
|
|
67
|
+
handle.removeListener("stats", onProgress);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearFinetuneRuntimeState(request.modelId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function pauseFinetune(modelId) {
|
|
76
|
+
const model = getModel(modelId);
|
|
77
|
+
await model.pause();
|
|
78
|
+
return {
|
|
79
|
+
type: "finetune",
|
|
80
|
+
status: "PAUSED",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export async function cancelFinetune(modelId) {
|
|
84
|
+
const model = getModel(modelId);
|
|
85
|
+
await model.cancel();
|
|
86
|
+
return {
|
|
87
|
+
type: "finetune",
|
|
88
|
+
status: "CANCELLED",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function getFinetuneState(params) {
|
|
92
|
+
const runtimeState = getRunningFinetuneState(params.modelId);
|
|
93
|
+
return {
|
|
94
|
+
type: "finetune",
|
|
95
|
+
status: runtimeState ? "RUNNING" : getFinetuneStateFromCheckpoints(params.options),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export async function finetune(request, onProgress) {
|
|
99
|
+
if (request.operation === undefined ||
|
|
100
|
+
request.operation === "start" ||
|
|
101
|
+
request.operation === "resume") {
|
|
102
|
+
return startFinetune(request, onProgress);
|
|
103
|
+
}
|
|
104
|
+
switch (request.operation) {
|
|
105
|
+
case "getState":
|
|
106
|
+
return getFinetuneState(request);
|
|
107
|
+
case "pause":
|
|
108
|
+
return pauseFinetune(request.modelId);
|
|
109
|
+
case "cancel":
|
|
110
|
+
return cancelFinetune(request.modelId);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -22,6 +22,9 @@ export declare const llmPlugin: {
|
|
|
22
22
|
stop_sequences: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
23
23
|
n_discarded: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
24
24
|
tools: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
25
|
+
"cache-type-k": import("zod").ZodOptional<import("zod").ZodString>;
|
|
26
|
+
"cache-type-v": import("zod").ZodOptional<import("zod").ZodString>;
|
|
27
|
+
openclCacheDir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
25
28
|
projectionModelSrc: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodObject<{
|
|
26
29
|
src: import("zod").ZodString;
|
|
27
30
|
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -41,6 +44,7 @@ export declare const llmPlugin: {
|
|
|
41
44
|
"onnx-tts": "onnx-tts";
|
|
42
45
|
"parakeet-transcription": "parakeet-transcription";
|
|
43
46
|
"onnx-ocr": "onnx-ocr";
|
|
47
|
+
"sdcpp-generation": "sdcpp-generation";
|
|
44
48
|
llm: "llm";
|
|
45
49
|
whisper: "whisper";
|
|
46
50
|
embeddings: "embeddings";
|
|
@@ -48,6 +52,7 @@ export declare const llmPlugin: {
|
|
|
48
52
|
parakeet: "parakeet";
|
|
49
53
|
tts: "tts";
|
|
50
54
|
ocr: "ocr";
|
|
55
|
+
diffusion: "diffusion";
|
|
51
56
|
}>, import("zod").ZodLiteral<"vad">]>>;
|
|
52
57
|
}, import("zod/v4/core").$strip>]>>;
|
|
53
58
|
}, import("zod/v4/core").$strip>;
|
|
@@ -71,6 +76,9 @@ export declare const llmPlugin: {
|
|
|
71
76
|
stop_sequences?: string[] | undefined;
|
|
72
77
|
n_discarded?: number | undefined;
|
|
73
78
|
tools?: boolean | undefined;
|
|
79
|
+
"cache-type-k"?: string | undefined;
|
|
80
|
+
"cache-type-v"?: string | undefined;
|
|
81
|
+
openclCacheDir?: string | undefined;
|
|
74
82
|
};
|
|
75
83
|
artifacts?: never;
|
|
76
84
|
} | {
|
|
@@ -93,6 +101,9 @@ export declare const llmPlugin: {
|
|
|
93
101
|
stop_sequences?: string[] | undefined;
|
|
94
102
|
n_discarded?: number | undefined;
|
|
95
103
|
tools?: boolean | undefined;
|
|
104
|
+
"cache-type-k"?: string | undefined;
|
|
105
|
+
"cache-type-v"?: string | undefined;
|
|
106
|
+
openclCacheDir?: string | undefined;
|
|
96
107
|
};
|
|
97
108
|
artifacts: {
|
|
98
109
|
projectionModelPath: string;
|
|
@@ -148,9 +159,13 @@ export declare const llmPlugin: {
|
|
|
148
159
|
token: import("zod").ZodString;
|
|
149
160
|
done: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
150
161
|
stats: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
151
|
-
timeToFirstToken: import("zod").ZodNumber
|
|
152
|
-
tokensPerSecond: import("zod").ZodNumber
|
|
153
|
-
cacheTokens: import("zod").ZodNumber
|
|
162
|
+
timeToFirstToken: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
163
|
+
tokensPerSecond: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
164
|
+
cacheTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
165
|
+
backendDevice: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
166
|
+
cpu: "cpu";
|
|
167
|
+
gpu: "gpu";
|
|
168
|
+
}>>;
|
|
154
169
|
}, import("zod/v4/core").$strip>>;
|
|
155
170
|
toolCallEvent: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
156
171
|
type: import("zod").ZodLiteral<"toolCall">;
|
|
@@ -180,6 +195,156 @@ export declare const llmPlugin: {
|
|
|
180
195
|
}, import("zod/v4/core").$strip>>>;
|
|
181
196
|
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
182
197
|
}, import("zod/v4/core").$strip>>;
|
|
198
|
+
finetune: import("../../../../schemas/index").PluginHandlerDefinition<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
199
|
+
modelId: import("zod").ZodString;
|
|
200
|
+
options: import("zod").ZodObject<{
|
|
201
|
+
trainDatasetDir: import("zod").ZodString;
|
|
202
|
+
validation: import("zod").ZodPipe<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
203
|
+
type: import("zod").ZodLiteral<"none">;
|
|
204
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
205
|
+
type: import("zod").ZodLiteral<"split">;
|
|
206
|
+
fraction: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
207
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
208
|
+
type: import("zod").ZodLiteral<"dataset">;
|
|
209
|
+
path: import("zod").ZodString;
|
|
210
|
+
}, import("zod/v4/core").$strict>], "type">, import("zod").ZodTransform<{
|
|
211
|
+
type: "none";
|
|
212
|
+
} | {
|
|
213
|
+
type: "dataset";
|
|
214
|
+
path: string;
|
|
215
|
+
} | {
|
|
216
|
+
fraction: number;
|
|
217
|
+
type: "split";
|
|
218
|
+
}, {
|
|
219
|
+
type: "none";
|
|
220
|
+
} | {
|
|
221
|
+
type: "split";
|
|
222
|
+
fraction?: number | undefined;
|
|
223
|
+
} | {
|
|
224
|
+
type: "dataset";
|
|
225
|
+
path: string;
|
|
226
|
+
}>>;
|
|
227
|
+
outputParametersDir: import("zod").ZodString;
|
|
228
|
+
numberOfEpochs: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
229
|
+
learningRate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
230
|
+
contextLength: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
231
|
+
batchSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
232
|
+
microBatchSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
233
|
+
assistantLossOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
234
|
+
loraRank: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
235
|
+
loraAlpha: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
236
|
+
loraInitStd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
237
|
+
loraSeed: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
238
|
+
loraModules: import("zod").ZodOptional<import("zod").ZodString>;
|
|
239
|
+
checkpointSaveDir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
240
|
+
checkpointSaveSteps: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
241
|
+
chatTemplatePath: import("zod").ZodOptional<import("zod").ZodString>;
|
|
242
|
+
lrScheduler: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
243
|
+
constant: "constant";
|
|
244
|
+
cosine: "cosine";
|
|
245
|
+
linear: "linear";
|
|
246
|
+
}>>;
|
|
247
|
+
lrMin: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
248
|
+
warmupRatio: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
249
|
+
warmupRatioSet: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
250
|
+
warmupSteps: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
251
|
+
warmupStepsSet: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
252
|
+
weightDecay: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
253
|
+
}, import("zod/v4/core").$strict>;
|
|
254
|
+
type: import("zod").ZodLiteral<"finetune">;
|
|
255
|
+
operation: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
256
|
+
start: "start";
|
|
257
|
+
resume: "resume";
|
|
258
|
+
}>>;
|
|
259
|
+
withProgress: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
260
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
261
|
+
modelId: import("zod").ZodString;
|
|
262
|
+
options: import("zod").ZodObject<{
|
|
263
|
+
trainDatasetDir: import("zod").ZodString;
|
|
264
|
+
validation: import("zod").ZodPipe<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
265
|
+
type: import("zod").ZodLiteral<"none">;
|
|
266
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
267
|
+
type: import("zod").ZodLiteral<"split">;
|
|
268
|
+
fraction: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
269
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
270
|
+
type: import("zod").ZodLiteral<"dataset">;
|
|
271
|
+
path: import("zod").ZodString;
|
|
272
|
+
}, import("zod/v4/core").$strict>], "type">, import("zod").ZodTransform<{
|
|
273
|
+
type: "none";
|
|
274
|
+
} | {
|
|
275
|
+
type: "dataset";
|
|
276
|
+
path: string;
|
|
277
|
+
} | {
|
|
278
|
+
fraction: number;
|
|
279
|
+
type: "split";
|
|
280
|
+
}, {
|
|
281
|
+
type: "none";
|
|
282
|
+
} | {
|
|
283
|
+
type: "split";
|
|
284
|
+
fraction?: number | undefined;
|
|
285
|
+
} | {
|
|
286
|
+
type: "dataset";
|
|
287
|
+
path: string;
|
|
288
|
+
}>>;
|
|
289
|
+
outputParametersDir: import("zod").ZodString;
|
|
290
|
+
numberOfEpochs: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
291
|
+
learningRate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
292
|
+
contextLength: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
293
|
+
batchSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
294
|
+
microBatchSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
295
|
+
assistantLossOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
296
|
+
loraRank: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
297
|
+
loraAlpha: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
298
|
+
loraInitStd: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
299
|
+
loraSeed: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
300
|
+
loraModules: import("zod").ZodOptional<import("zod").ZodString>;
|
|
301
|
+
checkpointSaveDir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
302
|
+
checkpointSaveSteps: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
303
|
+
chatTemplatePath: import("zod").ZodOptional<import("zod").ZodString>;
|
|
304
|
+
lrScheduler: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
305
|
+
constant: "constant";
|
|
306
|
+
cosine: "cosine";
|
|
307
|
+
linear: "linear";
|
|
308
|
+
}>>;
|
|
309
|
+
lrMin: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
310
|
+
warmupRatio: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
311
|
+
warmupRatioSet: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
312
|
+
warmupSteps: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
313
|
+
warmupStepsSet: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
314
|
+
weightDecay: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
315
|
+
}, import("zod/v4/core").$strict>;
|
|
316
|
+
type: import("zod").ZodLiteral<"finetune">;
|
|
317
|
+
operation: import("zod").ZodLiteral<"getState">;
|
|
318
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
319
|
+
modelId: import("zod").ZodString;
|
|
320
|
+
type: import("zod").ZodLiteral<"finetune">;
|
|
321
|
+
operation: import("zod").ZodEnum<{
|
|
322
|
+
cancel: "cancel";
|
|
323
|
+
pause: "pause";
|
|
324
|
+
}>;
|
|
325
|
+
}, import("zod/v4/core").$strict>]>, import("zod").ZodObject<{
|
|
326
|
+
type: import("zod").ZodLiteral<"finetune">;
|
|
327
|
+
status: import("zod").ZodEnum<{
|
|
328
|
+
IDLE: "IDLE";
|
|
329
|
+
RUNNING: "RUNNING";
|
|
330
|
+
PAUSED: "PAUSED";
|
|
331
|
+
CANCELLED: "CANCELLED";
|
|
332
|
+
COMPLETED: "COMPLETED";
|
|
333
|
+
}>;
|
|
334
|
+
stats: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
335
|
+
train_loss: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
336
|
+
train_loss_uncertainty: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodXor<readonly [import("zod").ZodNumber, import("zod").ZodNaN]>>>;
|
|
337
|
+
val_loss: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
338
|
+
val_loss_uncertainty: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodXor<readonly [import("zod").ZodNumber, import("zod").ZodNaN]>>>;
|
|
339
|
+
train_accuracy: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
340
|
+
train_accuracy_uncertainty: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodXor<readonly [import("zod").ZodNumber, import("zod").ZodNaN]>>>;
|
|
341
|
+
val_accuracy: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
342
|
+
val_accuracy_uncertainty: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodXor<readonly [import("zod").ZodNumber, import("zod").ZodNaN]>>>;
|
|
343
|
+
learning_rate: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
344
|
+
global_steps: import("zod").ZodNumber;
|
|
345
|
+
epochs_completed: import("zod").ZodNumber;
|
|
346
|
+
}, import("zod/v4/core").$strict>>;
|
|
347
|
+
}, import("zod/v4/core").$strict>>;
|
|
183
348
|
translate: import("../../../../schemas/index").PluginHandlerDefinition<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
184
349
|
modelId: import("zod").ZodString;
|
|
185
350
|
text: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodArray<import("zod").ZodString>]>;
|
|
@@ -206,8 +371,13 @@ export declare const llmPlugin: {
|
|
|
206
371
|
token: import("zod").ZodString;
|
|
207
372
|
done: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
208
373
|
stats: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
209
|
-
|
|
210
|
-
|
|
374
|
+
totalTime: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
375
|
+
totalTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
376
|
+
tokensPerSecond: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
377
|
+
timeToFirstToken: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
378
|
+
decodeTime: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
379
|
+
encodeTime: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
380
|
+
cacheTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
211
381
|
}, import("zod/v4/core").$strip>>;
|
|
212
382
|
error: import("zod").ZodOptional<import("zod").ZodString>;
|
|
213
383
|
}, import("zod/v4/core").$strip>>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import LlmLlamacpp, {} from "@qvac/llm-llamacpp";
|
|
2
2
|
import llmAddonLogging from "@qvac/llm-llamacpp/addonLogging.js";
|
|
3
|
-
import { definePlugin, defineHandler, completionStreamRequestSchema, completionStreamResponseSchema, translateRequestSchema, translateResponseSchema, ModelType, llmConfigBaseSchema, ADDON_LLM, } from "../../../../schemas/index.js";
|
|
3
|
+
import { definePlugin, defineHandler, finetuneRequestSchema, completionStreamRequestSchema, completionStreamResponseSchema, finetuneResponseSchema, translateRequestSchema, translateResponseSchema, ModelType, llmConfigBaseSchema, ADDON_LLM, } from "../../../../schemas/index.js";
|
|
4
4
|
import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
|
|
5
5
|
import { parseModelPath } from "../../../utils/index.js";
|
|
6
6
|
import FilesystemDL from "@qvac/dl-filesystem";
|
|
7
7
|
import { asLoader } from "../../utils/loader-adapter.js";
|
|
8
8
|
import { completion } from "./ops/completion-stream.js";
|
|
9
|
+
import { finetune } from "./ops/finetune.js";
|
|
9
10
|
import { translate } from "../../ops/translate.js";
|
|
11
|
+
import { attachModelExecutionMs } from "../../../../profiling/model-execution.js";
|
|
10
12
|
function transformLlmConfig(llmConfig) {
|
|
11
13
|
const transformed = JSON.parse(JSON.stringify(llmConfig, (key, v) => key === "modelType"
|
|
12
14
|
? undefined
|
|
@@ -21,6 +23,10 @@ function transformLlmConfig(llmConfig) {
|
|
|
21
23
|
transformed["reverse_prompt"] = transformed["stop_sequences"];
|
|
22
24
|
delete transformed["stop_sequences"];
|
|
23
25
|
}
|
|
26
|
+
if ("opencl_cache_dir" in transformed) {
|
|
27
|
+
transformed["openclCacheDir"] = transformed["opencl_cache_dir"];
|
|
28
|
+
delete transformed["opencl_cache_dir"];
|
|
29
|
+
}
|
|
24
30
|
return transformed;
|
|
25
31
|
}
|
|
26
32
|
function createLlmModel(modelId, modelPath, llmConfig, projectionModelPath) {
|
|
@@ -83,18 +89,10 @@ export const llmPlugin = definePlugin({
|
|
|
83
89
|
...(request.tools && { tools: request.tools }),
|
|
84
90
|
...(request.generationParams && { generationParams: request.generationParams }),
|
|
85
91
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
while (!done) {
|
|
91
|
-
const result = await stream.next();
|
|
92
|
-
if (result.done) {
|
|
93
|
-
stats = result.value.stats;
|
|
94
|
-
toolCalls = result.value.toolCalls;
|
|
95
|
-
done = true;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
92
|
+
try {
|
|
93
|
+
let buffer = "";
|
|
94
|
+
let result = await stream.next();
|
|
95
|
+
while (!result.done) {
|
|
98
96
|
if (request.stream) {
|
|
99
97
|
yield {
|
|
100
98
|
type: "completionStream",
|
|
@@ -107,15 +105,28 @@ export const llmPlugin = definePlugin({
|
|
|
107
105
|
else {
|
|
108
106
|
buffer += result.value.token;
|
|
109
107
|
}
|
|
108
|
+
result = await stream.next();
|
|
110
109
|
}
|
|
110
|
+
const { modelExecutionMs, stats, toolCalls } = result.value;
|
|
111
|
+
yield attachModelExecutionMs({
|
|
112
|
+
type: "completionStream",
|
|
113
|
+
token: request.stream ? "" : buffer,
|
|
114
|
+
done: true,
|
|
115
|
+
...(stats && { stats }),
|
|
116
|
+
...(toolCalls.length > 0 && { toolCalls }),
|
|
117
|
+
}, modelExecutionMs);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
await stream.return?.(undefined);
|
|
111
121
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
finetune: defineHandler({
|
|
125
|
+
requestSchema: finetuneRequestSchema,
|
|
126
|
+
responseSchema: finetuneResponseSchema,
|
|
127
|
+
streaming: false,
|
|
128
|
+
handler: function (request) {
|
|
129
|
+
return finetune(request);
|
|
119
130
|
},
|
|
120
131
|
}),
|
|
121
132
|
translate: defineHandler({
|
|
@@ -124,27 +135,26 @@ export const llmPlugin = definePlugin({
|
|
|
124
135
|
streaming: true,
|
|
125
136
|
handler: async function* (request) {
|
|
126
137
|
const stream = translate(request);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const result = await stream.next();
|
|
131
|
-
if (result.done) {
|
|
132
|
-
stats = result.value;
|
|
133
|
-
done = true;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
138
|
+
try {
|
|
139
|
+
let result = await stream.next();
|
|
140
|
+
while (!result.done) {
|
|
136
141
|
yield {
|
|
137
142
|
type: "translate",
|
|
138
143
|
token: result.value,
|
|
139
144
|
};
|
|
145
|
+
result = await stream.next();
|
|
140
146
|
}
|
|
147
|
+
const { modelExecutionMs, stats } = result.value;
|
|
148
|
+
yield attachModelExecutionMs({
|
|
149
|
+
type: "translate",
|
|
150
|
+
token: "",
|
|
151
|
+
done: true,
|
|
152
|
+
...(stats && { stats }),
|
|
153
|
+
}, modelExecutionMs);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
await stream.return?.(undefined);
|
|
141
157
|
}
|
|
142
|
-
yield {
|
|
143
|
-
type: "translate",
|
|
144
|
-
token: "",
|
|
145
|
-
done: true,
|
|
146
|
-
...(stats && { stats }),
|
|
147
|
-
};
|
|
148
158
|
},
|
|
149
159
|
}),
|
|
150
160
|
},
|