@qvac/sdk 0.2.7-dev.1761566029.f834aa3 → 0.4.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/README.md +26 -3
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +4 -3
- package/dist/client/api/completion-stream.d.ts +24 -32
- package/dist/client/api/completion-stream.js +142 -50
- package/dist/client/api/delete-cache.js +3 -2
- package/dist/client/api/download-asset.d.ts +3 -3
- package/dist/client/api/download-asset.js +12 -17
- package/dist/client/api/embed.d.ts +1 -1
- package/dist/client/api/embed.js +4 -3
- package/dist/client/api/get-model-info.d.ts +29 -0
- package/dist/client/api/get-model-info.js +14 -0
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.js +4 -0
- package/dist/client/api/load-model.d.ts +3 -3
- package/dist/client/api/load-model.js +13 -22
- package/dist/client/api/logging-stream.d.ts +1 -1
- package/dist/client/api/logging-stream.js +3 -2
- package/dist/client/api/ping.d.ts +1 -1
- package/dist/client/api/ping.js +3 -2
- package/dist/client/api/provide.d.ts +1 -1
- package/dist/client/api/provide.js +4 -3
- package/dist/client/api/rag.d.ts +3 -3
- package/dist/client/api/rag.js +13 -12
- package/dist/client/api/set-config.d.ts +7 -0
- package/dist/client/api/set-config.js +20 -0
- package/dist/client/api/stop-provider.d.ts +15 -0
- package/dist/client/api/stop-provider.js +25 -0
- package/dist/client/api/text-to-speech.d.ts +7 -0
- package/dist/client/api/text-to-speech.js +58 -0
- package/dist/client/api/transcribe.d.ts +4 -2
- package/dist/client/api/transcribe.js +9 -5
- package/dist/client/api/translate.d.ts +1 -1
- package/dist/client/api/translate.js +3 -2
- package/dist/client/api/unload-model.d.ts +5 -1
- package/dist/client/api/unload-model.js +14 -4
- package/dist/client/config-manager.d.ts +4 -0
- package/dist/client/config-manager.js +8 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/init-hooks.d.ts +6 -0
- package/dist/client/init-hooks.js +37 -0
- package/dist/client/rpc/bare-client.d.ts +73 -0
- package/dist/client/rpc/bare-client.js +5 -4
- package/dist/client/rpc/bare-rpc-client.js +7 -3
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -0
- package/dist/client/rpc/expo-rpc-client.js +9 -1
- package/dist/client/rpc/node-rpc-client.d.ts +1 -1
- package/dist/client/rpc/node-rpc-client.js +22 -9
- package/dist/client/rpc/rpc-client.d.ts +1 -0
- package/dist/client/rpc/rpc-client.js +27 -3
- package/dist/examples/cache-management.d.ts +2 -0
- package/dist/examples/cache-management.js +97 -0
- package/dist/examples/delegated-inference/consumer.js +2 -2
- package/dist/examples/download-with-blind-relays.d.ts +2 -0
- package/dist/examples/download-with-blind-relays.js +48 -0
- package/dist/examples/download-with-cancel.js +3 -4
- package/dist/examples/embed-hyperdrive.js +0 -1
- package/dist/examples/kv-cache-cleanup.js +0 -1
- package/dist/examples/kv-cache-custom-key.js +0 -1
- package/dist/examples/kv-cache-example.js +0 -1
- package/dist/examples/llamacpp-file-logging.js +0 -1
- package/dist/examples/llamacpp-filesystem.js +2 -2
- package/dist/examples/llamacpp-http.js +0 -1
- package/dist/examples/llamacpp-hyperdrive.js +0 -1
- package/dist/examples/llamacpp-multimodal.js +0 -1
- package/dist/examples/llamacpp-native-tools.js +118 -36
- package/dist/examples/llamacpp-sharded.d.ts +2 -0
- package/dist/examples/llamacpp-sharded.js +44 -0
- package/dist/examples/multi-model-demo.js +0 -1
- package/dist/examples/parallel-download.js +2 -2
- package/dist/examples/rag/rag-chromadb.js +0 -1
- package/dist/examples/rag/rag-hyperdb-workspaces.js +0 -1
- package/dist/examples/rag/rag-hyperdb.js +0 -1
- package/dist/examples/rag/rag-lancedb.js +0 -1
- package/dist/examples/rag/rag-sqlite.js +0 -1
- package/dist/examples/text-to-speech.d.ts +3 -0
- package/dist/examples/text-to-speech.js +137 -0
- package/dist/examples/translation/translation-indic.js +3 -1
- package/dist/examples/translation/translation-llm-context.js +0 -1
- package/dist/examples/translation/translation-llm.js +2 -2
- package/dist/examples/translation/translation-opus.js +3 -1
- package/dist/examples/translation/translation-stream.js +0 -1
- package/dist/examples/whispercpp-filesystem.js +32 -5
- package/dist/examples/whispercpp-microphone-record.js +9 -9
- package/dist/examples/whispercpp-prompt.d.ts +2 -0
- package/dist/examples/whispercpp-prompt.js +68 -0
- package/dist/expo/plugins/withMobileBundle.js +9 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/models/hyperdrive/models.d.ts +1924 -100
- package/dist/models/hyperdrive/models.js +2051 -105
- package/dist/schemas/common.d.ts +420 -58
- package/dist/schemas/common.js +12 -0
- package/dist/schemas/completion-stream.d.ts +26 -22
- package/dist/schemas/completion-stream.js +9 -23
- package/dist/schemas/download-asset.d.ts +77 -2
- package/dist/schemas/download-asset.js +15 -4
- package/dist/schemas/get-model-info.d.ts +100 -0
- package/dist/schemas/get-model-info.js +40 -0
- package/dist/schemas/index.d.ts +8 -0
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/llamacpp-config.d.ts +2 -1
- package/dist/schemas/llamacpp-config.js +3 -4
- package/dist/schemas/load-model.d.ts +2316 -266
- package/dist/schemas/load-model.js +157 -10
- package/dist/schemas/model-src-utils.d.ts +98 -0
- package/dist/schemas/model-src-utils.js +31 -0
- package/dist/schemas/sdk-errors-client.d.ts +25 -0
- package/dist/schemas/sdk-errors-client.js +111 -0
- package/dist/schemas/sdk-errors-server.d.ts +55 -0
- package/dist/schemas/sdk-errors-server.js +271 -0
- package/dist/schemas/set-config.d.ts +21 -0
- package/dist/schemas/set-config.js +14 -0
- package/dist/schemas/stop-provide.d.ts +17 -0
- package/dist/schemas/stop-provide.js +15 -0
- package/dist/schemas/text-to-speech.d.ts +34 -0
- package/dist/schemas/text-to-speech.js +25 -0
- package/dist/schemas/tools.d.ts +62 -0
- package/dist/schemas/tools.js +43 -0
- package/dist/schemas/transcription.d.ts +25 -2
- package/dist/schemas/transcription.js +12 -1
- package/dist/schemas/translation-config.d.ts +33 -5
- package/dist/schemas/translation-config.js +18 -1
- package/dist/schemas/unload-model.d.ts +2 -0
- package/dist/schemas/unload-model.js +2 -0
- package/dist/schemas/whispercpp-config.d.ts +55 -18
- package/dist/schemas/whispercpp-config.js +63 -15
- package/dist/server/bare/addons/cancel.js +2 -1
- package/dist/server/bare/addons/llamacpp/create-model.d.ts +9 -2
- package/dist/server/bare/addons/llamacpp/create-model.js +23 -23
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.d.ts +10 -2
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +62 -43
- package/dist/server/bare/addons/llamacpp/handlers/embed.js +3 -2
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +1 -1
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +6 -2
- package/dist/server/bare/addons/load-model.js +59 -28
- package/dist/server/bare/addons/translation/create-model.d.ts +5 -1
- package/dist/server/bare/addons/translation/create-model.js +17 -25
- package/dist/server/bare/addons/translation/handlers/translate.js +10 -1
- package/dist/server/bare/addons/tts/create-model.d.ts +10 -0
- package/dist/server/bare/addons/tts/create-model.js +25 -0
- package/dist/server/bare/addons/tts/handlers/text-to-speech.d.ts +3 -0
- package/dist/server/bare/addons/tts/handlers/text-to-speech.js +87 -0
- package/dist/server/bare/addons/tts/index.d.ts +3 -0
- package/dist/server/bare/addons/tts/index.js +2 -0
- package/dist/server/bare/addons/unload-model.js +21 -3
- package/dist/server/bare/addons/whispercpp/create-model.d.ts +5 -1
- package/dist/server/bare/addons/whispercpp/create-model.js +13 -32
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +41 -20
- package/dist/server/bare/delegate-rpc-client.js +3 -2
- package/dist/server/bare/hyperswarm.d.ts +3 -0
- package/dist/server/bare/hyperswarm.js +22 -1
- package/dist/server/bare/rag-hyperdb/rag-manager.js +16 -13
- package/dist/server/bare/registry/config-registry.d.ts +5 -0
- package/dist/server/bare/registry/config-registry.js +39 -0
- package/dist/server/bare/registry/logging-stream-registry.d.ts +1 -0
- package/dist/server/bare/registry/logging-stream-registry.js +7 -0
- package/dist/server/bare/registry/model-registry.d.ts +13 -0
- package/dist/server/bare/registry/model-registry.js +24 -7
- package/dist/server/rpc/handle-request.js +48 -3
- package/dist/server/rpc/handlers/completion-stream-delegated.js +2 -1
- package/dist/server/rpc/handlers/completion-stream.js +11 -4
- package/dist/server/rpc/handlers/download-asset.js +2 -3
- package/dist/server/rpc/handlers/get-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-model-info.js +148 -0
- package/dist/server/rpc/handlers/index.d.ts +6 -0
- package/dist/server/rpc/handlers/index.js +8 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +1 -0
- package/dist/server/rpc/handlers/load-model/download-manager.js +12 -31
- package/dist/server/rpc/handlers/load-model/http.js +51 -10
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +336 -156
- package/dist/server/rpc/handlers/load-model/index.js +1 -1
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +1 -1
- package/dist/server/rpc/handlers/load-model/resolve.js +17 -60
- package/dist/server/rpc/handlers/load-model-delegated.js +7 -4
- package/dist/server/rpc/handlers/load-model.js +19 -1
- package/dist/server/rpc/handlers/provideHandler/handler.js +2 -1
- package/dist/server/rpc/handlers/rag.js +0 -3
- package/dist/server/rpc/handlers/set-config.d.ts +3 -0
- package/dist/server/rpc/handlers/set-config.js +18 -0
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +3 -0
- package/dist/server/rpc/handlers/stopProvideHandler.js +22 -0
- package/dist/server/rpc/handlers/text-to-speech.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech.js +7 -0
- package/dist/server/rpc/handlers/transcribe-stream.js +6 -2
- package/dist/server/rpc/handlers/unload-model.js +7 -0
- package/dist/server/utils/cache.d.ts +13 -8
- package/dist/server/utils/cache.js +69 -14
- package/dist/server/utils/checksum.d.ts +2 -0
- package/dist/server/utils/checksum.js +24 -0
- package/dist/server/utils/index.d.ts +2 -0
- package/dist/server/utils/index.js +2 -0
- package/dist/server/utils/shard-utils.d.ts +22 -0
- package/dist/server/utils/shard-utils.js +37 -0
- package/dist/server/utils/tool-integration.d.ts +13 -0
- package/dist/server/utils/tool-integration.js +43 -0
- package/dist/server/utils/tool-parser.d.ts +7 -0
- package/dist/server/utils/tool-parser.js +244 -0
- package/dist/server/worker.js +28 -10
- package/dist/utils/errors-base.d.ts +3 -0
- package/dist/utils/errors-base.js +13 -0
- package/dist/utils/errors-client.d.ts +107 -0
- package/dist/utils/errors-client.js +186 -0
- package/dist/utils/errors-server.d.ts +146 -0
- package/dist/utils/errors-server.js +253 -0
- package/dist/utils/tool-helpers.d.ts +17 -0
- package/dist/utils/tool-helpers.js +99 -0
- package/package.json +15 -11
- package/dist/examples/llamacpp-tools-routing.d.ts +0 -2
- package/dist/examples/llamacpp-tools-routing.js +0 -364
- package/dist/examples/llamacpp-tools.d.ts +0 -2
- package/dist/examples/llamacpp-tools.js +0 -81
- package/dist/server/http-server.d.ts +0 -2
- package/dist/server/http-server.js +0 -189
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
// Marian model languages
|
|
3
|
-
const MARIAN_LANGUAGES = ["en", "de", "es", "it"];
|
|
3
|
+
const MARIAN_LANGUAGES = ["en", "de", "es", "it", "ru", "ja"];
|
|
4
4
|
// IndicTrans2 model languages
|
|
5
5
|
export const INDICTRANS_LANGUAGES = [
|
|
6
6
|
"asm_Beng", // Assamese
|
|
@@ -39,8 +39,25 @@ export const nmtConfigSchema = z
|
|
|
39
39
|
mode: z.enum(["full"]).optional(),
|
|
40
40
|
from: z.enum(NMT_LANGUAGES),
|
|
41
41
|
to: z.enum(NMT_LANGUAGES),
|
|
42
|
+
// Generation parameters (lowercase to match addon expectations)
|
|
43
|
+
beamsize: z.number().optional(),
|
|
44
|
+
lengthpenalty: z.number().optional(),
|
|
45
|
+
maxlength: z.number().optional(),
|
|
46
|
+
repetitionpenalty: z.number().optional(),
|
|
47
|
+
norepeatngramsize: z.number().optional(),
|
|
48
|
+
temperature: z.number().optional(),
|
|
49
|
+
topk: z.number().optional(),
|
|
50
|
+
topp: z.number().optional(),
|
|
42
51
|
})
|
|
43
52
|
.transform((data) => ({
|
|
44
53
|
...data,
|
|
45
54
|
mode: data.mode ?? "full",
|
|
55
|
+
beamsize: data.beamsize ?? 4,
|
|
56
|
+
lengthpenalty: data.lengthpenalty ?? 1.0,
|
|
57
|
+
maxlength: data.maxlength ?? 512,
|
|
58
|
+
repetitionpenalty: data.repetitionpenalty ?? 1.0,
|
|
59
|
+
norepeatngramsize: data.norepeatngramsize ?? 0,
|
|
60
|
+
temperature: data.temperature ?? 0.3,
|
|
61
|
+
topk: data.topk ?? 0,
|
|
62
|
+
topp: data.topp ?? 1.0,
|
|
46
63
|
}));
|
|
@@ -12,6 +12,8 @@ export declare const unloadModelResponseSchema: z.ZodObject<{
|
|
|
12
12
|
type: z.ZodLiteral<"unloadModel">;
|
|
13
13
|
success: z.ZodBoolean;
|
|
14
14
|
error: z.ZodOptional<z.ZodString>;
|
|
15
|
+
hasActiveModels: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
hasActiveProviders: z.ZodOptional<z.ZodBoolean>;
|
|
15
17
|
}, z.core.$strip>;
|
|
16
18
|
export type UnloadModelParams = z.input<typeof unloadModelParamsSchema>;
|
|
17
19
|
export type UnloadModelRequest = z.infer<typeof unloadModelRequestSchema>;
|
|
@@ -1,24 +1,61 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const whisperConfigSchema: z.ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
strategy: z.ZodOptional<z.ZodEnum<{
|
|
4
|
+
greedy: "greedy";
|
|
5
|
+
beam_search: "beam_search";
|
|
6
6
|
}>>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
n_threads: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
n_max_text_ctx: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
offset_ms: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
audio_ctx: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
translate: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
no_context: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
no_timestamps: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
single_segment: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
print_special: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
print_progress: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
print_realtime: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
print_timestamps: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
token_timestamps: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
thold_pt: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
thold_ptsum: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
max_len: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
split_on_word: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
debug_mode: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
tdrz_enable: z.ZodOptional<z.ZodBoolean>;
|
|
28
|
+
suppress_regex: z.ZodOptional<z.ZodString>;
|
|
29
|
+
initial_prompt: z.ZodOptional<z.ZodString>;
|
|
30
|
+
language: z.ZodOptional<z.ZodString>;
|
|
31
|
+
detect_language: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
suppress_blank: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
suppress_nst: z.ZodOptional<z.ZodBoolean>;
|
|
34
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
length_penalty: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
temperature_inc: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
entropy_thold: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
logprob_thold: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
greedy_best_of: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
beam_search_beam_size: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
vad_model_path: z.ZodOptional<z.ZodString>;
|
|
42
|
+
vad_params: z.ZodOptional<z.ZodObject<{
|
|
43
|
+
threshold: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
min_speech_duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
min_silence_duration_ms: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
max_speech_duration_s: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
speech_pad_ms: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
samples_overlap: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
audio_format: z.ZodOptional<z.ZodString>;
|
|
51
|
+
contextParams: z.ZodOptional<z.ZodObject<{
|
|
52
|
+
model: z.ZodOptional<z.ZodString>;
|
|
53
|
+
use_gpu: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
flash_attn: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
gpu_device: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
57
|
+
miscConfig: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
caption_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
22
59
|
}, z.core.$strip>>;
|
|
23
60
|
}, z.core.$strip>;
|
|
24
61
|
export type WhisperConfig = z.infer<typeof whisperConfigSchema>;
|
|
@@ -1,18 +1,66 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
const vadParamsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
threshold: z.number().optional(),
|
|
5
|
+
min_speech_duration_ms: z.number().optional(),
|
|
6
|
+
min_silence_duration_ms: z.number().optional(),
|
|
7
|
+
max_speech_duration_s: z.number().optional(),
|
|
8
|
+
speech_pad_ms: z.number().optional(),
|
|
9
|
+
samples_overlap: z.number().optional(),
|
|
10
|
+
})
|
|
11
|
+
.optional();
|
|
12
|
+
const contextParamsSchema = z
|
|
13
|
+
.object({
|
|
14
|
+
model: z.string().optional(),
|
|
15
|
+
use_gpu: z.boolean().optional(),
|
|
16
|
+
flash_attn: z.boolean().optional(),
|
|
17
|
+
gpu_device: z.number().optional(),
|
|
18
|
+
})
|
|
19
|
+
.optional();
|
|
20
|
+
const miscConfigSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
caption_enabled: z.boolean().optional(),
|
|
23
|
+
})
|
|
24
|
+
.optional();
|
|
10
25
|
export const whisperConfigSchema = z.object({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
strategy: z.enum(["greedy", "beam_search"]).optional(),
|
|
27
|
+
n_threads: z.number().int().optional(),
|
|
28
|
+
n_max_text_ctx: z.number().int().optional(),
|
|
29
|
+
offset_ms: z.number().int().optional(),
|
|
30
|
+
duration_ms: z.number().int().optional(),
|
|
31
|
+
audio_ctx: z.number().int().optional(),
|
|
32
|
+
translate: z.boolean().optional(),
|
|
33
|
+
no_context: z.boolean().optional(),
|
|
34
|
+
no_timestamps: z.boolean().optional(),
|
|
35
|
+
single_segment: z.boolean().optional(),
|
|
36
|
+
print_special: z.boolean().optional(),
|
|
37
|
+
print_progress: z.boolean().optional(),
|
|
38
|
+
print_realtime: z.boolean().optional(),
|
|
39
|
+
print_timestamps: z.boolean().optional(),
|
|
40
|
+
token_timestamps: z.boolean().optional(),
|
|
41
|
+
thold_pt: z.number().optional(),
|
|
42
|
+
thold_ptsum: z.number().optional(),
|
|
43
|
+
max_len: z.number().int().optional(),
|
|
44
|
+
split_on_word: z.boolean().optional(),
|
|
45
|
+
max_tokens: z.number().int().optional(),
|
|
46
|
+
debug_mode: z.boolean().optional(),
|
|
47
|
+
tdrz_enable: z.boolean().optional(),
|
|
48
|
+
suppress_regex: z.string().optional(),
|
|
49
|
+
initial_prompt: z.string().optional(),
|
|
50
|
+
language: z.string().optional(),
|
|
51
|
+
detect_language: z.boolean().optional(),
|
|
52
|
+
suppress_blank: z.boolean().optional(),
|
|
53
|
+
suppress_nst: z.boolean().optional(),
|
|
54
|
+
temperature: z.number().optional(),
|
|
55
|
+
length_penalty: z.number().optional(),
|
|
56
|
+
temperature_inc: z.number().optional(),
|
|
57
|
+
entropy_thold: z.number().optional(),
|
|
58
|
+
logprob_thold: z.number().optional(),
|
|
59
|
+
greedy_best_of: z.number().int().optional(),
|
|
60
|
+
beam_search_beam_size: z.number().int().optional(),
|
|
61
|
+
vad_model_path: z.string().optional(),
|
|
62
|
+
vad_params: vadParamsSchema,
|
|
63
|
+
audio_format: z.string().optional(),
|
|
64
|
+
contextParams: contextParamsSchema,
|
|
65
|
+
miscConfig: miscConfigSchema,
|
|
18
66
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getModel } from "../registry/model-registry.js";
|
|
2
2
|
import { cancelInferenceBaseSchema, } from "../../../schemas/index.js";
|
|
3
|
+
import { ModelNotLoadedError } from "../../../utils/errors-server.js";
|
|
3
4
|
export async function cancel(params) {
|
|
4
5
|
const { modelId } = cancelInferenceBaseSchema.parse(params);
|
|
5
6
|
const model = getModel(modelId);
|
|
6
7
|
if (!model) {
|
|
7
|
-
throw new
|
|
8
|
+
throw new ModelNotLoadedError(modelId);
|
|
8
9
|
}
|
|
9
10
|
if (model.addon && model.addon.cancel) {
|
|
10
11
|
await model.addon.cancel();
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { AnyModel } from "../../registry/model-registry";
|
|
2
2
|
import type { EmbedConfig, LlmConfig } from "../../../../schemas/index";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
3
|
+
import FilesystemDL from "@qvac/dl-filesystem";
|
|
4
|
+
export declare function createLlmModel(modelId: string, modelPath: string, llmConfig: LlmConfig, projectionModelPath?: string): {
|
|
5
|
+
model: AnyModel;
|
|
6
|
+
loader: FilesystemDL;
|
|
7
|
+
};
|
|
8
|
+
export declare function createEmbeddingsModel(modelId: string, modelPath: string, embedConfig: EmbedConfig): {
|
|
9
|
+
model: AnyModel;
|
|
10
|
+
loader: FilesystemDL;
|
|
11
|
+
};
|
|
5
12
|
//# sourceMappingURL=create-model.d.ts.map
|
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
import LlmLlamacpp from "@qvac/llm-llamacpp";
|
|
2
2
|
import EmbedLlamacpp from "@qvac/embed-llamacpp";
|
|
3
|
-
import { Readable } from "bare-stream";
|
|
4
3
|
import { createStreamLogger } from "../../../../logging/index.js";
|
|
5
4
|
import { parseModelPath } from "../../../utils/index.js";
|
|
6
|
-
|
|
7
|
-
function createFilesystemDLMimic() {
|
|
8
|
-
return {
|
|
9
|
-
dirPath: "./",
|
|
10
|
-
getStream: () => Promise.resolve(Readable.from([])),
|
|
11
|
-
ready: () => Promise.resolve(),
|
|
12
|
-
close: () => Promise.resolve(),
|
|
13
|
-
destroy: () => Promise.resolve(),
|
|
14
|
-
start: () => Promise.resolve(),
|
|
15
|
-
stop: () => Promise.resolve(),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
5
|
+
import FilesystemDL from "@qvac/dl-filesystem";
|
|
18
6
|
function transformLlmConfig(llmConfig) {
|
|
19
|
-
|
|
7
|
+
const transformed = JSON.parse(JSON.stringify(llmConfig, (key, v) => key === "modelType"
|
|
20
8
|
? undefined
|
|
21
|
-
:
|
|
22
|
-
?
|
|
23
|
-
|
|
9
|
+
: key === "stop_sequences"
|
|
10
|
+
? Array.isArray(v)
|
|
11
|
+
? v.join(", ")
|
|
12
|
+
: v
|
|
13
|
+
: typeof v === "number" || typeof v === "boolean"
|
|
14
|
+
? String(v)
|
|
15
|
+
: v).replace(/"([a-z][A-Za-z]*)":/g, (_, key) => `"${key.replace(/[A-Z]/g, (l) => `_${l.toLowerCase()}`)}":`));
|
|
16
|
+
// Rename stop_sequences to reverse_prompt for the addon
|
|
17
|
+
if ("stop_sequences" in transformed) {
|
|
18
|
+
transformed["reverse_prompt"] = transformed["stop_sequences"];
|
|
19
|
+
delete transformed["stop_sequences"];
|
|
20
|
+
}
|
|
21
|
+
return transformed;
|
|
24
22
|
}
|
|
25
23
|
export function createLlmModel(modelId, modelPath, llmConfig, projectionModelPath) {
|
|
26
24
|
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
27
|
-
const
|
|
25
|
+
const loader = new FilesystemDL({ dirPath });
|
|
28
26
|
const logger = createStreamLogger(modelId, "llamacpp:llm");
|
|
29
27
|
const llmConfigStrings = transformLlmConfig(llmConfig);
|
|
30
28
|
const args = {
|
|
31
|
-
loader
|
|
29
|
+
loader,
|
|
32
30
|
opts: { stats: true },
|
|
33
31
|
logger,
|
|
34
32
|
diskPath: dirPath,
|
|
@@ -39,19 +37,21 @@ export function createLlmModel(modelId, modelPath, llmConfig, projectionModelPat
|
|
|
39
37
|
modelPath,
|
|
40
38
|
modelConfig: llmConfigStrings,
|
|
41
39
|
};
|
|
42
|
-
|
|
40
|
+
const model = new LlmLlamacpp(args, llmConfigStrings);
|
|
41
|
+
return { model, loader };
|
|
43
42
|
}
|
|
44
43
|
export function createEmbeddingsModel(modelId, modelPath, embedConfig) {
|
|
45
44
|
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
46
|
-
const
|
|
45
|
+
const loader = new FilesystemDL({ dirPath });
|
|
47
46
|
const logger = createStreamLogger(modelId, "llamacpp:embed");
|
|
48
47
|
const args = {
|
|
49
|
-
loader
|
|
48
|
+
loader,
|
|
50
49
|
opts: { stats: true },
|
|
51
50
|
logger,
|
|
52
51
|
diskPath: dirPath,
|
|
53
52
|
modelName: basePath,
|
|
54
53
|
modelPath,
|
|
55
54
|
};
|
|
56
|
-
|
|
55
|
+
const model = new EmbedLlamacpp(args, embedConfig.config);
|
|
56
|
+
return { model, loader };
|
|
57
57
|
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import { type CompletionStats, type
|
|
2
|
-
export declare function completion(params: CompletionParams
|
|
1
|
+
import { type CompletionParams, type CompletionStats, type Tool, type ToolCall, type ToolCallEvent } from "../../../../../schemas/index";
|
|
2
|
+
export declare function completion(params: CompletionParams & {
|
|
3
|
+
tools?: Tool[];
|
|
4
|
+
}): AsyncGenerator<{
|
|
5
|
+
token: string;
|
|
6
|
+
toolCallEvent?: ToolCallEvent;
|
|
7
|
+
}, {
|
|
8
|
+
stats: CompletionStats;
|
|
9
|
+
toolCalls: ToolCall[];
|
|
10
|
+
}, unknown>;
|
|
3
11
|
//# sourceMappingURL=completion-stream.d.ts.map
|
|
@@ -1,20 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from "../../../../../schemas/index.js";
|
|
2
|
+
import { customCacheExists, extractSystemPrompt, findMatchingCache, generateConfigHash, getCacheFilePath, getCurrentCacheInfo, renameCacheFile, } from "../kv-cache-utils.js";
|
|
2
3
|
import { getModel, getModelConfig, } from "../../../registry/model-registry.js";
|
|
3
|
-
import {
|
|
4
|
+
import { checkForToolEvents, insertToolsIntoHistory, setupToolGrammar, } from "../../../../utils/tool-integration.js";
|
|
5
|
+
import { parseToolCalls } from "../../../../utils/tool-parser.js";
|
|
6
|
+
import { AttachmentNotFoundError } from "../../../../../utils/errors-server.js";
|
|
7
|
+
import fs from "bare-fs";
|
|
4
8
|
function transformMessage(message) {
|
|
5
9
|
const transformed = [];
|
|
6
|
-
if
|
|
7
|
-
|
|
10
|
+
// Check if it's a tool definition (has type: "function")
|
|
11
|
+
if ("type" in message && message.type === "function") {
|
|
12
|
+
transformed.push({
|
|
13
|
+
type: "function",
|
|
14
|
+
name: message.name,
|
|
15
|
+
description: message.description,
|
|
16
|
+
parameters: message.parameters,
|
|
17
|
+
});
|
|
18
|
+
return transformed;
|
|
19
|
+
}
|
|
20
|
+
const msg = message;
|
|
21
|
+
if (msg.attachments && msg.attachments.length > 0) {
|
|
22
|
+
for (const attachment of msg.attachments) {
|
|
23
|
+
if (!fs.existsSync(attachment.path)) {
|
|
24
|
+
throw new AttachmentNotFoundError(attachment.path);
|
|
25
|
+
}
|
|
8
26
|
transformed.push({
|
|
9
|
-
role:
|
|
27
|
+
role: msg.role,
|
|
10
28
|
content: attachment.path,
|
|
11
29
|
type: "media",
|
|
12
30
|
});
|
|
13
31
|
}
|
|
14
32
|
}
|
|
15
33
|
transformed.push({
|
|
16
|
-
role:
|
|
17
|
-
content:
|
|
34
|
+
role: msg.role,
|
|
35
|
+
content: msg.content,
|
|
18
36
|
});
|
|
19
37
|
return transformed;
|
|
20
38
|
}
|
|
@@ -25,11 +43,15 @@ function transformMessages(messages) {
|
|
|
25
43
|
}
|
|
26
44
|
return transformed;
|
|
27
45
|
}
|
|
28
|
-
async function initSystemPromptCache(model, cachePathToUse, systemPromptToUse) {
|
|
46
|
+
async function initSystemPromptCache(model, cachePathToUse, systemPromptToUse, tools) {
|
|
29
47
|
const primeMessages = [
|
|
30
48
|
{ role: "session", content: cachePathToUse },
|
|
31
49
|
{ role: "system", content: systemPromptToUse },
|
|
32
50
|
];
|
|
51
|
+
if (tools && tools.length > 0) {
|
|
52
|
+
const transformedTools = transformMessages(tools);
|
|
53
|
+
primeMessages.push(...transformedTools);
|
|
54
|
+
}
|
|
33
55
|
const primeResponse = await model.run(primeMessages);
|
|
34
56
|
primeResponse.once("output", () => {
|
|
35
57
|
void primeResponse.cancel();
|
|
@@ -52,55 +74,52 @@ function prepareMessagesForCache(cachePathToUse, cacheExists, history) {
|
|
|
52
74
|
...transformedHistoryWithoutSystem,
|
|
53
75
|
];
|
|
54
76
|
}
|
|
55
|
-
async function* processModelResponse(model, messagesToSend, shouldSaveCache) {
|
|
77
|
+
async function* processModelResponse(model, messagesToSend, shouldSaveCache, tools) {
|
|
56
78
|
const response = await model.run(messagesToSend);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
while (true) {
|
|
70
|
-
// Race between getting the next token and an error occurring
|
|
71
|
-
const result = await Promise.race([iterator.next(), errorPromise]);
|
|
72
|
-
if (result.done) {
|
|
73
|
-
break;
|
|
79
|
+
let accumulatedText = "";
|
|
80
|
+
const emittedToolCallPositions = new Set();
|
|
81
|
+
let toolCallsResult = [];
|
|
82
|
+
for await (const token of response.iterate()) {
|
|
83
|
+
const tokenStr = token;
|
|
84
|
+
accumulatedText += tokenStr;
|
|
85
|
+
yield { token: tokenStr };
|
|
86
|
+
if (tools && tools.length > 0) {
|
|
87
|
+
const toolEvents = checkForToolEvents(accumulatedText, tokenStr, tools, emittedToolCallPositions);
|
|
88
|
+
for (const toolEvent of toolEvents) {
|
|
89
|
+
yield { token: "", toolCallEvent: toolEvent };
|
|
74
90
|
}
|
|
75
|
-
yield result.value;
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw new Error(String(error));
|
|
84
|
-
}
|
|
93
|
+
if (tools && tools.length > 0) {
|
|
94
|
+
const { toolCalls } = parseToolCalls(accumulatedText, tools);
|
|
95
|
+
toolCallsResult = toolCalls;
|
|
85
96
|
}
|
|
86
97
|
if (shouldSaveCache) {
|
|
87
98
|
await model.run([{ role: "session", content: "save" }]);
|
|
88
99
|
}
|
|
89
100
|
const responseWithStats = response;
|
|
90
|
-
|
|
101
|
+
const stats = {
|
|
91
102
|
timeToFirstToken: responseWithStats.stats?.TTFT ?? 0,
|
|
92
103
|
tokensPerSecond: responseWithStats.stats?.TPS ?? 0,
|
|
93
104
|
cacheTokens: responseWithStats.stats?.CacheTokens ?? 0,
|
|
94
105
|
};
|
|
106
|
+
return { stats, toolCalls: toolCallsResult };
|
|
95
107
|
}
|
|
96
108
|
export async function* completion(params) {
|
|
97
|
-
const { history, modelId, kvCache } =
|
|
98
|
-
const
|
|
109
|
+
const { history, modelId, kvCache, tools } = params;
|
|
110
|
+
const modelConfig = getModelConfig(modelId);
|
|
111
|
+
const toolsEnabled = modelConfig.tools === true;
|
|
112
|
+
let historyWithTools = history;
|
|
113
|
+
if (tools && tools.length > 0 && toolsEnabled) {
|
|
114
|
+
historyWithTools = insertToolsIntoHistory(history, tools);
|
|
115
|
+
setupToolGrammar(modelConfig, tools);
|
|
116
|
+
}
|
|
117
|
+
const transformedHistory = transformMessages(historyWithTools);
|
|
99
118
|
const model = getModel(modelId);
|
|
100
119
|
if (kvCache) {
|
|
101
120
|
const modelConfig = getModelConfig(modelId);
|
|
102
121
|
const systemPromptFromHistory = extractSystemPrompt(history);
|
|
103
|
-
const configHash = generateConfigHash(modelConfig, systemPromptFromHistory);
|
|
122
|
+
const configHash = generateConfigHash(modelConfig, systemPromptFromHistory, tools);
|
|
104
123
|
const systemPromptToUse = systemPromptFromHistory ||
|
|
105
124
|
modelConfig.system_prompt ||
|
|
106
125
|
"You are a helpful assistant.";
|
|
@@ -109,10 +128,10 @@ export async function* completion(params) {
|
|
|
109
128
|
cachePathToUse = await getCacheFilePath(modelId, configHash, kvCache);
|
|
110
129
|
const cacheExists = await customCacheExists(modelId, configHash, kvCache);
|
|
111
130
|
if (!cacheExists) {
|
|
112
|
-
await initSystemPromptCache(model, cachePathToUse, systemPromptToUse);
|
|
131
|
+
await initSystemPromptCache(model, cachePathToUse, systemPromptToUse, tools && toolsEnabled ? tools : undefined);
|
|
113
132
|
}
|
|
114
133
|
const messagesToSend = prepareMessagesForCache(cachePathToUse, cacheExists, history);
|
|
115
|
-
return yield* processModelResponse(model, messagesToSend, true);
|
|
134
|
+
return yield* processModelResponse(model, messagesToSend, true, tools);
|
|
116
135
|
}
|
|
117
136
|
else {
|
|
118
137
|
// Auto-generate cache key based on conversation history
|
|
@@ -129,10 +148,10 @@ export async function* completion(params) {
|
|
|
129
148
|
: currentCacheInfo.cachePath;
|
|
130
149
|
const cacheExists = existingCache !== null;
|
|
131
150
|
if (!cacheExists) {
|
|
132
|
-
await initSystemPromptCache(model, cachePathToUse, systemPromptToUse);
|
|
151
|
+
await initSystemPromptCache(model, cachePathToUse, systemPromptToUse, tools && toolsEnabled ? tools : undefined);
|
|
133
152
|
}
|
|
134
153
|
const messagesToSend = prepareMessagesForCache(cachePathToUse, cacheExists, history);
|
|
135
|
-
const result = yield* processModelResponse(model, messagesToSend, true);
|
|
154
|
+
const result = yield* processModelResponse(model, messagesToSend, true, tools);
|
|
136
155
|
//If there was an existing cache, we rename it with new hash that includes the current message
|
|
137
156
|
if (existingCache !== null &&
|
|
138
157
|
existingCache.cachePath !== currentCacheInfo.cachePath) {
|
|
@@ -142,6 +161,6 @@ export async function* completion(params) {
|
|
|
142
161
|
}
|
|
143
162
|
}
|
|
144
163
|
else {
|
|
145
|
-
return yield* processModelResponse(model, transformedHistory, false);
|
|
164
|
+
return yield* processModelResponse(model, transformedHistory, false, tools);
|
|
146
165
|
}
|
|
147
166
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getModel } from "../../../registry/model-registry.js";
|
|
2
2
|
import { embedParamsSchema } from "../../../../../schemas/index.js";
|
|
3
|
+
import { EmbedNoEmbeddingsError, EmbedFailedError, } from "../../../../../utils/errors-server.js";
|
|
3
4
|
export async function embed(params) {
|
|
4
5
|
const { modelId, text } = embedParamsSchema.parse(params);
|
|
5
6
|
const model = getModel(modelId);
|
|
@@ -7,7 +8,7 @@ export async function embed(params) {
|
|
|
7
8
|
const rawEmbeddings = (await response.await());
|
|
8
9
|
const embeddingVector = rawEmbeddings?.[0]?.[0];
|
|
9
10
|
if (!embeddingVector || embeddingVector.length === 0) {
|
|
10
|
-
throw new
|
|
11
|
+
throw new EmbedNoEmbeddingsError();
|
|
11
12
|
}
|
|
12
13
|
return normalizeVector(embeddingVector);
|
|
13
14
|
}
|
|
@@ -16,7 +17,7 @@ export function normalizeVector(vector) {
|
|
|
16
17
|
for (let i = 0; i < vector.length; i++) {
|
|
17
18
|
const value = vector[i];
|
|
18
19
|
if (!Number.isFinite(value)) {
|
|
19
|
-
throw new
|
|
20
|
+
throw new EmbedFailedError(`NormalizeVector: non-finite value at index ${i}: ${value}`);
|
|
20
21
|
}
|
|
21
22
|
sumOfSquares += value * value;
|
|
22
23
|
}
|
|
@@ -6,7 +6,7 @@ export interface CacheMessage {
|
|
|
6
6
|
}[] | undefined;
|
|
7
7
|
}
|
|
8
8
|
export declare function extractSystemPrompt(messages: CacheMessage[]): string | null;
|
|
9
|
-
export declare function generateConfigHash(modelConfig: unknown, systemPrompt: string | null): string;
|
|
9
|
+
export declare function generateConfigHash(modelConfig: unknown, systemPrompt: string | null, tools?: unknown): string;
|
|
10
10
|
export declare function generateCacheKey(messages: CacheMessage[]): string;
|
|
11
11
|
export declare function getCacheFilePath(modelId: string, configHash: string, cacheKey: string): Promise<string>;
|
|
12
12
|
export declare function findMatchingCache(modelId: string, configHash: string, currentHistory: CacheMessage[]): Promise<{
|
|
@@ -6,9 +6,13 @@ export function extractSystemPrompt(messages) {
|
|
|
6
6
|
const systemMessage = messages.find((msg) => msg.role === "system");
|
|
7
7
|
return systemMessage ? systemMessage.content : null;
|
|
8
8
|
}
|
|
9
|
-
export function generateConfigHash(modelConfig, systemPrompt) {
|
|
9
|
+
export function generateConfigHash(modelConfig, systemPrompt, tools) {
|
|
10
10
|
const hash = crypto.createHash("sha256");
|
|
11
|
-
const configStr = JSON.stringify({
|
|
11
|
+
const configStr = JSON.stringify({
|
|
12
|
+
config: modelConfig,
|
|
13
|
+
systemPrompt,
|
|
14
|
+
tools,
|
|
15
|
+
});
|
|
12
16
|
const configBuffer = Buffer.from(configStr, "utf8");
|
|
13
17
|
hash.update(configBuffer);
|
|
14
18
|
const hashString = hash.digest("hex");
|