modelfusion 0.79.0 → 0.80.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 +4 -3
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.cjs +10 -10
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.d.ts +2 -2
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.js +10 -10
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.cjs +15 -13
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.js +15 -13
- package/model-function/generate-text/prompt-format/ChatPrompt.cjs +24 -0
- package/model-function/generate-text/prompt-format/ChatPrompt.d.ts +6 -0
- package/model-function/generate-text/prompt-format/ChatPrompt.js +22 -1
- package/model-function/generate-text/prompt-format/Content.cjs +2 -0
- package/model-function/generate-text/prompt-format/Content.d.ts +20 -0
- package/model-function/generate-text/prompt-format/Content.js +1 -0
- package/model-function/generate-text/prompt-format/InstructionPrompt.d.ts +21 -16
- package/model-function/generate-text/prompt-format/InvalidPromptError.cjs +28 -0
- package/model-function/generate-text/prompt-format/InvalidPromptError.d.ts +13 -0
- package/model-function/generate-text/prompt-format/InvalidPromptError.js +24 -0
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.cjs +14 -10
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.js +14 -10
- package/model-function/generate-text/prompt-format/TextPromptFormat.cjs +11 -11
- package/model-function/generate-text/prompt-format/TextPromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/TextPromptFormat.js +11 -11
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.cjs +6 -6
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.d.ts +1 -1
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.js +6 -6
- package/model-function/generate-text/prompt-format/index.cjs +2 -2
- package/model-function/generate-text/prompt-format/index.d.ts +2 -2
- package/model-function/generate-text/prompt-format/index.js +2 -2
- package/model-function/generate-text/prompt-format/trimChatPrompt.cjs +2 -2
- package/model-function/generate-text/prompt-format/trimChatPrompt.d.ts +1 -1
- package/model-function/generate-text/prompt-format/trimChatPrompt.js +1 -1
- package/model-provider/anthropic/AnthropicPromptFormat.cjs +10 -10
- package/model-provider/anthropic/AnthropicPromptFormat.d.ts +3 -3
- package/model-provider/anthropic/AnthropicPromptFormat.js +10 -10
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.cjs +20 -11
- package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.js +20 -11
- package/model-provider/openai/OpenAICompletionModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatMessage.cjs +19 -14
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +2 -5
- package/model-provider/openai/chat/OpenAIChatMessage.js +19 -14
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +11 -13
- package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +2 -2
- package/model-provider/openai/chat/OpenAIChatPromptFormat.js +11 -13
- package/package.json +1 -1
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.cjs +0 -17
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.d.ts +0 -8
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.js +0 -13
- package/model-function/generate-text/prompt-format/validateChatPrompt.cjs +0 -24
- package/model-function/generate-text/prompt-format/validateChatPrompt.d.ts +0 -5
- package/model-function/generate-text/prompt-format/validateChatPrompt.js +0 -20
@@ -1,22 +1,22 @@
|
|
1
|
-
import { validateChatPrompt } from "./
|
1
|
+
import { validateChatPrompt } from "./ChatPrompt.js";
|
2
2
|
/**
|
3
3
|
* Formats a text prompt as a basic text prompt. Does not change the text prompt in any way.
|
4
4
|
*/
|
5
5
|
export const text = () => ({
|
6
6
|
stopSequences: [],
|
7
|
-
format: (
|
7
|
+
format: (prompt) => prompt,
|
8
8
|
});
|
9
9
|
/**
|
10
10
|
* Formats an instruction prompt as a basic text prompt.
|
11
11
|
*/
|
12
12
|
export const instruction = () => ({
|
13
13
|
stopSequences: [],
|
14
|
-
format
|
14
|
+
format(prompt) {
|
15
15
|
let text = "";
|
16
|
-
if (
|
17
|
-
text += `${
|
16
|
+
if (prompt.system != null) {
|
17
|
+
text += `${prompt.system}\n\n`;
|
18
18
|
}
|
19
|
-
text +=
|
19
|
+
text += prompt.instruction;
|
20
20
|
return text;
|
21
21
|
},
|
22
22
|
});
|
@@ -28,12 +28,12 @@ export const instruction = () => ({
|
|
28
28
|
* @param system The label of the system in the chat. Optional, defaults to no prefix.
|
29
29
|
*/
|
30
30
|
export const chat = ({ user = "user", assistant = "assistant", system, } = {}) => ({
|
31
|
-
format
|
32
|
-
validateChatPrompt(
|
33
|
-
let text =
|
34
|
-
? `${system != null ? `${system}:` : ""}${
|
31
|
+
format(prompt) {
|
32
|
+
validateChatPrompt(prompt);
|
33
|
+
let text = prompt.system != null
|
34
|
+
? `${system != null ? `${system}:` : ""}${prompt.system}\n\n`
|
35
35
|
: "";
|
36
|
-
for (const { role, content } of
|
36
|
+
for (const { role, content } of prompt.messages) {
|
37
37
|
switch (role) {
|
38
38
|
case "user": {
|
39
39
|
text += `${user}:\n${content}\n\n`;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.chat = void 0;
|
4
|
-
const
|
4
|
+
const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
|
5
5
|
// default Vicuna 1 system message
|
6
6
|
const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
|
7
7
|
"The assistant gives helpful, detailed, and polite answers to the user's questions.";
|
@@ -20,12 +20,12 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
|
|
20
20
|
*/
|
21
21
|
function chat() {
|
22
22
|
return {
|
23
|
-
format
|
24
|
-
(0,
|
25
|
-
let text =
|
26
|
-
? `${
|
23
|
+
format(prompt) {
|
24
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
25
|
+
let text = prompt.system != null
|
26
|
+
? `${prompt.system}\n\n`
|
27
27
|
: `${DEFAULT_SYSTEM_MESSAGE}\n\n`;
|
28
|
-
for (const { role, content } of
|
28
|
+
for (const { role, content } of prompt.messages) {
|
29
29
|
switch (role) {
|
30
30
|
case "user": {
|
31
31
|
text += `USER: ${content}\n`;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { validateChatPrompt } from "./
|
1
|
+
import { validateChatPrompt } from "./ChatPrompt.js";
|
2
2
|
// default Vicuna 1 system message
|
3
3
|
const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
|
4
4
|
"The assistant gives helpful, detailed, and polite answers to the user's questions.";
|
@@ -17,12 +17,12 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
|
|
17
17
|
*/
|
18
18
|
export function chat() {
|
19
19
|
return {
|
20
|
-
format
|
21
|
-
validateChatPrompt(
|
22
|
-
let text =
|
23
|
-
? `${
|
20
|
+
format(prompt) {
|
21
|
+
validateChatPrompt(prompt);
|
22
|
+
let text = prompt.system != null
|
23
|
+
? `${prompt.system}\n\n`
|
24
24
|
: `${DEFAULT_SYSTEM_MESSAGE}\n\n`;
|
25
|
-
for (const { role, content } of
|
25
|
+
for (const { role, content } of prompt.messages) {
|
26
26
|
switch (role) {
|
27
27
|
case "user": {
|
28
28
|
text += `USER: ${content}\n`;
|
@@ -30,10 +30,10 @@ exports.VicunaPromptFormat = exports.TextPromptFormat = exports.Llama2PromptForm
|
|
30
30
|
exports.AlpacaPromptFormat = __importStar(require("./AlpacaPromptFormat.cjs"));
|
31
31
|
exports.ChatMLPromptFormat = __importStar(require("./ChatMLPromptFormat.cjs"));
|
32
32
|
__exportStar(require("./ChatPrompt.cjs"), exports);
|
33
|
-
__exportStar(require("./
|
33
|
+
__exportStar(require("./Content.cjs"), exports);
|
34
34
|
__exportStar(require("./InstructionPrompt.cjs"), exports);
|
35
35
|
exports.Llama2PromptFormat = __importStar(require("./Llama2PromptFormat.cjs"));
|
36
|
+
__exportStar(require("./InvalidPromptError.cjs"), exports);
|
36
37
|
exports.TextPromptFormat = __importStar(require("./TextPromptFormat.cjs"));
|
37
38
|
exports.VicunaPromptFormat = __importStar(require("./VicunaPromptFormat.cjs"));
|
38
39
|
__exportStar(require("./trimChatPrompt.cjs"), exports);
|
39
|
-
__exportStar(require("./validateChatPrompt.cjs"), exports);
|
@@ -1,10 +1,10 @@
|
|
1
1
|
export * as AlpacaPromptFormat from "./AlpacaPromptFormat.js";
|
2
2
|
export * as ChatMLPromptFormat from "./ChatMLPromptFormat.js";
|
3
3
|
export * from "./ChatPrompt.js";
|
4
|
-
export * from "./
|
4
|
+
export * from "./Content.js";
|
5
5
|
export * from "./InstructionPrompt.js";
|
6
6
|
export * as Llama2PromptFormat from "./Llama2PromptFormat.js";
|
7
|
+
export * from "./InvalidPromptError.js";
|
7
8
|
export * as TextPromptFormat from "./TextPromptFormat.js";
|
8
9
|
export * as VicunaPromptFormat from "./VicunaPromptFormat.js";
|
9
10
|
export * from "./trimChatPrompt.js";
|
10
|
-
export * from "./validateChatPrompt.js";
|
@@ -1,10 +1,10 @@
|
|
1
1
|
export * as AlpacaPromptFormat from "./AlpacaPromptFormat.js";
|
2
2
|
export * as ChatMLPromptFormat from "./ChatMLPromptFormat.js";
|
3
3
|
export * from "./ChatPrompt.js";
|
4
|
-
export * from "./
|
4
|
+
export * from "./Content.js";
|
5
5
|
export * from "./InstructionPrompt.js";
|
6
6
|
export * as Llama2PromptFormat from "./Llama2PromptFormat.js";
|
7
|
+
export * from "./InvalidPromptError.js";
|
7
8
|
export * as TextPromptFormat from "./TextPromptFormat.js";
|
8
9
|
export * as VicunaPromptFormat from "./VicunaPromptFormat.js";
|
9
10
|
export * from "./trimChatPrompt.js";
|
10
|
-
export * from "./validateChatPrompt.js";
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.trimChatPrompt = void 0;
|
4
|
-
const
|
4
|
+
const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
|
5
5
|
/**
|
6
6
|
* Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
|
7
7
|
*
|
@@ -14,7 +14,7 @@ const validateChatPrompt_js_1 = require("./validateChatPrompt.cjs");
|
|
14
14
|
*/
|
15
15
|
async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
|
16
16
|
(model.settings.maxCompletionTokens ?? model.contextWindowSize / 4), }) {
|
17
|
-
(0,
|
17
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
18
18
|
let minimalPrompt = {
|
19
19
|
system: prompt.system,
|
20
20
|
messages: [prompt.messages[prompt.messages.length - 1]], // last user message
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ChatPrompt } from "./ChatPrompt.js";
|
2
1
|
import { HasContextWindowSize, HasTokenizer, TextGenerationModel, TextGenerationModelSettings } from "../TextGenerationModel.js";
|
2
|
+
import { ChatPrompt } from "./ChatPrompt.js";
|
3
3
|
/**
|
4
4
|
* Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
|
5
5
|
*
|
@@ -1,16 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.chat = exports.instruction = exports.text = void 0;
|
4
|
-
const
|
4
|
+
const ChatPrompt_js_1 = require("../../model-function/generate-text/prompt-format/ChatPrompt.cjs");
|
5
5
|
/**
|
6
6
|
* Formats a text prompt as an Anthropic prompt.
|
7
7
|
*/
|
8
8
|
function text() {
|
9
9
|
return {
|
10
|
-
format
|
10
|
+
format(prompt) {
|
11
11
|
let text = "";
|
12
12
|
text += "\n\nHuman:";
|
13
|
-
text +=
|
13
|
+
text += prompt;
|
14
14
|
text += "\n\nAssistant:";
|
15
15
|
return text;
|
16
16
|
},
|
@@ -23,10 +23,10 @@ exports.text = text;
|
|
23
23
|
*/
|
24
24
|
function instruction() {
|
25
25
|
return {
|
26
|
-
format
|
27
|
-
let text =
|
26
|
+
format(prompt) {
|
27
|
+
let text = prompt.system ?? "";
|
28
28
|
text += "\n\nHuman:";
|
29
|
-
text +=
|
29
|
+
text += prompt.instruction;
|
30
30
|
text += "\n\nAssistant:";
|
31
31
|
return text;
|
32
32
|
},
|
@@ -41,10 +41,10 @@ exports.instruction = instruction;
|
|
41
41
|
*/
|
42
42
|
function chat() {
|
43
43
|
return {
|
44
|
-
format
|
45
|
-
(0,
|
46
|
-
let text =
|
47
|
-
for (const { role, content } of
|
44
|
+
format(prompt) {
|
45
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
46
|
+
let text = prompt.system ?? "";
|
47
|
+
for (const { role, content } of prompt.messages) {
|
48
48
|
switch (role) {
|
49
49
|
case "user": {
|
50
50
|
text += `\n\nHuman:${content}`;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { ChatPrompt } from "../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
2
|
-
import { InstructionPrompt } from "../../model-function/generate-text/prompt-format/InstructionPrompt.js";
|
3
1
|
import { TextGenerationPromptFormat } from "../../model-function/generate-text/TextGenerationPromptFormat.js";
|
2
|
+
import { ChatPrompt } from "../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
3
|
+
import { TextInstructionPrompt } from "../../model-function/generate-text/prompt-format/InstructionPrompt.js";
|
4
4
|
/**
|
5
5
|
* Formats a text prompt as an Anthropic prompt.
|
6
6
|
*/
|
@@ -8,7 +8,7 @@ export declare function text(): TextGenerationPromptFormat<string, string>;
|
|
8
8
|
/**
|
9
9
|
* Formats an instruction prompt as an Anthropic prompt.
|
10
10
|
*/
|
11
|
-
export declare function instruction(): TextGenerationPromptFormat<
|
11
|
+
export declare function instruction(): TextGenerationPromptFormat<TextInstructionPrompt, string>;
|
12
12
|
/**
|
13
13
|
* Formats a chat prompt as an Anthropic prompt.
|
14
14
|
*
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import { validateChatPrompt } from "../../model-function/generate-text/prompt-format/
|
1
|
+
import { validateChatPrompt, } from "../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
2
2
|
/**
|
3
3
|
* Formats a text prompt as an Anthropic prompt.
|
4
4
|
*/
|
5
5
|
export function text() {
|
6
6
|
return {
|
7
|
-
format
|
7
|
+
format(prompt) {
|
8
8
|
let text = "";
|
9
9
|
text += "\n\nHuman:";
|
10
|
-
text +=
|
10
|
+
text += prompt;
|
11
11
|
text += "\n\nAssistant:";
|
12
12
|
return text;
|
13
13
|
},
|
@@ -19,10 +19,10 @@ export function text() {
|
|
19
19
|
*/
|
20
20
|
export function instruction() {
|
21
21
|
return {
|
22
|
-
format
|
23
|
-
let text =
|
22
|
+
format(prompt) {
|
23
|
+
let text = prompt.system ?? "";
|
24
24
|
text += "\n\nHuman:";
|
25
|
-
text +=
|
25
|
+
text += prompt.instruction;
|
26
26
|
text += "\n\nAssistant:";
|
27
27
|
return text;
|
28
28
|
},
|
@@ -36,10 +36,10 @@ export function instruction() {
|
|
36
36
|
*/
|
37
37
|
export function chat() {
|
38
38
|
return {
|
39
|
-
format
|
40
|
-
validateChatPrompt(
|
41
|
-
let text =
|
42
|
-
for (const { role, content } of
|
39
|
+
format(prompt) {
|
40
|
+
validateChatPrompt(prompt);
|
41
|
+
let text = prompt.system ?? "";
|
42
|
+
for (const { role, content } of prompt.messages) {
|
43
43
|
switch (role) {
|
44
44
|
case "user": {
|
45
45
|
text += `\n\nHuman:${content}`;
|
@@ -65,7 +65,7 @@ export declare class AnthropicTextGenerationModel extends AbstractModel<Anthropi
|
|
65
65
|
/**
|
66
66
|
* Returns this model with an instruction prompt format.
|
67
67
|
*/
|
68
|
-
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").
|
68
|
+
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").TextInstructionPrompt, string, AnthropicTextGenerationModelSettings, this>;
|
69
69
|
/**
|
70
70
|
* Returns this model with a chat prompt format.
|
71
71
|
*/
|
@@ -87,7 +87,7 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
87
87
|
/**
|
88
88
|
* Returns this model with an instruction prompt format.
|
89
89
|
*/
|
90
|
-
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").
|
90
|
+
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").TextInstructionPrompt, string, CohereTextGenerationModelSettings, this>;
|
91
91
|
/**
|
92
92
|
* Returns this model with a chat prompt format.
|
93
93
|
*/
|
@@ -11,21 +11,30 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
|
|
11
11
|
*/
|
12
12
|
function instruction() {
|
13
13
|
return {
|
14
|
-
format
|
14
|
+
format(prompt) {
|
15
15
|
let text = "";
|
16
|
-
text += `${
|
16
|
+
text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
|
17
17
|
text += `USER: `;
|
18
|
-
|
19
|
-
|
18
|
+
// construct text and image mapping:
|
19
|
+
let imageCounter = 1;
|
20
|
+
const images = {};
|
21
|
+
for (const content of prompt.instruction) {
|
22
|
+
switch (content.type) {
|
23
|
+
case "text": {
|
24
|
+
text += content.text;
|
25
|
+
break;
|
26
|
+
}
|
27
|
+
case "image": {
|
28
|
+
text += `[img-${imageCounter}]`;
|
29
|
+
images[imageCounter.toString()] = content.base64Image;
|
30
|
+
imageCounter++;
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
text += `${content}\n`;
|
20
35
|
}
|
21
|
-
text += `${instruction.instruction}\n`;
|
22
36
|
text += `ASSISTANT: `;
|
23
|
-
return {
|
24
|
-
text,
|
25
|
-
images: instruction.image != null
|
26
|
-
? { "1": instruction.image.base64Content }
|
27
|
-
: undefined,
|
28
|
-
};
|
37
|
+
return { text, images };
|
29
38
|
},
|
30
39
|
stopSequences: [`\nUSER:`],
|
31
40
|
};
|
@@ -8,21 +8,30 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
|
|
8
8
|
*/
|
9
9
|
export function instruction() {
|
10
10
|
return {
|
11
|
-
format
|
11
|
+
format(prompt) {
|
12
12
|
let text = "";
|
13
|
-
text += `${
|
13
|
+
text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
|
14
14
|
text += `USER: `;
|
15
|
-
|
16
|
-
|
15
|
+
// construct text and image mapping:
|
16
|
+
let imageCounter = 1;
|
17
|
+
const images = {};
|
18
|
+
for (const content of prompt.instruction) {
|
19
|
+
switch (content.type) {
|
20
|
+
case "text": {
|
21
|
+
text += content.text;
|
22
|
+
break;
|
23
|
+
}
|
24
|
+
case "image": {
|
25
|
+
text += `[img-${imageCounter}]`;
|
26
|
+
images[imageCounter.toString()] = content.base64Image;
|
27
|
+
imageCounter++;
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
text += `${content}\n`;
|
17
32
|
}
|
18
|
-
text += `${instruction.instruction}\n`;
|
19
33
|
text += `ASSISTANT: `;
|
20
|
-
return {
|
21
|
-
text,
|
22
|
-
images: instruction.image != null
|
23
|
-
? { "1": instruction.image.base64Content }
|
24
|
-
: undefined,
|
25
|
-
};
|
34
|
+
return { text, images };
|
26
35
|
},
|
27
36
|
stopSequences: [`\nUSER:`],
|
28
37
|
};
|
@@ -176,7 +176,7 @@ export declare class OpenAICompletionModel extends AbstractModel<OpenAICompletio
|
|
176
176
|
/**
|
177
177
|
* Returns this model with an instruction prompt format.
|
178
178
|
*/
|
179
|
-
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").
|
179
|
+
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../index.js").TextInstructionPrompt, string, OpenAICompletionModelSettings, this>;
|
180
180
|
/**
|
181
181
|
* Returns this model with a chat prompt format.
|
182
182
|
*/
|
@@ -6,20 +6,25 @@ exports.OpenAIChatMessage = {
|
|
6
6
|
return { role: "system", content };
|
7
7
|
},
|
8
8
|
user(content, options) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
content
|
13
|
-
|
14
|
-
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
return {
|
10
|
+
role: "user",
|
11
|
+
content: typeof content === "string"
|
12
|
+
? content
|
13
|
+
: content.map((element) => {
|
14
|
+
switch (element.type) {
|
15
|
+
case "text": {
|
16
|
+
return { type: "text", text: element.text };
|
17
|
+
}
|
18
|
+
case "image": {
|
19
|
+
return {
|
20
|
+
type: "image_url",
|
21
|
+
image_url: `data:${element.mimeType ?? "image/jpeg"};base64,${element.base64Image}`,
|
22
|
+
};
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}),
|
26
|
+
name: options?.name,
|
27
|
+
};
|
23
28
|
},
|
24
29
|
/**
|
25
30
|
* Creates an assistant chat message. The assistant message can optionally contain tool calls.
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { MultiModalInput } from "../../../model-function/generate-text/prompt-format/Content.js";
|
1
2
|
import { ToolCall } from "../../../tool/ToolCall.js";
|
2
3
|
export type OpenAIChatMessage = {
|
3
4
|
role: "system";
|
@@ -43,12 +44,8 @@ export type OpenAIChatMessage = {
|
|
43
44
|
};
|
44
45
|
export declare const OpenAIChatMessage: {
|
45
46
|
system(content: string): OpenAIChatMessage;
|
46
|
-
user(content: string, options?: {
|
47
|
+
user(content: string | MultiModalInput, options?: {
|
47
48
|
name?: string;
|
48
|
-
image?: {
|
49
|
-
base64Content: string;
|
50
|
-
mimeType?: string;
|
51
|
-
};
|
52
49
|
}): OpenAIChatMessage;
|
53
50
|
/**
|
54
51
|
* Creates an assistant chat message. The assistant message can optionally contain tool calls.
|
@@ -3,20 +3,25 @@ export const OpenAIChatMessage = {
|
|
3
3
|
return { role: "system", content };
|
4
4
|
},
|
5
5
|
user(content, options) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
content
|
10
|
-
|
11
|
-
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
return {
|
7
|
+
role: "user",
|
8
|
+
content: typeof content === "string"
|
9
|
+
? content
|
10
|
+
: content.map((element) => {
|
11
|
+
switch (element.type) {
|
12
|
+
case "text": {
|
13
|
+
return { type: "text", text: element.text };
|
14
|
+
}
|
15
|
+
case "image": {
|
16
|
+
return {
|
17
|
+
type: "image_url",
|
18
|
+
image_url: `data:${element.mimeType ?? "image/jpeg"};base64,${element.base64Image}`,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}),
|
23
|
+
name: options?.name,
|
24
|
+
};
|
20
25
|
},
|
21
26
|
/**
|
22
27
|
* Creates an assistant chat message. The assistant message can optionally contain tool calls.
|
@@ -382,7 +382,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
|
|
382
382
|
/**
|
383
383
|
* Returns this model with an instruction prompt format.
|
384
384
|
*/
|
385
|
-
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../../index.js").InstructionPrompt, OpenAIChatMessage[], OpenAIChatSettings, this>;
|
385
|
+
withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../../index.js").InstructionPrompt | import("../../../index.js").TextInstructionPrompt, OpenAIChatMessage[], OpenAIChatSettings, this>;
|
386
386
|
/**
|
387
387
|
* Returns this model with a chat prompt format.
|
388
388
|
*/
|
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.chat = exports.instruction = exports.text = void 0;
|
4
|
-
const
|
4
|
+
const ChatPrompt_js_1 = require("../../../model-function/generate-text/prompt-format/ChatPrompt.cjs");
|
5
5
|
const OpenAIChatMessage_js_1 = require("./OpenAIChatMessage.cjs");
|
6
6
|
/**
|
7
7
|
* Formats a text prompt as an OpenAI chat prompt.
|
8
8
|
*/
|
9
9
|
function text() {
|
10
10
|
return {
|
11
|
-
format: (
|
11
|
+
format: (prompt) => [OpenAIChatMessage_js_1.OpenAIChatMessage.user(prompt)],
|
12
12
|
stopSequences: [],
|
13
13
|
};
|
14
14
|
}
|
@@ -18,14 +18,12 @@ exports.text = text;
|
|
18
18
|
*/
|
19
19
|
function instruction() {
|
20
20
|
return {
|
21
|
-
format
|
21
|
+
format(prompt) {
|
22
22
|
const messages = [];
|
23
|
-
if (
|
24
|
-
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.system(
|
23
|
+
if (prompt.system != null) {
|
24
|
+
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.system(prompt.system));
|
25
25
|
}
|
26
|
-
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.user(
|
27
|
-
image: instruction.image,
|
28
|
-
}));
|
26
|
+
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.user(prompt.instruction));
|
29
27
|
return messages;
|
30
28
|
},
|
31
29
|
stopSequences: [],
|
@@ -37,13 +35,13 @@ exports.instruction = instruction;
|
|
37
35
|
*/
|
38
36
|
function chat() {
|
39
37
|
return {
|
40
|
-
format
|
41
|
-
(0,
|
38
|
+
format(prompt) {
|
39
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
42
40
|
const messages = [];
|
43
|
-
if (
|
44
|
-
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.system(
|
41
|
+
if (prompt.system != null) {
|
42
|
+
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.system(prompt.system));
|
45
43
|
}
|
46
|
-
for (const { role, content } of
|
44
|
+
for (const { role, content } of prompt.messages) {
|
47
45
|
switch (role) {
|
48
46
|
case "user": {
|
49
47
|
messages.push(OpenAIChatMessage_js_1.OpenAIChatMessage.user(content));
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { TextGenerationPromptFormat } from "../../../model-function/generate-text/TextGenerationPromptFormat.js";
|
2
2
|
import { ChatPrompt } from "../../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
3
|
-
import { InstructionPrompt } from "../../../model-function/generate-text/prompt-format/InstructionPrompt.js";
|
3
|
+
import { InstructionPrompt, TextInstructionPrompt } from "../../../model-function/generate-text/prompt-format/InstructionPrompt.js";
|
4
4
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
5
5
|
/**
|
6
6
|
* Formats a text prompt as an OpenAI chat prompt.
|
@@ -9,7 +9,7 @@ export declare function text(): TextGenerationPromptFormat<string, Array<OpenAIC
|
|
9
9
|
/**
|
10
10
|
* Formats an instruction prompt as an OpenAI chat prompt.
|
11
11
|
*/
|
12
|
-
export declare function instruction(): TextGenerationPromptFormat<InstructionPrompt, Array<OpenAIChatMessage>>;
|
12
|
+
export declare function instruction(): TextGenerationPromptFormat<InstructionPrompt | TextInstructionPrompt, Array<OpenAIChatMessage>>;
|
13
13
|
/**
|
14
14
|
* Formats a chat prompt as an OpenAI chat prompt.
|
15
15
|
*/
|