node-llama-cpp 3.4.3 → 3.6.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 +2 -2
- package/dist/ChatWrapper.js +45 -0
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.js +2 -0
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/chatWrappers/DeepSeekChatWrapper.d.ts +37 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js +294 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js +39 -13
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +0 -3
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +5 -4
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +1 -1
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -1
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +10 -1
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +8 -2
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -1
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +17 -1
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +10 -2
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -1
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.d.ts +22 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js +28 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +46 -3
- package/dist/chatWrappers/utils/resolveChatWrapper.js +6 -2
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -1
- package/dist/cli/commands/ChatCommand.js +38 -7
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/PullCommand.js +2 -1
- package/dist/cli/commands/PullCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +18 -5
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +16 -5
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -1
- package/dist/cli/recommendedModels.js +137 -67
- package/dist/cli/recommendedModels.js.map +1 -1
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +8 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +45 -1
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -1
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +2 -2
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +87 -5
- package/dist/evaluator/LlamaChat/LlamaChat.js +770 -194
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +55 -1
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +22 -7
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +28 -8
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +1 -1
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +9 -2
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.js +61 -48
- package/dist/evaluator/LlamaCompletion.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.d.ts +2 -2
- package/dist/evaluator/LlamaGrammar.js +2 -2
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +1 -1
- package/dist/evaluator/LlamaModel/LlamaModel.js +1 -1
- package/dist/gguf/readGgufFileInfo.js +7 -4
- package/dist/gguf/readGgufFileInfo.js.map +1 -1
- package/dist/gguf/types/GgufMetadataTypes.d.ts +2 -2
- package/dist/gguf/types/GgufMetadataTypes.js +2 -2
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -1
- package/dist/gguf/utils/getGgufFileTypeName.d.ts +1 -1
- package/dist/gguf/utils/ggufQuantNames.d.ts +2 -0
- package/dist/gguf/utils/ggufQuantNames.js +40 -0
- package/dist/gguf/utils/ggufQuantNames.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +1 -1
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -1
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +1 -2
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +32 -2
- package/dist/types.js +7 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/LlamaText.js +8 -9
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/TokenStreamRegulator.d.ts +2 -0
- package/dist/utils/TokenStreamRegulator.js +12 -0
- package/dist/utils/TokenStreamRegulator.js.map +1 -1
- package/dist/utils/createModelDownloader.d.ts +21 -4
- package/dist/utils/createModelDownloader.js +83 -36
- package/dist/utils/createModelDownloader.js.map +1 -1
- package/dist/utils/getChatWrapperSegmentDefinition.d.ts +2 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js +7 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js.map +1 -0
- package/dist/utils/modelFileAccesTokens.js +1 -1
- package/dist/utils/modelFileAccesTokens.js.map +1 -1
- package/dist/utils/parseModelFileName.d.ts +5 -0
- package/dist/utils/parseModelFileName.js +63 -4
- package/dist/utils/parseModelFileName.js.map +1 -1
- package/dist/utils/parseModelUri.d.ts +30 -2
- package/dist/utils/parseModelUri.js +199 -24
- package/dist/utils/parseModelUri.js.map +1 -1
- package/dist/utils/resolveModelDestination.d.ts +4 -3
- package/dist/utils/resolveModelDestination.js +25 -2
- package/dist/utils/resolveModelDestination.js.map +1 -1
- package/dist/utils/resolveModelFile.d.ts +1 -1
- package/dist/utils/resolveModelFile.js +61 -20
- package/dist/utils/resolveModelFile.js.map +1 -1
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/grammars/README.md +4 -4
- package/llama/llama.cpp.info.json +2 -2
- package/package.json +36 -35
- package/templates/packed/electron-typescript-react.json +1 -1
- package/templates/packed/node-typescript.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { EventRelay } from "lifecycle-utils";
|
|
2
2
|
import { ChatWrapper } from "../../ChatWrapper.js";
|
|
3
3
|
import { LlamaContextSequence } from "../LlamaContext/LlamaContext.js";
|
|
4
|
-
import { ChatHistoryItem, ChatModelFunctions, LLamaContextualRepeatPenalty, Token, Tokenizer } from "../../types.js";
|
|
4
|
+
import { ChatHistoryItem, ChatModelFunctions, ChatModelSegmentType, LLamaContextualRepeatPenalty, Token, Tokenizer } from "../../types.js";
|
|
5
5
|
import { GbnfJsonSchemaToType } from "../../utils/gbnfJson/types.js";
|
|
6
6
|
import { LlamaGrammar } from "../LlamaGrammar.js";
|
|
7
7
|
import { LlamaText, LlamaTextJSON } from "../../utils/LlamaText.js";
|
|
8
8
|
import { EvaluationPriority } from "../LlamaContext/types.js";
|
|
9
9
|
import { TokenBias } from "../TokenBias.js";
|
|
10
|
+
import { LlamaModel } from "../LlamaModel/LlamaModel.js";
|
|
10
11
|
export type LlamaChatOptions = {
|
|
11
12
|
contextSequence: LlamaContextSequence;
|
|
12
13
|
/** `"auto"` is used by default */
|
|
@@ -18,19 +19,84 @@ export type LlamaChatOptions = {
|
|
|
18
19
|
*/
|
|
19
20
|
autoDisposeSequence?: boolean;
|
|
20
21
|
};
|
|
22
|
+
export type LlamaChatResponseChunk = LlamaChatResponseTextChunk | LlamaChatResponseSegmentChunk;
|
|
23
|
+
export type LlamaChatResponseTextChunk = {
|
|
24
|
+
/** When `type` is `undefined`, the chunk is part of the main response and is not a segment */
|
|
25
|
+
type: undefined;
|
|
26
|
+
/**
|
|
27
|
+
* `segmentType` has no purpose when `type` is `undefined` (meaning that this chunk is part of the main response and is not a segment).
|
|
28
|
+
*/
|
|
29
|
+
segmentType: undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The generated text chunk.
|
|
32
|
+
*
|
|
33
|
+
* Detokenized from the `tokens` property,
|
|
34
|
+
* but with the context of the previous generation (for better spacing of the text with some models).
|
|
35
|
+
*
|
|
36
|
+
* Prefer using this property over `tokens` when streaming the generated response as text.
|
|
37
|
+
*/
|
|
38
|
+
text: string;
|
|
39
|
+
/** The generated tokens */
|
|
40
|
+
tokens: Token[];
|
|
41
|
+
};
|
|
42
|
+
export type LlamaChatResponseSegmentChunk = {
|
|
43
|
+
type: "segment";
|
|
44
|
+
/** Segment type */
|
|
45
|
+
segmentType: ChatModelSegmentType;
|
|
46
|
+
/**
|
|
47
|
+
* The generated text chunk.
|
|
48
|
+
*
|
|
49
|
+
* Detokenized from the `tokens` property,
|
|
50
|
+
* but with the context of the previous generation (for better spacing of the text with some models).
|
|
51
|
+
*
|
|
52
|
+
* Prefer using this property over `tokens` when streaming the generated response as text.
|
|
53
|
+
*/
|
|
54
|
+
text: string;
|
|
55
|
+
/** The generated tokens */
|
|
56
|
+
tokens: Token[];
|
|
57
|
+
/**
|
|
58
|
+
* When the current chunk is the start of a segment, this field will be set.
|
|
59
|
+
*
|
|
60
|
+
* It's possible that a chunk with no tokens and empty text will be emitted just to set this field
|
|
61
|
+
* to signify that the segment has started.
|
|
62
|
+
*/
|
|
63
|
+
segmentStartTime?: Date;
|
|
64
|
+
/**
|
|
65
|
+
* When the current chunk is the last one of a segment (meaning the current segment has ended), this field will be set.
|
|
66
|
+
*
|
|
67
|
+
* It's possible that a chunk with no tokens and empty text will be emitted just to set this field
|
|
68
|
+
* to signify that the segment has ended.
|
|
69
|
+
*/
|
|
70
|
+
segmentEndTime?: Date;
|
|
71
|
+
};
|
|
21
72
|
export type LLamaChatGenerateResponseOptions<Functions extends ChatModelFunctions | undefined = undefined> = {
|
|
22
73
|
/**
|
|
23
|
-
* Called as the model generates
|
|
74
|
+
* Called as the model generates the main response with the generated text chunk.
|
|
24
75
|
*
|
|
25
76
|
* Useful for streaming the generated response as it's being generated.
|
|
77
|
+
*
|
|
78
|
+
* Includes only the main response without any text segments (like thoughts).
|
|
79
|
+
* For streaming the response with segments, use {@link onResponseChunk `onResponseChunk`}.
|
|
26
80
|
*/
|
|
27
81
|
onTextChunk?: (text: string) => void;
|
|
28
82
|
/**
|
|
29
|
-
* Called as the model generates
|
|
83
|
+
* Called as the model generates the main response with the generated tokens.
|
|
30
84
|
*
|
|
31
|
-
* Preferably, you'd want to use `onTextChunk` instead of this.
|
|
85
|
+
* Preferably, you'd want to use {@link onTextChunk `onTextChunk`} instead of this.
|
|
86
|
+
*
|
|
87
|
+
* Includes only the main response without any segments (like thoughts).
|
|
88
|
+
* For streaming the response with segments, use {@link onResponseChunk `onResponseChunk`}.
|
|
32
89
|
*/
|
|
33
90
|
onToken?: (tokens: Token[]) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Called as the model generates a response with the generated text and tokens,
|
|
93
|
+
* including segment information (when the generated output is part of a segment).
|
|
94
|
+
*
|
|
95
|
+
* Useful for streaming the generated response as it's being generated, including the main response and all segments.
|
|
96
|
+
*
|
|
97
|
+
* Only use this function when you need the segmented texts, like thought segments (chain of thought text).
|
|
98
|
+
*/
|
|
99
|
+
onResponseChunk?: (chunk: LlamaChatResponseChunk) => void;
|
|
34
100
|
signal?: AbortSignal;
|
|
35
101
|
/**
|
|
36
102
|
* When a response already started being generated and then the signal is aborted,
|
|
@@ -247,12 +313,19 @@ export declare class LlamaChat {
|
|
|
247
313
|
get chatWrapper(): ChatWrapper;
|
|
248
314
|
get sequence(): LlamaContextSequence;
|
|
249
315
|
get context(): import("../LlamaContext/LlamaContext.js").LlamaContext;
|
|
250
|
-
get model():
|
|
316
|
+
get model(): LlamaModel;
|
|
251
317
|
generateResponse<const Functions extends ChatModelFunctions | undefined = undefined>(history: ChatHistoryItem[], options?: LLamaChatGenerateResponseOptions<Functions>): Promise<LlamaChatResponse<Functions>>;
|
|
252
318
|
loadChatAndCompleteUserMessage<const Functions extends ChatModelFunctions | undefined = undefined>(history: ChatHistoryItem[], options?: LLamaChatLoadAndCompleteUserMessageOptions<Functions>): Promise<LlamaChatLoadAndCompleteUserResponse>;
|
|
253
319
|
}
|
|
254
320
|
export type LlamaChatResponse<Functions extends ChatModelFunctions | undefined = undefined> = {
|
|
321
|
+
/**
|
|
322
|
+
* The response text only, _without_ any text segments (like thoughts).
|
|
323
|
+
*/
|
|
255
324
|
response: string;
|
|
325
|
+
/**
|
|
326
|
+
* The full response, including all text and text segments (like thoughts).
|
|
327
|
+
*/
|
|
328
|
+
fullResponse: Array<string | LlamaChatResponseSegment>;
|
|
256
329
|
functionCalls?: Functions extends ChatModelFunctions ? LlamaChatResponseFunctionCall<Functions>[] : never;
|
|
257
330
|
lastEvaluation: {
|
|
258
331
|
cleanHistory: ChatHistoryItem[];
|
|
@@ -273,6 +346,15 @@ export type LlamaChatResponseFunctionCall<Functions extends ChatModelFunctions,
|
|
|
273
346
|
params: Params;
|
|
274
347
|
raw: LlamaTextJSON;
|
|
275
348
|
};
|
|
349
|
+
export type LlamaChatResponseSegment = {
|
|
350
|
+
type: "segment";
|
|
351
|
+
segmentType: ChatModelSegmentType;
|
|
352
|
+
text: string;
|
|
353
|
+
ended: boolean;
|
|
354
|
+
raw: LlamaTextJSON;
|
|
355
|
+
startTime?: string;
|
|
356
|
+
endTime?: string;
|
|
357
|
+
};
|
|
276
358
|
export type LlamaChatLoadAndCompleteUserResponse = {
|
|
277
359
|
completion: string;
|
|
278
360
|
lastEvaluation: {
|