modelfusion 0.93.1 → 0.95.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 +1 -0
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.cjs +11 -11
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.js +11 -11
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.cjs +81 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.d.ts +23 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js +75 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.test.cjs +49 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.test.d.ts +1 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.test.js +47 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.cjs +2 -2
- package/model-function/generate-text/prompt-template/TextPromptTemplate.js +2 -2
- package/model-function/generate-text/prompt-template/index.cjs +3 -2
- package/model-function/generate-text/prompt-template/index.d.ts +2 -1
- package/model-function/generate-text/prompt-template/index.js +2 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +3 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +4 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,11 +4,11 @@ exports.chat = exports.instruction = exports.text = void 0;
|
|
4
4
|
const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
|
5
5
|
const START_SEGMENT = "<|im_start|>";
|
6
6
|
const END_SEGMENT = "<|im_end|>";
|
7
|
-
function
|
7
|
+
function segmentStart(role) {
|
8
8
|
return `${START_SEGMENT}${role}\n`;
|
9
9
|
}
|
10
|
-
function
|
11
|
-
return text == null ? "" : `${
|
10
|
+
function segment(role, text) {
|
11
|
+
return text == null ? "" : `${segmentStart(role)}${text}${END_SEGMENT}\n`;
|
12
12
|
}
|
13
13
|
/**
|
14
14
|
* Formats a text prompt using the ChatML format.
|
@@ -18,7 +18,7 @@ function text() {
|
|
18
18
|
stopSequences: [END_SEGMENT],
|
19
19
|
format(prompt) {
|
20
20
|
// prompt and then prefix start of assistant response:
|
21
|
-
return
|
21
|
+
return segment("user", prompt) + segmentStart("assistant");
|
22
22
|
},
|
23
23
|
};
|
24
24
|
}
|
@@ -40,9 +40,9 @@ function instruction() {
|
|
40
40
|
return {
|
41
41
|
stopSequences: [END_SEGMENT],
|
42
42
|
format(prompt) {
|
43
|
-
return (
|
44
|
-
|
45
|
-
|
43
|
+
return (segment("system", prompt.system) +
|
44
|
+
segment("user", prompt.instruction) +
|
45
|
+
segmentStart("assistant") +
|
46
46
|
(prompt.responsePrefix ?? ""));
|
47
47
|
},
|
48
48
|
};
|
@@ -65,15 +65,15 @@ function chat() {
|
|
65
65
|
return {
|
66
66
|
format(prompt) {
|
67
67
|
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
68
|
-
let text = prompt.system != null ?
|
68
|
+
let text = prompt.system != null ? segment("system", prompt.system) : "";
|
69
69
|
for (const { role, content } of prompt.messages) {
|
70
70
|
switch (role) {
|
71
71
|
case "user": {
|
72
|
-
text +=
|
72
|
+
text += segment("user", content);
|
73
73
|
break;
|
74
74
|
}
|
75
75
|
case "assistant": {
|
76
|
-
text +=
|
76
|
+
text += segment("assistant", content);
|
77
77
|
break;
|
78
78
|
}
|
79
79
|
default: {
|
@@ -83,7 +83,7 @@ function chat() {
|
|
83
83
|
}
|
84
84
|
}
|
85
85
|
// prefix start of assistant response:
|
86
|
-
text +=
|
86
|
+
text += segmentStart("assistant");
|
87
87
|
return text;
|
88
88
|
},
|
89
89
|
stopSequences: [END_SEGMENT],
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { validateChatPrompt } from "./ChatPrompt.js";
|
2
2
|
const START_SEGMENT = "<|im_start|>";
|
3
3
|
const END_SEGMENT = "<|im_end|>";
|
4
|
-
function
|
4
|
+
function segmentStart(role) {
|
5
5
|
return `${START_SEGMENT}${role}\n`;
|
6
6
|
}
|
7
|
-
function
|
8
|
-
return text == null ? "" : `${
|
7
|
+
function segment(role, text) {
|
8
|
+
return text == null ? "" : `${segmentStart(role)}${text}${END_SEGMENT}\n`;
|
9
9
|
}
|
10
10
|
/**
|
11
11
|
* Formats a text prompt using the ChatML format.
|
@@ -15,7 +15,7 @@ export function text() {
|
|
15
15
|
stopSequences: [END_SEGMENT],
|
16
16
|
format(prompt) {
|
17
17
|
// prompt and then prefix start of assistant response:
|
18
|
-
return
|
18
|
+
return segment("user", prompt) + segmentStart("assistant");
|
19
19
|
},
|
20
20
|
};
|
21
21
|
}
|
@@ -36,9 +36,9 @@ export function instruction() {
|
|
36
36
|
return {
|
37
37
|
stopSequences: [END_SEGMENT],
|
38
38
|
format(prompt) {
|
39
|
-
return (
|
40
|
-
|
41
|
-
|
39
|
+
return (segment("system", prompt.system) +
|
40
|
+
segment("user", prompt.instruction) +
|
41
|
+
segmentStart("assistant") +
|
42
42
|
(prompt.responsePrefix ?? ""));
|
43
43
|
},
|
44
44
|
};
|
@@ -60,15 +60,15 @@ export function chat() {
|
|
60
60
|
return {
|
61
61
|
format(prompt) {
|
62
62
|
validateChatPrompt(prompt);
|
63
|
-
let text = prompt.system != null ?
|
63
|
+
let text = prompt.system != null ? segment("system", prompt.system) : "";
|
64
64
|
for (const { role, content } of prompt.messages) {
|
65
65
|
switch (role) {
|
66
66
|
case "user": {
|
67
|
-
text +=
|
67
|
+
text += segment("user", content);
|
68
68
|
break;
|
69
69
|
}
|
70
70
|
case "assistant": {
|
71
|
-
text +=
|
71
|
+
text += segment("assistant", content);
|
72
72
|
break;
|
73
73
|
}
|
74
74
|
default: {
|
@@ -78,7 +78,7 @@ export function chat() {
|
|
78
78
|
}
|
79
79
|
}
|
80
80
|
// prefix start of assistant response:
|
81
|
-
text +=
|
81
|
+
text += segmentStart("assistant");
|
82
82
|
return text;
|
83
83
|
},
|
84
84
|
stopSequences: [END_SEGMENT],
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.chat = exports.instruction = exports.text = void 0;
|
4
|
+
const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
|
5
|
+
const roleNames = {
|
6
|
+
system: "System",
|
7
|
+
user: "User",
|
8
|
+
assistant: "Assistant",
|
9
|
+
};
|
10
|
+
function segmentStart(role) {
|
11
|
+
return `### ${roleNames[role]}:\n`;
|
12
|
+
}
|
13
|
+
function segment(role, text) {
|
14
|
+
return text == null ? "" : `${segmentStart(role)}${text}\n`;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Formats a text prompt as a neural chat prompt.
|
18
|
+
*
|
19
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
20
|
+
*/
|
21
|
+
function text() {
|
22
|
+
return {
|
23
|
+
stopSequences: [],
|
24
|
+
format(prompt) {
|
25
|
+
// prompt and then prefix start of assistant response:
|
26
|
+
return segment("user", prompt) + segmentStart("assistant");
|
27
|
+
},
|
28
|
+
};
|
29
|
+
}
|
30
|
+
exports.text = text;
|
31
|
+
/**
|
32
|
+
* Formats an instruction prompt as a neural chat prompt.
|
33
|
+
*
|
34
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
35
|
+
*/
|
36
|
+
const instruction = () => ({
|
37
|
+
stopSequences: [],
|
38
|
+
format(prompt) {
|
39
|
+
return (segment("system", prompt.system) +
|
40
|
+
segment("user", prompt.instruction) +
|
41
|
+
segmentStart("assistant") +
|
42
|
+
(prompt.responsePrefix ?? ""));
|
43
|
+
},
|
44
|
+
});
|
45
|
+
exports.instruction = instruction;
|
46
|
+
/**
|
47
|
+
* Formats a chat prompt as a basic text prompt.
|
48
|
+
*
|
49
|
+
* @param user The label of the user in the chat. Default to "user".
|
50
|
+
* @param assistant The label of the assistant in the chat. Default to "assistant".
|
51
|
+
* @param system The label of the system in the chat. Optional, defaults to no prefix.
|
52
|
+
*/
|
53
|
+
function chat() {
|
54
|
+
return {
|
55
|
+
format(prompt) {
|
56
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
57
|
+
let text = prompt.system != null ? segment("system", prompt.system) : "";
|
58
|
+
for (const { role, content } of prompt.messages) {
|
59
|
+
switch (role) {
|
60
|
+
case "user": {
|
61
|
+
text += segment("user", content);
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
case "assistant": {
|
65
|
+
text += segment("assistant", content);
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
default: {
|
69
|
+
const _exhaustiveCheck = role;
|
70
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
// prefix start of assistant response:
|
75
|
+
text += segmentStart("assistant");
|
76
|
+
return text;
|
77
|
+
},
|
78
|
+
stopSequences: [`\n${roleNames.user}:`],
|
79
|
+
};
|
80
|
+
}
|
81
|
+
exports.chat = chat;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
|
2
|
+
import { TextChatPrompt } from "./ChatPrompt.js";
|
3
|
+
import { TextInstructionPrompt } from "./InstructionPrompt.js";
|
4
|
+
/**
|
5
|
+
* Formats a text prompt as a neural chat prompt.
|
6
|
+
*
|
7
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
8
|
+
*/
|
9
|
+
export declare function text(): TextGenerationPromptTemplate<string, string>;
|
10
|
+
/**
|
11
|
+
* Formats an instruction prompt as a neural chat prompt.
|
12
|
+
*
|
13
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
14
|
+
*/
|
15
|
+
export declare const instruction: () => TextGenerationPromptTemplate<TextInstructionPrompt, string>;
|
16
|
+
/**
|
17
|
+
* Formats a chat prompt as a basic text prompt.
|
18
|
+
*
|
19
|
+
* @param user The label of the user in the chat. Default to "user".
|
20
|
+
* @param assistant The label of the assistant in the chat. Default to "assistant".
|
21
|
+
* @param system The label of the system in the chat. Optional, defaults to no prefix.
|
22
|
+
*/
|
23
|
+
export declare function chat(): TextGenerationPromptTemplate<TextChatPrompt, string>;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { validateChatPrompt } from "./ChatPrompt.js";
|
2
|
+
const roleNames = {
|
3
|
+
system: "System",
|
4
|
+
user: "User",
|
5
|
+
assistant: "Assistant",
|
6
|
+
};
|
7
|
+
function segmentStart(role) {
|
8
|
+
return `### ${roleNames[role]}:\n`;
|
9
|
+
}
|
10
|
+
function segment(role, text) {
|
11
|
+
return text == null ? "" : `${segmentStart(role)}${text}\n`;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Formats a text prompt as a neural chat prompt.
|
15
|
+
*
|
16
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
17
|
+
*/
|
18
|
+
export function text() {
|
19
|
+
return {
|
20
|
+
stopSequences: [],
|
21
|
+
format(prompt) {
|
22
|
+
// prompt and then prefix start of assistant response:
|
23
|
+
return segment("user", prompt) + segmentStart("assistant");
|
24
|
+
},
|
25
|
+
};
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* Formats an instruction prompt as a neural chat prompt.
|
29
|
+
*
|
30
|
+
* @see https://huggingface.co/Intel/neural-chat-7b-v3-1#prompt-template
|
31
|
+
*/
|
32
|
+
export const instruction = () => ({
|
33
|
+
stopSequences: [],
|
34
|
+
format(prompt) {
|
35
|
+
return (segment("system", prompt.system) +
|
36
|
+
segment("user", prompt.instruction) +
|
37
|
+
segmentStart("assistant") +
|
38
|
+
(prompt.responsePrefix ?? ""));
|
39
|
+
},
|
40
|
+
});
|
41
|
+
/**
|
42
|
+
* Formats a chat prompt as a basic text prompt.
|
43
|
+
*
|
44
|
+
* @param user The label of the user in the chat. Default to "user".
|
45
|
+
* @param assistant The label of the assistant in the chat. Default to "assistant".
|
46
|
+
* @param system The label of the system in the chat. Optional, defaults to no prefix.
|
47
|
+
*/
|
48
|
+
export function chat() {
|
49
|
+
return {
|
50
|
+
format(prompt) {
|
51
|
+
validateChatPrompt(prompt);
|
52
|
+
let text = prompt.system != null ? segment("system", prompt.system) : "";
|
53
|
+
for (const { role, content } of prompt.messages) {
|
54
|
+
switch (role) {
|
55
|
+
case "user": {
|
56
|
+
text += segment("user", content);
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
case "assistant": {
|
60
|
+
text += segment("assistant", content);
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
default: {
|
64
|
+
const _exhaustiveCheck = role;
|
65
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
// prefix start of assistant response:
|
70
|
+
text += segmentStart("assistant");
|
71
|
+
return text;
|
72
|
+
},
|
73
|
+
stopSequences: [`\n${roleNames.user}:`],
|
74
|
+
};
|
75
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const NeuralChatPromptTemplate_js_1 = require("./NeuralChatPromptTemplate.cjs");
|
4
|
+
describe("text prompt", () => {
|
5
|
+
it("should format prompt", () => {
|
6
|
+
const prompt = (0, NeuralChatPromptTemplate_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, NeuralChatPromptTemplate_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, NeuralChatPromptTemplate_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, NeuralChatPromptTemplate_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, NeuralChatPromptTemplate_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, NeuralChatPromptTemplate_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 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { chat, instruction, text } from "./NeuralChatPromptTemplate.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
|
+
});
|
@@ -20,9 +20,9 @@ const instruction = () => ({
|
|
20
20
|
if (prompt.system != null) {
|
21
21
|
text += `${prompt.system}\n\n`;
|
22
22
|
}
|
23
|
-
text += prompt.instruction
|
23
|
+
text += `${prompt.instruction}\n\n`;
|
24
24
|
if (prompt.responsePrefix != null) {
|
25
|
-
text +=
|
25
|
+
text += prompt.responsePrefix;
|
26
26
|
}
|
27
27
|
return text;
|
28
28
|
},
|
@@ -16,9 +16,9 @@ export const instruction = () => ({
|
|
16
16
|
if (prompt.system != null) {
|
17
17
|
text += `${prompt.system}\n\n`;
|
18
18
|
}
|
19
|
-
text += prompt.instruction
|
19
|
+
text += `${prompt.instruction}\n\n`;
|
20
20
|
if (prompt.responsePrefix != null) {
|
21
|
-
text +=
|
21
|
+
text += prompt.responsePrefix;
|
22
22
|
}
|
23
23
|
return text;
|
24
24
|
},
|
@@ -26,14 +26,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.VicunaPrompt = exports.TextPrompt = exports.Llama2Prompt = exports.ChatMLPrompt = exports.AlpacaPrompt = void 0;
|
29
|
+
exports.VicunaPrompt = exports.TextPrompt = exports.NeuralChatPrompt = exports.Llama2Prompt = exports.ChatMLPrompt = exports.AlpacaPrompt = void 0;
|
30
30
|
exports.AlpacaPrompt = __importStar(require("./AlpacaPromptTemplate.cjs"));
|
31
31
|
exports.ChatMLPrompt = __importStar(require("./ChatMLPromptTemplate.cjs"));
|
32
32
|
__exportStar(require("./ChatPrompt.cjs"), exports);
|
33
33
|
__exportStar(require("./Content.cjs"), exports);
|
34
34
|
__exportStar(require("./InstructionPrompt.cjs"), exports);
|
35
|
-
exports.Llama2Prompt = __importStar(require("./Llama2PromptTemplate.cjs"));
|
36
35
|
__exportStar(require("./InvalidPromptError.cjs"), exports);
|
36
|
+
exports.Llama2Prompt = __importStar(require("./Llama2PromptTemplate.cjs"));
|
37
|
+
exports.NeuralChatPrompt = __importStar(require("./NeuralChatPromptTemplate.cjs"));
|
37
38
|
exports.TextPrompt = __importStar(require("./TextPromptTemplate.cjs"));
|
38
39
|
exports.VicunaPrompt = __importStar(require("./VicunaPromptTemplate.cjs"));
|
39
40
|
__exportStar(require("./trimChatPrompt.cjs"), exports);
|
@@ -3,8 +3,9 @@ export * as ChatMLPrompt from "./ChatMLPromptTemplate.js";
|
|
3
3
|
export * from "./ChatPrompt.js";
|
4
4
|
export * from "./Content.js";
|
5
5
|
export * from "./InstructionPrompt.js";
|
6
|
-
export * as Llama2Prompt from "./Llama2PromptTemplate.js";
|
7
6
|
export * from "./InvalidPromptError.js";
|
7
|
+
export * as Llama2Prompt from "./Llama2PromptTemplate.js";
|
8
|
+
export * as NeuralChatPrompt from "./NeuralChatPromptTemplate.js";
|
8
9
|
export * as TextPrompt from "./TextPromptTemplate.js";
|
9
10
|
export * as VicunaPrompt from "./VicunaPromptTemplate.js";
|
10
11
|
export * from "./trimChatPrompt.js";
|
@@ -3,8 +3,9 @@ export * as ChatMLPrompt from "./ChatMLPromptTemplate.js";
|
|
3
3
|
export * from "./ChatPrompt.js";
|
4
4
|
export * from "./Content.js";
|
5
5
|
export * from "./InstructionPrompt.js";
|
6
|
-
export * as Llama2Prompt from "./Llama2PromptTemplate.js";
|
7
6
|
export * from "./InvalidPromptError.js";
|
7
|
+
export * as Llama2Prompt from "./Llama2PromptTemplate.js";
|
8
|
+
export * as NeuralChatPrompt from "./NeuralChatPromptTemplate.js";
|
8
9
|
export * as TextPrompt from "./TextPromptTemplate.js";
|
9
10
|
export * as VicunaPrompt from "./VicunaPromptTemplate.js";
|
10
11
|
export * from "./trimChatPrompt.js";
|
@@ -57,6 +57,7 @@ class LlamaCppTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
57
57
|
"maxCompletionTokens",
|
58
58
|
"stopSequences",
|
59
59
|
"contextWindowSize",
|
60
|
+
"cachePrompt",
|
60
61
|
"temperature",
|
61
62
|
"topK",
|
62
63
|
"topP",
|
@@ -197,13 +198,14 @@ const llamaCppTextStreamingResponseSchema = new ZodSchema_js_1.ZodSchema(zod_1.z
|
|
197
198
|
}),
|
198
199
|
llamaCppTextGenerationResponseSchema,
|
199
200
|
]));
|
200
|
-
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration_js_1.LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
201
|
+
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration_js_1.LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, cachePrompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
201
202
|
return (0, postToApi_js_1.postJsonToApi)({
|
202
203
|
url: api.assembleUrl(`/completion`),
|
203
204
|
headers: api.headers,
|
204
205
|
body: {
|
205
206
|
stream: responseFormat.stream,
|
206
207
|
prompt: prompt.text,
|
208
|
+
cache_prompt: cachePrompt,
|
207
209
|
temperature,
|
208
210
|
top_k: topK,
|
209
211
|
top_p: topP,
|
@@ -15,6 +15,10 @@ export interface LlamaCppTextGenerationModelSettings<CONTEXT_WINDOW_SIZE extends
|
|
15
15
|
* Llama.cpp server.
|
16
16
|
*/
|
17
17
|
contextWindowSize?: CONTEXT_WINDOW_SIZE;
|
18
|
+
/**
|
19
|
+
* Save the prompt and generation for avoid reprocess entire prompt if a part of this isn't change (default: false)
|
20
|
+
*/
|
21
|
+
cachePrompt?: boolean;
|
18
22
|
temperature?: number;
|
19
23
|
topK?: number;
|
20
24
|
topP?: number;
|
@@ -54,6 +54,7 @@ export class LlamaCppTextGenerationModel extends AbstractModel {
|
|
54
54
|
"maxCompletionTokens",
|
55
55
|
"stopSequences",
|
56
56
|
"contextWindowSize",
|
57
|
+
"cachePrompt",
|
57
58
|
"temperature",
|
58
59
|
"topK",
|
59
60
|
"topP",
|
@@ -193,13 +194,14 @@ const llamaCppTextStreamingResponseSchema = new ZodSchema(z.discriminatedUnion("
|
|
193
194
|
}),
|
194
195
|
llamaCppTextGenerationResponseSchema,
|
195
196
|
]));
|
196
|
-
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
197
|
+
async function callLlamaCppTextGenerationAPI({ api = new LlamaCppApiConfiguration(), abortSignal, responseFormat, prompt, cachePrompt, temperature, topK, topP, nPredict, nKeep, stop, tfsZ, typicalP, repeatPenalty, repeatLastN, penalizeNl, mirostat, mirostatTau, mirostatEta, seed, ignoreEos, logitBias, }) {
|
197
198
|
return postJsonToApi({
|
198
199
|
url: api.assembleUrl(`/completion`),
|
199
200
|
headers: api.headers,
|
200
201
|
body: {
|
201
202
|
stream: responseFormat.stream,
|
202
203
|
prompt: prompt.text,
|
204
|
+
cache_prompt: cachePrompt,
|
203
205
|
temperature,
|
204
206
|
top_k: topK,
|
205
207
|
top_p: topP,
|