modelfusion 0.92.1 → 0.93.1
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 +19 -19
- package/model-function/{PromptFormat.d.ts → PromptTemplate.d.ts} +2 -2
- package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
- package/model-function/generate-image/{PromptFormatImageGenerationModel.cjs → PromptTemplateImageGenerationModel.cjs} +11 -11
- package/model-function/generate-image/PromptTemplateImageGenerationModel.d.ts +20 -0
- package/model-function/generate-image/{PromptFormatImageGenerationModel.js → PromptTemplateImageGenerationModel.js} +9 -9
- package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +6 -6
- package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +4 -4
- package/model-function/generate-structure/StructureFromTextGenerationModel.js +6 -6
- package/model-function/generate-structure/{StructureFromTextPromptFormat.d.ts → StructureFromTextPromptTemplate.d.ts} +1 -1
- package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +4 -4
- package/model-function/generate-structure/StructureFromTextStreamingModel.d.ts +2 -2
- package/model-function/generate-structure/StructureFromTextStreamingModel.js +4 -4
- package/model-function/generate-structure/index.cjs +1 -1
- package/model-function/generate-structure/index.d.ts +1 -1
- package/model-function/generate-structure/index.js +1 -1
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +2 -2
- package/model-function/generate-text/{PromptFormatTextGenerationModel.cjs → PromptTemplateTextGenerationModel.cjs} +21 -21
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +35 -0
- package/model-function/generate-text/{PromptFormatTextGenerationModel.js → PromptTemplateTextGenerationModel.js} +19 -19
- package/model-function/generate-text/PromptTemplateTextStreamingModel.cjs +38 -0
- package/model-function/generate-text/PromptTemplateTextStreamingModel.d.ts +16 -0
- package/model-function/generate-text/PromptTemplateTextStreamingModel.js +34 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
- package/model-function/generate-text/TextGenerationPromptTemplate.d.ts +11 -0
- package/model-function/generate-text/index.cjs +4 -4
- package/model-function/generate-text/index.d.ts +4 -4
- package/model-function/generate-text/index.js +4 -4
- package/model-function/generate-text/{prompt-format/AlpacaPromptFormat.cjs → prompt-template/AlpacaPromptTemplate.cjs} +5 -2
- package/model-function/generate-text/{prompt-format/AlpacaPromptFormat.d.ts → prompt-template/AlpacaPromptTemplate.d.ts} +5 -5
- package/model-function/generate-text/{prompt-format/AlpacaPromptFormat.js → prompt-template/AlpacaPromptTemplate.js} +5 -2
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.test.cjs +31 -0
- package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.test.js +29 -0
- package/model-function/generate-text/{prompt-format/ChatMLPromptFormat.cjs → prompt-template/ChatMLPromptTemplate.cjs} +5 -5
- package/model-function/generate-text/{prompt-format/ChatMLPromptFormat.d.ts → prompt-template/ChatMLPromptTemplate.d.ts} +7 -7
- package/model-function/generate-text/{prompt-format/ChatMLPromptFormat.js → prompt-template/ChatMLPromptTemplate.js} +5 -5
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.test.cjs +49 -0
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.test.js +47 -0
- package/model-function/generate-text/{prompt-format → prompt-template}/ChatPrompt.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Content.js +1 -0
- package/model-function/generate-text/{prompt-format → prompt-template}/InstructionPrompt.d.ts +7 -0
- package/model-function/generate-text/prompt-template/InstructionPrompt.js +1 -0
- package/model-function/generate-text/{prompt-format/Llama2PromptFormat.cjs → prompt-template/Llama2PromptTemplate.cjs} +8 -7
- package/model-function/generate-text/{prompt-format/Llama2PromptFormat.d.ts → prompt-template/Llama2PromptTemplate.d.ts} +7 -6
- package/model-function/generate-text/{prompt-format/Llama2PromptFormat.js → prompt-template/Llama2PromptTemplate.js} +8 -7
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.test.cjs +49 -0
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.test.d.ts +1 -0
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.test.js +47 -0
- package/model-function/generate-text/{prompt-format/TextPromptFormat.cjs → prompt-template/TextPromptTemplate.cjs} +3 -0
- package/model-function/generate-text/{prompt-format/TextPromptFormat.d.ts → prompt-template/TextPromptTemplate.d.ts} +4 -4
- package/model-function/generate-text/{prompt-format/TextPromptFormat.js → prompt-template/TextPromptTemplate.js} +3 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.test.cjs +49 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.test.d.ts +1 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.test.js +47 -0
- package/model-function/generate-text/{prompt-format/VicunaPromptFormat.d.ts → prompt-template/VicunaPromptTemplate.d.ts} +2 -2
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.test.cjs +21 -0
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.test.d.ts +1 -0
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.test.js +19 -0
- package/model-function/generate-text/{prompt-format → prompt-template}/index.cjs +6 -6
- package/model-function/generate-text/prompt-template/index.d.ts +10 -0
- package/model-function/generate-text/prompt-template/index.js +10 -0
- package/model-function/index.cjs +2 -2
- package/model-function/index.d.ts +2 -2
- package/model-function/index.js +2 -2
- package/model-provider/anthropic/{AnthropicPromptFormat.cjs → AnthropicPromptTemplate.cjs} +15 -8
- package/model-provider/anthropic/AnthropicPromptTemplate.d.ts +17 -0
- package/model-provider/anthropic/{AnthropicPromptFormat.js → AnthropicPromptTemplate.js} +15 -8
- package/model-provider/anthropic/AnthropicPromptTemplate.test.cjs +49 -0
- package/model-provider/anthropic/AnthropicPromptTemplate.test.d.ts +1 -0
- package/model-provider/anthropic/AnthropicPromptTemplate.test.js +47 -0
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +12 -12
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +9 -9
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +12 -12
- package/model-provider/anthropic/index.cjs +2 -2
- package/model-provider/anthropic/index.d.ts +1 -1
- package/model-provider/anthropic/index.js +1 -1
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +5 -5
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +4 -4
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +5 -5
- package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.d.ts +2 -2
- package/model-provider/cohere/CohereTextGenerationModel.cjs +10 -10
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +7 -7
- package/model-provider/cohere/CohereTextGenerationModel.js +10 -10
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +4 -4
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +4 -4
- package/model-provider/llamacpp/{LlamaCppBakLLaVA1Format.cjs → LlamaCppBakLLaVA1PromptTemplate.cjs} +1 -1
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.d.ts +11 -0
- package/model-provider/llamacpp/{LlamaCppBakLLaVA1Format.js → LlamaCppBakLLaVA1PromptTemplate.js} +1 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +12 -12
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +7 -7
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +12 -12
- package/model-provider/llamacpp/index.cjs +2 -2
- package/model-provider/llamacpp/index.d.ts +1 -1
- package/model-provider/llamacpp/index.js +1 -1
- package/model-provider/ollama/OllamaTextGenerationModel.cjs +9 -9
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +7 -7
- package/model-provider/ollama/OllamaTextGenerationModel.js +9 -9
- package/model-provider/openai/OpenAICompletionModel.cjs +10 -10
- package/model-provider/openai/OpenAICompletionModel.d.ts +7 -7
- package/model-provider/openai/OpenAICompletionModel.js +10 -10
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +4 -4
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +3 -3
- package/model-provider/openai/OpenAIImageGenerationModel.js +4 -4
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.cjs +16 -16
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +14 -14
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.js +16 -16
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.cjs +15 -15
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +12 -12
- package/model-provider/openai/chat/OpenAIChatModel.js +15 -15
- package/model-provider/openai/chat/{OpenAIChatPromptFormat.cjs → OpenAIChatPromptTemplate.cjs} +1 -1
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.d.ts +20 -0
- package/model-provider/openai/chat/{OpenAIChatPromptFormat.js → OpenAIChatPromptTemplate.js} +1 -1
- package/model-provider/openai/index.cjs +2 -2
- package/model-provider/openai/index.d.ts +1 -1
- package/model-provider/openai/index.js +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +14 -14
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +11 -11
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +14 -14
- package/model-provider/stability/StabilityImageGenerationModel.cjs +5 -5
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +4 -4
- package/model-provider/stability/StabilityImageGenerationModel.js +5 -5
- package/model-provider/stability/StabilityImageGenerationPrompt.d.ts +2 -2
- package/package.json +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +2 -2
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs +6 -6
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +4 -4
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js +6 -6
- package/model-function/generate-image/PromptFormatImageGenerationModel.d.ts +0 -20
- package/model-function/generate-text/PromptFormatTextGenerationModel.d.ts +0 -35
- package/model-function/generate-text/PromptFormatTextStreamingModel.cjs +0 -38
- package/model-function/generate-text/PromptFormatTextStreamingModel.d.ts +0 -16
- package/model-function/generate-text/PromptFormatTextStreamingModel.js +0 -34
- package/model-function/generate-text/TextGenerationPromptFormat.d.ts +0 -11
- package/model-function/generate-text/prompt-format/index.d.ts +0 -10
- package/model-function/generate-text/prompt-format/index.js +0 -10
- package/model-provider/anthropic/AnthropicPromptFormat.d.ts +0 -17
- package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.d.ts +0 -11
- package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +0 -20
- /package/model-function/{PromptFormat.cjs → PromptTemplate.cjs} +0 -0
- /package/model-function/{PromptFormat.js → PromptTemplate.js} +0 -0
- /package/model-function/generate-structure/{StructureFromTextPromptFormat.cjs → StructureFromTextPromptTemplate.cjs} +0 -0
- /package/model-function/generate-structure/{StructureFromTextPromptFormat.js → StructureFromTextPromptTemplate.js} +0 -0
- /package/model-function/generate-text/{TextGenerationPromptFormat.cjs → TextGenerationPromptTemplate.cjs} +0 -0
- /package/model-function/generate-text/{TextGenerationPromptFormat.js → TextGenerationPromptTemplate.js} +0 -0
- /package/model-function/generate-text/{prompt-format/Content.js → prompt-template/AlpacaPromptTemplate.test.d.ts} +0 -0
- /package/model-function/generate-text/{prompt-format/InstructionPrompt.js → prompt-template/ChatMLPromptTemplate.test.d.ts} +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/ChatPrompt.cjs +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/ChatPrompt.js +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/Content.cjs +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/Content.d.ts +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/InstructionPrompt.cjs +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/InvalidPromptError.cjs +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/InvalidPromptError.d.ts +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/InvalidPromptError.js +0 -0
- /package/model-function/generate-text/{prompt-format/VicunaPromptFormat.cjs → prompt-template/VicunaPromptTemplate.cjs} +0 -0
- /package/model-function/generate-text/{prompt-format/VicunaPromptFormat.js → prompt-template/VicunaPromptTemplate.js} +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/trimChatPrompt.cjs +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/trimChatPrompt.d.ts +0 -0
- /package/model-function/generate-text/{prompt-format → prompt-template}/trimChatPrompt.js +0 -0
@@ -1,22 +1,22 @@
|
|
1
|
-
import { StructureFromTextGenerationModel } from "../../model-function/generate-structure/StructureFromTextGenerationModel.js";
|
2
1
|
import { TextGenerationToolCallModel, } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
3
2
|
import { TextGenerationToolCallsOrGenerateTextModel, } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
4
|
-
|
5
|
-
|
3
|
+
import { StructureFromTextGenerationModel } from "../generate-structure/StructureFromTextGenerationModel.js";
|
4
|
+
export class PromptTemplateTextGenerationModel {
|
5
|
+
constructor({ model, promptTemplate, }) {
|
6
6
|
Object.defineProperty(this, "model", {
|
7
7
|
enumerable: true,
|
8
8
|
configurable: true,
|
9
9
|
writable: true,
|
10
10
|
value: void 0
|
11
11
|
});
|
12
|
-
Object.defineProperty(this, "
|
12
|
+
Object.defineProperty(this, "promptTemplate", {
|
13
13
|
enumerable: true,
|
14
14
|
configurable: true,
|
15
15
|
writable: true,
|
16
16
|
value: void 0
|
17
17
|
});
|
18
18
|
this.model = model;
|
19
|
-
this.
|
19
|
+
this.promptTemplate = promptTemplate;
|
20
20
|
}
|
21
21
|
get modelInformation() {
|
22
22
|
return this.model.modelInformation;
|
@@ -35,48 +35,48 @@ export class PromptFormatTextGenerationModel {
|
|
35
35
|
if (originalCountPromptTokens === undefined) {
|
36
36
|
return undefined;
|
37
37
|
}
|
38
|
-
return ((prompt) => originalCountPromptTokens(this.
|
38
|
+
return ((prompt) => originalCountPromptTokens(this.promptTemplate.format(prompt)));
|
39
39
|
}
|
40
40
|
doGenerateText(prompt, options) {
|
41
|
-
const mappedPrompt = this.
|
41
|
+
const mappedPrompt = this.promptTemplate.format(prompt);
|
42
42
|
return this.model.doGenerateText(mappedPrompt, options);
|
43
43
|
}
|
44
44
|
get settingsForEvent() {
|
45
45
|
return this.model.settingsForEvent;
|
46
46
|
}
|
47
|
-
asToolCallGenerationModel(
|
47
|
+
asToolCallGenerationModel(promptTemplate) {
|
48
48
|
return new TextGenerationToolCallModel({
|
49
49
|
model: this,
|
50
|
-
format:
|
50
|
+
format: promptTemplate,
|
51
51
|
});
|
52
52
|
}
|
53
|
-
asToolCallsOrTextGenerationModel(
|
53
|
+
asToolCallsOrTextGenerationModel(promptTemplate) {
|
54
54
|
return new TextGenerationToolCallsOrGenerateTextModel({
|
55
55
|
model: this,
|
56
|
-
|
56
|
+
template: promptTemplate,
|
57
57
|
});
|
58
58
|
}
|
59
|
-
asStructureGenerationModel(
|
59
|
+
asStructureGenerationModel(promptTemplate) {
|
60
60
|
return new StructureFromTextGenerationModel({
|
61
61
|
model: this,
|
62
|
-
|
62
|
+
template: promptTemplate,
|
63
63
|
});
|
64
64
|
}
|
65
|
-
|
66
|
-
return new
|
65
|
+
withPromptTemplate(promptTemplate) {
|
66
|
+
return new PromptTemplateTextGenerationModel({
|
67
67
|
model: this.withSettings({
|
68
68
|
stopSequences: [
|
69
69
|
...(this.settings.stopSequences ?? []),
|
70
|
-
...
|
70
|
+
...promptTemplate.stopSequences,
|
71
71
|
],
|
72
72
|
}),
|
73
|
-
|
73
|
+
promptTemplate,
|
74
74
|
});
|
75
75
|
}
|
76
76
|
withSettings(additionalSettings) {
|
77
|
-
return new
|
77
|
+
return new PromptTemplateTextGenerationModel({
|
78
78
|
model: this.model.withSettings(additionalSettings),
|
79
|
-
|
79
|
+
promptTemplate: this.promptTemplate,
|
80
80
|
});
|
81
81
|
}
|
82
82
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PromptTemplateTextStreamingModel = void 0;
|
4
|
+
const StructureFromTextStreamingModel_js_1 = require("../generate-structure/StructureFromTextStreamingModel.cjs");
|
5
|
+
const PromptTemplateTextGenerationModel_js_1 = require("./PromptTemplateTextGenerationModel.cjs");
|
6
|
+
class PromptTemplateTextStreamingModel extends PromptTemplateTextGenerationModel_js_1.PromptTemplateTextGenerationModel {
|
7
|
+
constructor(options) {
|
8
|
+
super(options);
|
9
|
+
}
|
10
|
+
doStreamText(prompt, options) {
|
11
|
+
const mappedPrompt = this.promptTemplate.format(prompt);
|
12
|
+
return this.model.doStreamText(mappedPrompt, options);
|
13
|
+
}
|
14
|
+
asStructureGenerationModel(promptTemplate) {
|
15
|
+
return new StructureFromTextStreamingModel_js_1.StructureFromTextStreamingModel({
|
16
|
+
model: this,
|
17
|
+
template: promptTemplate,
|
18
|
+
});
|
19
|
+
}
|
20
|
+
withPromptTemplate(promptTemplate) {
|
21
|
+
return new PromptTemplateTextStreamingModel({
|
22
|
+
model: this.withSettings({
|
23
|
+
stopSequences: [
|
24
|
+
...(this.settings.stopSequences ?? []),
|
25
|
+
...promptTemplate.stopSequences,
|
26
|
+
],
|
27
|
+
}),
|
28
|
+
promptTemplate,
|
29
|
+
});
|
30
|
+
}
|
31
|
+
withSettings(additionalSettings) {
|
32
|
+
return new PromptTemplateTextStreamingModel({
|
33
|
+
model: this.model.withSettings(additionalSettings),
|
34
|
+
promptTemplate: this.promptTemplate,
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.PromptTemplateTextStreamingModel = PromptTemplateTextStreamingModel;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
|
+
import { StructureFromTextPromptTemplate } from "../generate-structure/StructureFromTextPromptTemplate.js";
|
3
|
+
import { StructureFromTextStreamingModel } from "../generate-structure/StructureFromTextStreamingModel.js";
|
4
|
+
import { PromptTemplateTextGenerationModel } from "./PromptTemplateTextGenerationModel.js";
|
5
|
+
import { TextGenerationModelSettings, TextStreamingModel } from "./TextGenerationModel.js";
|
6
|
+
import { TextGenerationPromptTemplate } from "./TextGenerationPromptTemplate.js";
|
7
|
+
export declare class PromptTemplateTextStreamingModel<PROMPT, MODEL_PROMPT, SETTINGS extends TextGenerationModelSettings, MODEL extends TextStreamingModel<MODEL_PROMPT, SETTINGS>> extends PromptTemplateTextGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS, MODEL> implements TextStreamingModel<PROMPT, SETTINGS> {
|
8
|
+
constructor(options: {
|
9
|
+
model: MODEL;
|
10
|
+
promptTemplate: TextGenerationPromptTemplate<PROMPT, MODEL_PROMPT>;
|
11
|
+
});
|
12
|
+
doStreamText(prompt: PROMPT, options?: FunctionOptions): PromiseLike<AsyncIterable<import("../Delta.js").Delta<string>>>;
|
13
|
+
asStructureGenerationModel<INPUT_PROMPT>(promptTemplate: StructureFromTextPromptTemplate<INPUT_PROMPT, PROMPT>): StructureFromTextStreamingModel<INPUT_PROMPT, PROMPT, this>;
|
14
|
+
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, PROMPT>): PromptTemplateTextStreamingModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
|
15
|
+
withSettings(additionalSettings: Partial<SETTINGS>): this;
|
16
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { StructureFromTextStreamingModel } from "../generate-structure/StructureFromTextStreamingModel.js";
|
2
|
+
import { PromptTemplateTextGenerationModel } from "./PromptTemplateTextGenerationModel.js";
|
3
|
+
export class PromptTemplateTextStreamingModel extends PromptTemplateTextGenerationModel {
|
4
|
+
constructor(options) {
|
5
|
+
super(options);
|
6
|
+
}
|
7
|
+
doStreamText(prompt, options) {
|
8
|
+
const mappedPrompt = this.promptTemplate.format(prompt);
|
9
|
+
return this.model.doStreamText(mappedPrompt, options);
|
10
|
+
}
|
11
|
+
asStructureGenerationModel(promptTemplate) {
|
12
|
+
return new StructureFromTextStreamingModel({
|
13
|
+
model: this,
|
14
|
+
template: promptTemplate,
|
15
|
+
});
|
16
|
+
}
|
17
|
+
withPromptTemplate(promptTemplate) {
|
18
|
+
return new PromptTemplateTextStreamingModel({
|
19
|
+
model: this.withSettings({
|
20
|
+
stopSequences: [
|
21
|
+
...(this.settings.stopSequences ?? []),
|
22
|
+
...promptTemplate.stopSequences,
|
23
|
+
],
|
24
|
+
}),
|
25
|
+
promptTemplate,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
withSettings(additionalSettings) {
|
29
|
+
return new PromptTemplateTextStreamingModel({
|
30
|
+
model: this.model.withSettings(additionalSettings),
|
31
|
+
promptTemplate: this.promptTemplate,
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
@@ -2,7 +2,7 @@ import { FunctionOptions } from "../../core/FunctionOptions.js";
|
|
2
2
|
import { Delta } from "../Delta.js";
|
3
3
|
import { Model, ModelSettings } from "../Model.js";
|
4
4
|
import { BasicTokenizer, FullTokenizer } from "../tokenize-text/Tokenizer.js";
|
5
|
-
import {
|
5
|
+
import { TextGenerationPromptTemplate } from "./TextGenerationPromptTemplate.js";
|
6
6
|
export interface TextGenerationModelSettings extends ModelSettings {
|
7
7
|
/**
|
8
8
|
* Maximum number of tokens to generate.
|
@@ -43,9 +43,9 @@ export interface TextGenerationModel<PROMPT, SETTINGS extends TextGenerationMode
|
|
43
43
|
totalTokens: number;
|
44
44
|
};
|
45
45
|
}>;
|
46
|
-
|
46
|
+
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, PROMPT>): TextGenerationModel<INPUT_PROMPT, SETTINGS>;
|
47
47
|
}
|
48
48
|
export interface TextStreamingModel<PROMPT, SETTINGS extends TextGenerationModelSettings = TextGenerationModelSettings> extends TextGenerationModel<PROMPT, SETTINGS> {
|
49
49
|
doStreamText(prompt: PROMPT, options?: FunctionOptions): PromiseLike<AsyncIterable<Delta<string>>>;
|
50
|
-
|
50
|
+
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, PROMPT>): TextStreamingModel<INPUT_PROMPT, SETTINGS>;
|
51
51
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { PromptTemplate } from "../PromptTemplate.js";
|
2
|
+
/**
|
3
|
+
* Prompt templates format a source prompt into the structure of a target prompt.
|
4
|
+
*/
|
5
|
+
export interface TextGenerationPromptTemplate<SOURCE_PROMPT, TARGET_PROMPT> extends PromptTemplate<SOURCE_PROMPT, TARGET_PROMPT> {
|
6
|
+
/**
|
7
|
+
* The texts that should be used as default stop sequences.
|
8
|
+
* This is e.g. important for chat formats.
|
9
|
+
*/
|
10
|
+
stopSequences: string[];
|
11
|
+
}
|
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./
|
18
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./PromptTemplateTextGenerationModel.cjs"), exports);
|
18
|
+
__exportStar(require("./PromptTemplateTextStreamingModel.cjs"), exports);
|
19
19
|
__exportStar(require("./TextGenerationEvent.cjs"), exports);
|
20
20
|
__exportStar(require("./TextGenerationModel.cjs"), exports);
|
21
|
-
__exportStar(require("./
|
21
|
+
__exportStar(require("./TextGenerationPromptTemplate.cjs"), exports);
|
22
22
|
__exportStar(require("./generateText.cjs"), exports);
|
23
|
-
__exportStar(require("./prompt-
|
23
|
+
__exportStar(require("./prompt-template/index.cjs"), exports);
|
24
24
|
__exportStar(require("./streamText.cjs"), exports);
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export * from "./
|
2
|
-
export * from "./
|
1
|
+
export * from "./PromptTemplateTextGenerationModel.js";
|
2
|
+
export * from "./PromptTemplateTextStreamingModel.js";
|
3
3
|
export * from "./TextGenerationEvent.js";
|
4
4
|
export * from "./TextGenerationModel.js";
|
5
|
-
export * from "./
|
5
|
+
export * from "./TextGenerationPromptTemplate.js";
|
6
6
|
export * from "./generateText.js";
|
7
|
-
export * from "./prompt-
|
7
|
+
export * from "./prompt-template/index.js";
|
8
8
|
export * from "./streamText.js";
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export * from "./
|
2
|
-
export * from "./
|
1
|
+
export * from "./PromptTemplateTextGenerationModel.js";
|
2
|
+
export * from "./PromptTemplateTextStreamingModel.js";
|
3
3
|
export * from "./TextGenerationEvent.js";
|
4
4
|
export * from "./TextGenerationModel.js";
|
5
|
-
export * from "./
|
5
|
+
export * from "./TextGenerationPromptTemplate.js";
|
6
6
|
export * from "./generateText.js";
|
7
|
-
export * from "./prompt-
|
7
|
+
export * from "./prompt-template/index.js";
|
8
8
|
export * from "./streamText.js";
|
@@ -25,7 +25,7 @@ exports.text = text;
|
|
25
25
|
* If the instruction has a system prompt, it overrides the default system prompt
|
26
26
|
* (which can impact the results, because the model may be trained on the default system prompt).
|
27
27
|
*
|
28
|
-
* Prompt
|
28
|
+
* Prompt template with input:
|
29
29
|
* ```
|
30
30
|
* Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
31
31
|
*
|
@@ -41,7 +41,7 @@ exports.text = text;
|
|
41
41
|
*
|
42
42
|
* ```
|
43
43
|
*
|
44
|
-
* Prompt
|
44
|
+
* Prompt template without input:
|
45
45
|
* ```
|
46
46
|
* Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
47
47
|
*
|
@@ -72,6 +72,9 @@ function instruction() {
|
|
72
72
|
text += `\n\n### Input:\n${prompt.input}`;
|
73
73
|
}
|
74
74
|
text += "\n\n### Response:\n";
|
75
|
+
if (prompt.responsePrefix != null) {
|
76
|
+
text += `${prompt.responsePrefix}\n`;
|
77
|
+
}
|
75
78
|
return text;
|
76
79
|
},
|
77
80
|
};
|
@@ -1,16 +1,16 @@
|
|
1
|
-
import {
|
1
|
+
import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
|
2
2
|
import { TextInstructionPrompt } from "./InstructionPrompt.js";
|
3
3
|
/**
|
4
4
|
* Formats a text prompt as an Alpaca prompt.
|
5
5
|
*/
|
6
|
-
export declare function text():
|
6
|
+
export declare function text(): TextGenerationPromptTemplate<string, string>;
|
7
7
|
/**
|
8
8
|
* Formats an instruction prompt as an Alpaca prompt.
|
9
9
|
*
|
10
10
|
* If the instruction has a system prompt, it overrides the default system prompt
|
11
11
|
* (which can impact the results, because the model may be trained on the default system prompt).
|
12
12
|
*
|
13
|
-
* Prompt
|
13
|
+
* Prompt template with input:
|
14
14
|
* ```
|
15
15
|
* Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
16
16
|
*
|
@@ -26,7 +26,7 @@ export declare function text(): TextGenerationPromptFormat<string, string>;
|
|
26
26
|
*
|
27
27
|
* ```
|
28
28
|
*
|
29
|
-
* Prompt
|
29
|
+
* Prompt template without input:
|
30
30
|
* ```
|
31
31
|
* Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
32
32
|
*
|
@@ -40,7 +40,7 @@ export declare function text(): TextGenerationPromptFormat<string, string>;
|
|
40
40
|
*
|
41
41
|
* @see https://github.com/tatsu-lab/stanford_alpaca#data-release
|
42
42
|
*/
|
43
|
-
export declare function instruction():
|
43
|
+
export declare function instruction(): TextGenerationPromptTemplate<TextInstructionPrompt & {
|
44
44
|
input?: string;
|
45
45
|
}, // optional input supported by Alpaca
|
46
46
|
string>;
|
@@ -21,7 +21,7 @@ export function text() {
|
|
21
21
|
* If the instruction has a system prompt, it overrides the default system prompt
|
22
22
|
* (which can impact the results, because the model may be trained on the default system prompt).
|
23
23
|
*
|
24
|
-
* Prompt
|
24
|
+
* Prompt template with input:
|
25
25
|
* ```
|
26
26
|
* Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
27
27
|
*
|
@@ -37,7 +37,7 @@ export function text() {
|
|
37
37
|
*
|
38
38
|
* ```
|
39
39
|
*
|
40
|
-
* Prompt
|
40
|
+
* Prompt template without input:
|
41
41
|
* ```
|
42
42
|
* Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
43
43
|
*
|
@@ -68,6 +68,9 @@ export function instruction() {
|
|
68
68
|
text += `\n\n### Input:\n${prompt.input}`;
|
69
69
|
}
|
70
70
|
text += "\n\n### Response:\n";
|
71
|
+
if (prompt.responsePrefix != null) {
|
72
|
+
text += `${prompt.responsePrefix}\n`;
|
73
|
+
}
|
71
74
|
return text;
|
72
75
|
},
|
73
76
|
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const AlpacaPromptTemplate_js_1 = require("./AlpacaPromptTemplate.cjs");
|
4
|
+
describe("text prompt", () => {
|
5
|
+
it("should format prompt", () => {
|
6
|
+
const prompt = (0, AlpacaPromptTemplate_js_1.text)().format("prompt");
|
7
|
+
expect(prompt).toMatchSnapshot();
|
8
|
+
});
|
9
|
+
});
|
10
|
+
describe("instruction prompt", () => {
|
11
|
+
it("should format prompt with instruction", () => {
|
12
|
+
const prompt = (0, AlpacaPromptTemplate_js_1.instruction)().format({
|
13
|
+
instruction: "instruction",
|
14
|
+
});
|
15
|
+
expect(prompt).toMatchSnapshot();
|
16
|
+
});
|
17
|
+
it("should format prompt with system and instruction", () => {
|
18
|
+
const prompt = (0, AlpacaPromptTemplate_js_1.instruction)().format({
|
19
|
+
system: "system",
|
20
|
+
instruction: "instruction",
|
21
|
+
});
|
22
|
+
expect(prompt).toMatchSnapshot();
|
23
|
+
});
|
24
|
+
it("should format prompt with instruction and response prefix", () => {
|
25
|
+
const prompt = (0, AlpacaPromptTemplate_js_1.instruction)().format({
|
26
|
+
instruction: "instruction",
|
27
|
+
responsePrefix: "response prefix",
|
28
|
+
});
|
29
|
+
expect(prompt).toMatchSnapshot();
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { instruction, text } from "./AlpacaPromptTemplate.js";
|
2
|
+
describe("text prompt", () => {
|
3
|
+
it("should format prompt", () => {
|
4
|
+
const prompt = text().format("prompt");
|
5
|
+
expect(prompt).toMatchSnapshot();
|
6
|
+
});
|
7
|
+
});
|
8
|
+
describe("instruction prompt", () => {
|
9
|
+
it("should format prompt with instruction", () => {
|
10
|
+
const prompt = instruction().format({
|
11
|
+
instruction: "instruction",
|
12
|
+
});
|
13
|
+
expect(prompt).toMatchSnapshot();
|
14
|
+
});
|
15
|
+
it("should format prompt with system and instruction", () => {
|
16
|
+
const prompt = instruction().format({
|
17
|
+
system: "system",
|
18
|
+
instruction: "instruction",
|
19
|
+
});
|
20
|
+
expect(prompt).toMatchSnapshot();
|
21
|
+
});
|
22
|
+
it("should format prompt with instruction and response prefix", () => {
|
23
|
+
const prompt = instruction().format({
|
24
|
+
instruction: "instruction",
|
25
|
+
responsePrefix: "response prefix",
|
26
|
+
});
|
27
|
+
expect(prompt).toMatchSnapshot();
|
28
|
+
});
|
29
|
+
});
|
@@ -29,11 +29,11 @@ exports.text = text;
|
|
29
29
|
* ChatML prompt template:
|
30
30
|
* ```
|
31
31
|
* <|im_start|>system
|
32
|
-
*
|
32
|
+
* ${ system prompt }<|im_end|>
|
33
33
|
* <|im_start|>user
|
34
|
-
*
|
34
|
+
* ${ instruction }<|im_end|>
|
35
35
|
* <|im_start|>assistant
|
36
|
-
*
|
36
|
+
* ${response prefix}
|
37
37
|
* ```
|
38
38
|
*/
|
39
39
|
function instruction() {
|
@@ -42,8 +42,8 @@ function instruction() {
|
|
42
42
|
format(prompt) {
|
43
43
|
return (chatMLSegment("system", prompt.system) +
|
44
44
|
chatMLSegment("user", prompt.instruction) +
|
45
|
-
chatMLStart("assistant")
|
46
|
-
|
45
|
+
chatMLStart("assistant") +
|
46
|
+
(prompt.responsePrefix ?? ""));
|
47
47
|
},
|
48
48
|
};
|
49
49
|
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
import {
|
1
|
+
import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
|
2
2
|
import { TextChatPrompt } from "./ChatPrompt.js";
|
3
3
|
import { TextInstructionPrompt } from "./InstructionPrompt.js";
|
4
4
|
/**
|
5
5
|
* Formats a text prompt using the ChatML format.
|
6
6
|
*/
|
7
|
-
export declare function text():
|
7
|
+
export declare function text(): TextGenerationPromptTemplate<string, string>;
|
8
8
|
/**
|
9
9
|
* Formats an instruction prompt using the ChatML format.
|
10
10
|
*
|
11
11
|
* ChatML prompt template:
|
12
12
|
* ```
|
13
13
|
* <|im_start|>system
|
14
|
-
*
|
14
|
+
* ${ system prompt }<|im_end|>
|
15
15
|
* <|im_start|>user
|
16
|
-
*
|
16
|
+
* ${ instruction }<|im_end|>
|
17
17
|
* <|im_start|>assistant
|
18
|
-
*
|
18
|
+
* ${response prefix}
|
19
19
|
* ```
|
20
20
|
*/
|
21
|
-
export declare function instruction():
|
21
|
+
export declare function instruction(): TextGenerationPromptTemplate<TextInstructionPrompt, string>;
|
22
22
|
/**
|
23
23
|
* Formats a chat prompt using the ChatML format.
|
24
24
|
*
|
@@ -32,4 +32,4 @@ export declare function instruction(): TextGenerationPromptFormat<TextInstructio
|
|
32
32
|
* Paris<|im_end|>
|
33
33
|
* ```
|
34
34
|
*/
|
35
|
-
export declare function chat():
|
35
|
+
export declare function chat(): TextGenerationPromptTemplate<TextChatPrompt, string>;
|
@@ -25,11 +25,11 @@ export function text() {
|
|
25
25
|
* ChatML prompt template:
|
26
26
|
* ```
|
27
27
|
* <|im_start|>system
|
28
|
-
*
|
28
|
+
* ${ system prompt }<|im_end|>
|
29
29
|
* <|im_start|>user
|
30
|
-
*
|
30
|
+
* ${ instruction }<|im_end|>
|
31
31
|
* <|im_start|>assistant
|
32
|
-
*
|
32
|
+
* ${response prefix}
|
33
33
|
* ```
|
34
34
|
*/
|
35
35
|
export function instruction() {
|
@@ -38,8 +38,8 @@ export function instruction() {
|
|
38
38
|
format(prompt) {
|
39
39
|
return (chatMLSegment("system", prompt.system) +
|
40
40
|
chatMLSegment("user", prompt.instruction) +
|
41
|
-
chatMLStart("assistant")
|
42
|
-
|
41
|
+
chatMLStart("assistant") +
|
42
|
+
(prompt.responsePrefix ?? ""));
|
43
43
|
},
|
44
44
|
};
|
45
45
|
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const ChatMLPromptTemplate_js_1 = require("./ChatMLPromptTemplate.cjs");
|
4
|
+
describe("text prompt", () => {
|
5
|
+
it("should format prompt", () => {
|
6
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.text)().format("prompt");
|
7
|
+
expect(prompt).toMatchSnapshot();
|
8
|
+
});
|
9
|
+
});
|
10
|
+
describe("instruction prompt", () => {
|
11
|
+
it("should format prompt with instruction", () => {
|
12
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.instruction)().format({
|
13
|
+
instruction: "instruction",
|
14
|
+
});
|
15
|
+
expect(prompt).toMatchSnapshot();
|
16
|
+
});
|
17
|
+
it("should format prompt with system and instruction", () => {
|
18
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.instruction)().format({
|
19
|
+
system: "system",
|
20
|
+
instruction: "instruction",
|
21
|
+
});
|
22
|
+
expect(prompt).toMatchSnapshot();
|
23
|
+
});
|
24
|
+
it("should format prompt with instruction and response prefix", () => {
|
25
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.instruction)().format({
|
26
|
+
instruction: "instruction",
|
27
|
+
responsePrefix: "response prefix",
|
28
|
+
});
|
29
|
+
expect(prompt).toMatchSnapshot();
|
30
|
+
});
|
31
|
+
});
|
32
|
+
describe("chat prompt", () => {
|
33
|
+
it("should format prompt with user message", () => {
|
34
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.chat)().format({
|
35
|
+
messages: [{ role: "user", content: "user message" }],
|
36
|
+
});
|
37
|
+
expect(prompt).toMatchSnapshot();
|
38
|
+
});
|
39
|
+
it("should format prompt with user-assistant-user messages", () => {
|
40
|
+
const prompt = (0, ChatMLPromptTemplate_js_1.chat)().format({
|
41
|
+
messages: [
|
42
|
+
{ role: "user", content: "1st user message" },
|
43
|
+
{ role: "assistant", content: "assistant message" },
|
44
|
+
{ role: "user", content: "2nd user message" },
|
45
|
+
],
|
46
|
+
});
|
47
|
+
expect(prompt).toMatchSnapshot();
|
48
|
+
});
|
49
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { chat, instruction, text } from "./ChatMLPromptTemplate.js";
|
2
|
+
describe("text prompt", () => {
|
3
|
+
it("should format prompt", () => {
|
4
|
+
const prompt = text().format("prompt");
|
5
|
+
expect(prompt).toMatchSnapshot();
|
6
|
+
});
|
7
|
+
});
|
8
|
+
describe("instruction prompt", () => {
|
9
|
+
it("should format prompt with instruction", () => {
|
10
|
+
const prompt = instruction().format({
|
11
|
+
instruction: "instruction",
|
12
|
+
});
|
13
|
+
expect(prompt).toMatchSnapshot();
|
14
|
+
});
|
15
|
+
it("should format prompt with system and instruction", () => {
|
16
|
+
const prompt = instruction().format({
|
17
|
+
system: "system",
|
18
|
+
instruction: "instruction",
|
19
|
+
});
|
20
|
+
expect(prompt).toMatchSnapshot();
|
21
|
+
});
|
22
|
+
it("should format prompt with instruction and response prefix", () => {
|
23
|
+
const prompt = instruction().format({
|
24
|
+
instruction: "instruction",
|
25
|
+
responsePrefix: "response prefix",
|
26
|
+
});
|
27
|
+
expect(prompt).toMatchSnapshot();
|
28
|
+
});
|
29
|
+
});
|
30
|
+
describe("chat prompt", () => {
|
31
|
+
it("should format prompt with user message", () => {
|
32
|
+
const prompt = chat().format({
|
33
|
+
messages: [{ role: "user", content: "user message" }],
|
34
|
+
});
|
35
|
+
expect(prompt).toMatchSnapshot();
|
36
|
+
});
|
37
|
+
it("should format prompt with user-assistant-user messages", () => {
|
38
|
+
const prompt = chat().format({
|
39
|
+
messages: [
|
40
|
+
{ role: "user", content: "1st user message" },
|
41
|
+
{ role: "assistant", content: "assistant message" },
|
42
|
+
{ role: "user", content: "2nd user message" },
|
43
|
+
],
|
44
|
+
});
|
45
|
+
expect(prompt).toMatchSnapshot();
|
46
|
+
});
|
47
|
+
});
|
@@ -9,7 +9,7 @@ import { MultiModalInput } from "./Content.js";
|
|
9
9
|
*
|
10
10
|
* You can use a ChatPrompt without an final user message when you e.g. want to display the current state of a conversation.
|
11
11
|
*
|
12
|
-
* The type checking is done at runtime when you submit a chat prompt to a model with a prompt
|
12
|
+
* The type checking is done at runtime when you submit a chat prompt to a model with a prompt template.
|
13
13
|
*
|
14
14
|
* @example
|
15
15
|
* ```ts
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/model-function/generate-text/{prompt-format → prompt-template}/InstructionPrompt.d.ts
RENAMED
@@ -37,4 +37,11 @@ export interface TextInstructionPrompt {
|
|
37
37
|
* The text instruction for the model.
|
38
38
|
*/
|
39
39
|
instruction: string;
|
40
|
+
/**
|
41
|
+
* Response prefix that will be injected in the prompt at the beginning of the response.
|
42
|
+
* This is useful for guiding the model by starting its response with a specific text.
|
43
|
+
*
|
44
|
+
* Note: Not all models support this feature. E.g. it is not supported by OpenAI chat models.
|
45
|
+
*/
|
46
|
+
responsePrefix?: string;
|
40
47
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|