modelfusion 0.13.0 → 0.14.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 +5 -5
- package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.cjs +5 -5
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.js +5 -5
- 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/LlamaCppTextGenerationModel.cjs +5 -5
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +5 -5
- package/model-provider/openai/OpenAITextGenerationModel.cjs +5 -5
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
- package/model-provider/openai/OpenAITextGenerationModel.js +5 -5
- package/model-provider/openai/chat/OpenAIChatModel.cjs +5 -5
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.js +5 -5
- package/package.json +1 -1
- package/prompt/{AlpacaPromptMapping.cjs → AlpacaPromptFormat.cjs} +5 -5
- package/prompt/{AlpacaPromptMapping.d.ts → AlpacaPromptFormat.d.ts} +3 -3
- package/prompt/{AlpacaPromptMapping.js → AlpacaPromptFormat.js} +3 -3
- package/prompt/{Llama2PromptMapping.cjs → Llama2PromptFormat.cjs} +11 -8
- package/prompt/Llama2PromptFormat.d.ts +13 -0
- package/prompt/{Llama2PromptMapping.js → Llama2PromptFormat.js} +8 -5
- package/prompt/{OpenAIChatPromptMapping.cjs → OpenAIChatPromptFormat.cjs} +13 -7
- package/prompt/OpenAIChatPromptFormat.d.ts +12 -0
- package/prompt/{OpenAIChatPromptMapping.js → OpenAIChatPromptFormat.js} +10 -4
- package/prompt/PromptFormat.d.ts +14 -0
- package/prompt/{PromptMappingTextGenerationModel.cjs → PromptFormatTextGenerationModel.cjs} +19 -19
- package/prompt/{PromptMappingTextGenerationModel.d.ts → PromptFormatTextGenerationModel.d.ts} +6 -6
- package/prompt/{PromptMappingTextGenerationModel.js → PromptFormatTextGenerationModel.js} +17 -17
- package/prompt/{TextPromptMapping.cjs → TextPromptFormat.cjs} +11 -8
- package/prompt/TextPromptFormat.d.ts +17 -0
- package/prompt/{TextPromptMapping.js → TextPromptFormat.js} +8 -5
- package/prompt/{VicunaPromptMapping.cjs → VicunaPromptFormat.cjs} +5 -5
- package/prompt/{VicunaPromptMapping.d.ts → VicunaPromptFormat.d.ts} +3 -3
- package/prompt/{VicunaPromptMapping.js → VicunaPromptFormat.js} +3 -3
- package/prompt/chat/trimChatPrompt.cjs +1 -1
- package/prompt/chat/trimChatPrompt.d.ts +1 -1
- package/prompt/chat/trimChatPrompt.js +1 -1
- package/prompt/index.cjs +7 -7
- package/prompt/index.d.ts +7 -7
- package/prompt/index.js +7 -7
- package/tool/WebSearchTool.cjs +7 -28
- package/tool/WebSearchTool.d.ts +6 -67
- package/tool/WebSearchTool.js +7 -28
- package/tool/executeTool.cjs +1 -0
- package/tool/executeTool.d.ts +5 -4
- package/tool/executeTool.js +1 -0
- package/prompt/Llama2PromptMapping.d.ts +0 -10
- package/prompt/OpenAIChatPromptMapping.d.ts +0 -6
- package/prompt/PromptMapping.d.ts +0 -7
- package/prompt/TextPromptMapping.d.ts +0 -14
- /package/prompt/{PromptMapping.cjs → PromptFormat.cjs} +0 -0
- /package/prompt/{PromptMapping.js → PromptFormat.js} +0 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
import { OpenAIChatMessage } from "../model-provider/openai/chat/OpenAIChatMessage.js";
|
2
|
+
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
3
|
+
import { InstructionPrompt } from "./InstructionPrompt.js";
|
4
|
+
import { PromptFormat } from "./PromptFormat.js";
|
5
|
+
/**
|
6
|
+
* Formats an instruction prompt as an OpenAI chat prompt.
|
7
|
+
*/
|
8
|
+
export declare const OpenAIChatInstructionPromptFormat: () => PromptFormat<InstructionPrompt, Array<OpenAIChatMessage>>;
|
9
|
+
/**
|
10
|
+
* Formats a chat prompt as an OpenAI chat prompt.
|
11
|
+
*/
|
12
|
+
export declare const OpenAIChatChatPromptFormat: () => PromptFormat<ChatPrompt, Array<OpenAIChatMessage>>;
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import { validateChatPrompt } from "./chat/validateChatPrompt.js";
|
2
|
-
|
3
|
-
|
2
|
+
/**
|
3
|
+
* Formats an instruction prompt as an OpenAI chat prompt.
|
4
|
+
*/
|
5
|
+
export const OpenAIChatInstructionPromptFormat = () => ({
|
6
|
+
format: (instruction) => {
|
4
7
|
const messages = [];
|
5
8
|
if (instruction.system != null) {
|
6
9
|
messages.push({
|
@@ -22,8 +25,11 @@ export const InstructionToOpenAIChatPromptMapping = () => ({
|
|
22
25
|
},
|
23
26
|
stopTokens: [],
|
24
27
|
});
|
25
|
-
|
26
|
-
|
28
|
+
/**
|
29
|
+
* Formats a chat prompt as an OpenAI chat prompt.
|
30
|
+
*/
|
31
|
+
export const OpenAIChatChatPromptFormat = () => ({
|
32
|
+
format: (chatPrompt) => {
|
27
33
|
validateChatPrompt(chatPrompt);
|
28
34
|
const messages = [];
|
29
35
|
for (let i = 0; i < chatPrompt.length; i++) {
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Prompt formats format a source prompt into the structure of a target prompt.
|
3
|
+
*/
|
4
|
+
export interface PromptFormat<SOURCE_PROMPT, TARGET_PROMPT> {
|
5
|
+
/**
|
6
|
+
* Formats the source prompt into the structure of the target prompt.
|
7
|
+
*/
|
8
|
+
format(sourcePrompt: SOURCE_PROMPT): TARGET_PROMPT;
|
9
|
+
/**
|
10
|
+
* The tokens that should be used as default stop tokens.
|
11
|
+
* This is e.g. important for chat formats.
|
12
|
+
*/
|
13
|
+
stopTokens: string[];
|
14
|
+
}
|
@@ -1,22 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
class
|
5
|
-
constructor({ model,
|
3
|
+
exports.PromptFormatTextGenerationModel = void 0;
|
4
|
+
class PromptFormatTextGenerationModel {
|
5
|
+
constructor({ model, promptFormat, }) {
|
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, "promptFormat", {
|
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.promptFormat = promptFormat;
|
20
20
|
}
|
21
21
|
get modelInformation() {
|
22
22
|
return this.model.modelInformation;
|
@@ -35,10 +35,10 @@ class PromptMappingTextGenerationModel {
|
|
35
35
|
if (originalCountPromptTokens === undefined) {
|
36
36
|
return undefined;
|
37
37
|
}
|
38
|
-
return ((prompt) => originalCountPromptTokens(this.
|
38
|
+
return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
|
39
39
|
}
|
40
40
|
generateTextResponse(prompt, options) {
|
41
|
-
const mappedPrompt = this.
|
41
|
+
const mappedPrompt = this.promptFormat.format(prompt);
|
42
42
|
return this.model.generateTextResponse(mappedPrompt, options);
|
43
43
|
}
|
44
44
|
extractText(response) {
|
@@ -50,39 +50,39 @@ class PromptMappingTextGenerationModel {
|
|
50
50
|
return undefined;
|
51
51
|
}
|
52
52
|
return ((prompt, options) => {
|
53
|
-
const mappedPrompt = this.
|
53
|
+
const mappedPrompt = this.promptFormat.format(prompt);
|
54
54
|
return originalGenerateDeltaStreamResponse(mappedPrompt, options);
|
55
55
|
});
|
56
56
|
}
|
57
57
|
get extractTextDelta() {
|
58
58
|
return this.model.extractTextDelta;
|
59
59
|
}
|
60
|
-
|
61
|
-
return new
|
62
|
-
model: this.withStopTokens(
|
63
|
-
|
60
|
+
withPromptFormat(promptFormat) {
|
61
|
+
return new PromptFormatTextGenerationModel({
|
62
|
+
model: this.withStopTokens(promptFormat.stopTokens),
|
63
|
+
promptFormat,
|
64
64
|
});
|
65
65
|
}
|
66
66
|
withSettings(additionalSettings) {
|
67
|
-
return new
|
67
|
+
return new PromptFormatTextGenerationModel({
|
68
68
|
model: this.model.withSettings(additionalSettings),
|
69
|
-
|
69
|
+
promptFormat: this.promptFormat,
|
70
70
|
});
|
71
71
|
}
|
72
72
|
get maxCompletionTokens() {
|
73
73
|
return this.model.maxCompletionTokens;
|
74
74
|
}
|
75
75
|
withMaxCompletionTokens(maxCompletionTokens) {
|
76
|
-
return new
|
76
|
+
return new PromptFormatTextGenerationModel({
|
77
77
|
model: this.model.withMaxCompletionTokens(maxCompletionTokens),
|
78
|
-
|
78
|
+
promptFormat: this.promptFormat,
|
79
79
|
});
|
80
80
|
}
|
81
81
|
withStopTokens(stopTokens) {
|
82
|
-
return new
|
82
|
+
return new PromptFormatTextGenerationModel({
|
83
83
|
model: this.model.withStopTokens(stopTokens),
|
84
|
-
|
84
|
+
promptFormat: this.promptFormat,
|
85
85
|
});
|
86
86
|
}
|
87
87
|
}
|
88
|
-
exports.
|
88
|
+
exports.PromptFormatTextGenerationModel = PromptFormatTextGenerationModel;
|
package/prompt/{PromptMappingTextGenerationModel.d.ts → PromptFormatTextGenerationModel.d.ts}
RENAMED
@@ -1,13 +1,13 @@
|
|
1
1
|
import { FunctionOptions } from "../model-function/FunctionOptions.js";
|
2
2
|
import { DeltaEvent } from "../model-function/generate-text/DeltaEvent.js";
|
3
3
|
import { TextGenerationModel, TextGenerationModelSettings } from "../model-function/generate-text/TextGenerationModel.js";
|
4
|
-
import {
|
5
|
-
export declare class
|
4
|
+
import { PromptFormat } from "./PromptFormat.js";
|
5
|
+
export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS>> implements TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS> {
|
6
6
|
private readonly model;
|
7
|
-
private readonly
|
8
|
-
constructor({ model,
|
7
|
+
private readonly promptFormat;
|
8
|
+
constructor({ model, promptFormat, }: {
|
9
9
|
model: MODEL;
|
10
|
-
|
10
|
+
promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
|
11
11
|
});
|
12
12
|
get modelInformation(): import("../index.js").ModelInformation;
|
13
13
|
get settings(): SETTINGS;
|
@@ -18,7 +18,7 @@ export declare class PromptMappingTextGenerationModel<PROMPT, MODEL_PROMPT, RESP
|
|
18
18
|
extractText(response: RESPONSE): string;
|
19
19
|
get generateDeltaStreamResponse(): MODEL["generateDeltaStreamResponse"] extends undefined ? undefined : (prompt: PROMPT, options: FunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
|
20
20
|
get extractTextDelta(): MODEL["extractTextDelta"];
|
21
|
-
|
21
|
+
withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, RESPONSE, FULL_DELTA, SETTINGS, this>;
|
22
22
|
withSettings(additionalSettings: Partial<SETTINGS>): this;
|
23
23
|
get maxCompletionTokens(): MODEL["maxCompletionTokens"];
|
24
24
|
withMaxCompletionTokens(maxCompletionTokens: number): this;
|
@@ -1,19 +1,19 @@
|
|
1
|
-
export class
|
2
|
-
constructor({ model,
|
1
|
+
export class PromptFormatTextGenerationModel {
|
2
|
+
constructor({ model, promptFormat, }) {
|
3
3
|
Object.defineProperty(this, "model", {
|
4
4
|
enumerable: true,
|
5
5
|
configurable: true,
|
6
6
|
writable: true,
|
7
7
|
value: void 0
|
8
8
|
});
|
9
|
-
Object.defineProperty(this, "
|
9
|
+
Object.defineProperty(this, "promptFormat", {
|
10
10
|
enumerable: true,
|
11
11
|
configurable: true,
|
12
12
|
writable: true,
|
13
13
|
value: void 0
|
14
14
|
});
|
15
15
|
this.model = model;
|
16
|
-
this.
|
16
|
+
this.promptFormat = promptFormat;
|
17
17
|
}
|
18
18
|
get modelInformation() {
|
19
19
|
return this.model.modelInformation;
|
@@ -32,10 +32,10 @@ export class PromptMappingTextGenerationModel {
|
|
32
32
|
if (originalCountPromptTokens === undefined) {
|
33
33
|
return undefined;
|
34
34
|
}
|
35
|
-
return ((prompt) => originalCountPromptTokens(this.
|
35
|
+
return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
|
36
36
|
}
|
37
37
|
generateTextResponse(prompt, options) {
|
38
|
-
const mappedPrompt = this.
|
38
|
+
const mappedPrompt = this.promptFormat.format(prompt);
|
39
39
|
return this.model.generateTextResponse(mappedPrompt, options);
|
40
40
|
}
|
41
41
|
extractText(response) {
|
@@ -47,38 +47,38 @@ export class PromptMappingTextGenerationModel {
|
|
47
47
|
return undefined;
|
48
48
|
}
|
49
49
|
return ((prompt, options) => {
|
50
|
-
const mappedPrompt = this.
|
50
|
+
const mappedPrompt = this.promptFormat.format(prompt);
|
51
51
|
return originalGenerateDeltaStreamResponse(mappedPrompt, options);
|
52
52
|
});
|
53
53
|
}
|
54
54
|
get extractTextDelta() {
|
55
55
|
return this.model.extractTextDelta;
|
56
56
|
}
|
57
|
-
|
58
|
-
return new
|
59
|
-
model: this.withStopTokens(
|
60
|
-
|
57
|
+
withPromptFormat(promptFormat) {
|
58
|
+
return new PromptFormatTextGenerationModel({
|
59
|
+
model: this.withStopTokens(promptFormat.stopTokens),
|
60
|
+
promptFormat,
|
61
61
|
});
|
62
62
|
}
|
63
63
|
withSettings(additionalSettings) {
|
64
|
-
return new
|
64
|
+
return new PromptFormatTextGenerationModel({
|
65
65
|
model: this.model.withSettings(additionalSettings),
|
66
|
-
|
66
|
+
promptFormat: this.promptFormat,
|
67
67
|
});
|
68
68
|
}
|
69
69
|
get maxCompletionTokens() {
|
70
70
|
return this.model.maxCompletionTokens;
|
71
71
|
}
|
72
72
|
withMaxCompletionTokens(maxCompletionTokens) {
|
73
|
-
return new
|
73
|
+
return new PromptFormatTextGenerationModel({
|
74
74
|
model: this.model.withMaxCompletionTokens(maxCompletionTokens),
|
75
|
-
|
75
|
+
promptFormat: this.promptFormat,
|
76
76
|
});
|
77
77
|
}
|
78
78
|
withStopTokens(stopTokens) {
|
79
|
-
return new
|
79
|
+
return new PromptFormatTextGenerationModel({
|
80
80
|
model: this.model.withStopTokens(stopTokens),
|
81
|
-
|
81
|
+
promptFormat: this.promptFormat,
|
82
82
|
});
|
83
83
|
}
|
84
84
|
}
|
@@ -1,10 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.TextChatPromptFormat = exports.TextInstructionPromptFormat = void 0;
|
4
4
|
const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
|
5
|
-
|
5
|
+
/**
|
6
|
+
* Formats an instruction prompt as a basic text prompt.
|
7
|
+
*/
|
8
|
+
const TextInstructionPromptFormat = () => ({
|
6
9
|
stopTokens: [],
|
7
|
-
|
10
|
+
format: (instruction) => {
|
8
11
|
let text = "";
|
9
12
|
if (instruction.system != null) {
|
10
13
|
text += `${instruction.system}\n\n`;
|
@@ -16,15 +19,15 @@ const InstructionToTextPromptMapping = () => ({
|
|
16
19
|
return text;
|
17
20
|
},
|
18
21
|
});
|
19
|
-
exports.
|
22
|
+
exports.TextInstructionPromptFormat = TextInstructionPromptFormat;
|
20
23
|
/**
|
21
|
-
*
|
24
|
+
* Formats a chat prompt as a basic text prompt.
|
22
25
|
*
|
23
26
|
* @param user The label of the user in the chat.
|
24
27
|
* @param ai The name of the AI in the chat.
|
25
28
|
*/
|
26
|
-
const
|
27
|
-
|
29
|
+
const TextChatPromptFormat = ({ user, ai }) => ({
|
30
|
+
format: (chatPrompt) => {
|
28
31
|
(0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
|
29
32
|
let text = "";
|
30
33
|
for (let i = 0; i < chatPrompt.length; i++) {
|
@@ -55,4 +58,4 @@ const ChatToTextPromptMapping = ({ user, ai }) => ({
|
|
55
58
|
},
|
56
59
|
stopTokens: [`\n${user}:`],
|
57
60
|
});
|
58
|
-
exports.
|
61
|
+
exports.TextChatPromptFormat = TextChatPromptFormat;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { PromptFormat } from "./PromptFormat.js";
|
2
|
+
import { InstructionPrompt } from "./InstructionPrompt.js";
|
3
|
+
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
4
|
+
/**
|
5
|
+
* Formats an instruction prompt as a basic text prompt.
|
6
|
+
*/
|
7
|
+
export declare const TextInstructionPromptFormat: () => PromptFormat<InstructionPrompt, string>;
|
8
|
+
/**
|
9
|
+
* Formats a chat prompt as a basic text prompt.
|
10
|
+
*
|
11
|
+
* @param user The label of the user in the chat.
|
12
|
+
* @param ai The name of the AI in the chat.
|
13
|
+
*/
|
14
|
+
export declare const TextChatPromptFormat: ({ user, ai, }: {
|
15
|
+
user: string;
|
16
|
+
ai: string;
|
17
|
+
}) => PromptFormat<ChatPrompt, string>;
|
@@ -1,7 +1,10 @@
|
|
1
1
|
import { validateChatPrompt } from "./chat/validateChatPrompt.js";
|
2
|
-
|
2
|
+
/**
|
3
|
+
* Formats an instruction prompt as a basic text prompt.
|
4
|
+
*/
|
5
|
+
export const TextInstructionPromptFormat = () => ({
|
3
6
|
stopTokens: [],
|
4
|
-
|
7
|
+
format: (instruction) => {
|
5
8
|
let text = "";
|
6
9
|
if (instruction.system != null) {
|
7
10
|
text += `${instruction.system}\n\n`;
|
@@ -14,13 +17,13 @@ export const InstructionToTextPromptMapping = () => ({
|
|
14
17
|
},
|
15
18
|
});
|
16
19
|
/**
|
17
|
-
*
|
20
|
+
* Formats a chat prompt as a basic text prompt.
|
18
21
|
*
|
19
22
|
* @param user The label of the user in the chat.
|
20
23
|
* @param ai The name of the AI in the chat.
|
21
24
|
*/
|
22
|
-
export const
|
23
|
-
|
25
|
+
export const TextChatPromptFormat = ({ user, ai }) => ({
|
26
|
+
format: (chatPrompt) => {
|
24
27
|
validateChatPrompt(chatPrompt);
|
25
28
|
let text = "";
|
26
29
|
for (let i = 0; i < chatPrompt.length; i++) {
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.VicunaChatPromptFormat = void 0;
|
4
4
|
const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
|
5
5
|
const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.";
|
6
6
|
/**
|
7
|
-
*
|
7
|
+
* Formats a chat prompt as a Vicuna prompt.
|
8
8
|
*
|
9
9
|
* Overridding the system message in the first chat message can affect model respones.
|
10
10
|
*
|
@@ -16,8 +16,8 @@ const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial i
|
|
16
16
|
* ASSISTANT:
|
17
17
|
* ```
|
18
18
|
*/
|
19
|
-
const
|
20
|
-
|
19
|
+
const VicunaChatPromptFormat = () => ({
|
20
|
+
format: (chatPrompt) => {
|
21
21
|
(0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
|
22
22
|
let text = "";
|
23
23
|
for (let i = 0; i < chatPrompt.length; i++) {
|
@@ -52,4 +52,4 @@ const ChatToVicunaPromptMapping = () => ({
|
|
52
52
|
},
|
53
53
|
stopTokens: [`\nUSER:`],
|
54
54
|
});
|
55
|
-
exports.
|
55
|
+
exports.VicunaChatPromptFormat = VicunaChatPromptFormat;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { PromptFormat } from "./PromptFormat.js";
|
2
2
|
import { ChatPrompt } from "./chat/ChatPrompt.js";
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* Formats a chat prompt as a Vicuna prompt.
|
5
5
|
*
|
6
6
|
* Overridding the system message in the first chat message can affect model respones.
|
7
7
|
*
|
@@ -13,4 +13,4 @@ import { ChatPrompt } from "./chat/ChatPrompt.js";
|
|
13
13
|
* ASSISTANT:
|
14
14
|
* ```
|
15
15
|
*/
|
16
|
-
export declare const
|
16
|
+
export declare const VicunaChatPromptFormat: () => PromptFormat<ChatPrompt, string>;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { validateChatPrompt } from "./chat/validateChatPrompt.js";
|
2
2
|
const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.";
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* Formats a chat prompt as a Vicuna prompt.
|
5
5
|
*
|
6
6
|
* Overridding the system message in the first chat message can affect model respones.
|
7
7
|
*
|
@@ -13,8 +13,8 @@ const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial i
|
|
13
13
|
* ASSISTANT:
|
14
14
|
* ```
|
15
15
|
*/
|
16
|
-
export const
|
17
|
-
|
16
|
+
export const VicunaChatPromptFormat = () => ({
|
17
|
+
format: (chatPrompt) => {
|
18
18
|
validateChatPrompt(chatPrompt);
|
19
19
|
let text = "";
|
20
20
|
for (let i = 0; i < chatPrompt.length; i++) {
|
@@ -10,7 +10,7 @@ const validateChatPrompt_js_1 = require("./validateChatPrompt.cjs");
|
|
10
10
|
* When the minimal chat prompt (system message + last user message) is already too long, it will only
|
11
11
|
* return this minimal chat prompt.
|
12
12
|
*
|
13
|
-
* @see https://modelfusion.dev/guide/function/generate-text/prompt-
|
13
|
+
* @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
|
14
14
|
*/
|
15
15
|
async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
|
16
16
|
(model.maxCompletionTokens ?? model.contextWindowSize / 4), }) {
|
@@ -8,7 +8,7 @@ import { ChatPrompt } from "./ChatPrompt.js";
|
|
8
8
|
* When the minimal chat prompt (system message + last user message) is already too long, it will only
|
9
9
|
* return this minimal chat prompt.
|
10
10
|
*
|
11
|
-
* @see https://modelfusion.dev/guide/function/generate-text/prompt-
|
11
|
+
* @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
|
12
12
|
*/
|
13
13
|
export declare function trimChatPrompt({ prompt, model, tokenLimit, }: {
|
14
14
|
prompt: ChatPrompt;
|
@@ -7,7 +7,7 @@ import { validateChatPrompt } from "./validateChatPrompt.js";
|
|
7
7
|
* When the minimal chat prompt (system message + last user message) is already too long, it will only
|
8
8
|
* return this minimal chat prompt.
|
9
9
|
*
|
10
|
-
* @see https://modelfusion.dev/guide/function/generate-text/prompt-
|
10
|
+
* @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
|
11
11
|
*/
|
12
12
|
export async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
|
13
13
|
(model.maxCompletionTokens ?? model.contextWindowSize / 4), }) {
|
package/prompt/index.cjs
CHANGED
@@ -14,14 +14,14 @@ 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("./
|
17
|
+
__exportStar(require("./AlpacaPromptFormat.cjs"), exports);
|
18
18
|
__exportStar(require("./InstructionPrompt.cjs"), exports);
|
19
|
-
__exportStar(require("./
|
20
|
-
__exportStar(require("./
|
21
|
-
__exportStar(require("./
|
22
|
-
__exportStar(require("./
|
23
|
-
__exportStar(require("./
|
24
|
-
__exportStar(require("./
|
19
|
+
__exportStar(require("./Llama2PromptFormat.cjs"), exports);
|
20
|
+
__exportStar(require("./OpenAIChatPromptFormat.cjs"), exports);
|
21
|
+
__exportStar(require("./PromptFormat.cjs"), exports);
|
22
|
+
__exportStar(require("./PromptFormatTextGenerationModel.cjs"), exports);
|
23
|
+
__exportStar(require("./TextPromptFormat.cjs"), exports);
|
24
|
+
__exportStar(require("./VicunaPromptFormat.cjs"), exports);
|
25
25
|
__exportStar(require("./chat/ChatPrompt.cjs"), exports);
|
26
26
|
__exportStar(require("./chat/trimChatPrompt.cjs"), exports);
|
27
27
|
__exportStar(require("./chat/validateChatPrompt.cjs"), exports);
|
package/prompt/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./AlpacaPromptFormat.js";
|
2
2
|
export * from "./InstructionPrompt.js";
|
3
|
-
export * from "./
|
4
|
-
export * from "./
|
5
|
-
export * from "./
|
6
|
-
export * from "./
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
3
|
+
export * from "./Llama2PromptFormat.js";
|
4
|
+
export * from "./OpenAIChatPromptFormat.js";
|
5
|
+
export * from "./PromptFormat.js";
|
6
|
+
export * from "./PromptFormatTextGenerationModel.js";
|
7
|
+
export * from "./TextPromptFormat.js";
|
8
|
+
export * from "./VicunaPromptFormat.js";
|
9
9
|
export * from "./chat/ChatPrompt.js";
|
10
10
|
export * from "./chat/trimChatPrompt.js";
|
11
11
|
export * from "./chat/validateChatPrompt.js";
|
package/prompt/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./AlpacaPromptFormat.js";
|
2
2
|
export * from "./InstructionPrompt.js";
|
3
|
-
export * from "./
|
4
|
-
export * from "./
|
5
|
-
export * from "./
|
6
|
-
export * from "./
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
3
|
+
export * from "./Llama2PromptFormat.js";
|
4
|
+
export * from "./OpenAIChatPromptFormat.js";
|
5
|
+
export * from "./PromptFormat.js";
|
6
|
+
export * from "./PromptFormatTextGenerationModel.js";
|
7
|
+
export * from "./TextPromptFormat.js";
|
8
|
+
export * from "./VicunaPromptFormat.js";
|
9
9
|
export * from "./chat/ChatPrompt.js";
|
10
10
|
export * from "./chat/trimChatPrompt.js";
|
11
11
|
export * from "./chat/validateChatPrompt.js";
|
package/tool/WebSearchTool.cjs
CHANGED
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebSearchTool = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
const Tool_js_1 = require("./Tool.cjs");
|
6
|
-
const INPUT_SCHEMA = zod_1.z.object({
|
7
|
-
query: zod_1.z.string(),
|
8
|
-
});
|
9
6
|
const OUTPUT_SCHEMA = zod_1.z.object({
|
10
7
|
results: zod_1.z.array(zod_1.z.object({
|
11
8
|
title: zod_1.z.string(),
|
@@ -13,39 +10,21 @@ const OUTPUT_SCHEMA = zod_1.z.object({
|
|
13
10
|
snippet: zod_1.z.string(),
|
14
11
|
})),
|
15
12
|
});
|
13
|
+
// expose the schemas to library consumers:
|
14
|
+
const createInputSchema = (description) =>
|
15
|
+
// same structure, but with description:
|
16
|
+
zod_1.z.object({
|
17
|
+
query: zod_1.z.string().describe(description),
|
18
|
+
});
|
16
19
|
class WebSearchTool extends Tool_js_1.Tool {
|
17
20
|
constructor({ name, description, queryDescription = "Search query", execute, }) {
|
18
21
|
super({
|
19
22
|
name,
|
20
23
|
description,
|
21
|
-
inputSchema:
|
24
|
+
inputSchema: createInputSchema(queryDescription),
|
22
25
|
outputSchema: OUTPUT_SCHEMA,
|
23
26
|
execute,
|
24
27
|
});
|
25
|
-
Object.defineProperty(this, "outputSchema", {
|
26
|
-
enumerable: true,
|
27
|
-
configurable: true,
|
28
|
-
writable: true,
|
29
|
-
value: void 0
|
30
|
-
});
|
31
|
-
this.outputSchema = OUTPUT_SCHEMA;
|
32
28
|
}
|
33
29
|
}
|
34
30
|
exports.WebSearchTool = WebSearchTool;
|
35
|
-
// expose the schemas to library consumers:
|
36
|
-
Object.defineProperty(WebSearchTool, "createInputSchema", {
|
37
|
-
enumerable: true,
|
38
|
-
configurable: true,
|
39
|
-
writable: true,
|
40
|
-
value: (description) =>
|
41
|
-
// same structure, but with description:
|
42
|
-
zod_1.z.object({
|
43
|
-
query: zod_1.z.string().describe(description),
|
44
|
-
})
|
45
|
-
});
|
46
|
-
Object.defineProperty(WebSearchTool, "createOutputSchema", {
|
47
|
-
enumerable: true,
|
48
|
-
configurable: true,
|
49
|
-
writable: true,
|
50
|
-
value: () => OUTPUT_SCHEMA
|
51
|
-
});
|