modelfusion 0.78.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/PromptFormatTextGenerationModel.cjs +14 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.d.ts +4 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.js +14 -0
- 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 -10
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.js +15 -10
- 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/ollama/OllamaTextGenerationModel.cjs +7 -0
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +2 -0
- package/model-provider/ollama/OllamaTextGenerationModel.js +7 -0
- 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/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
- package/tool/{ToolCallParseError.cjs → generate-tool-call/ToolCallParseError.cjs} +1 -1
- package/tool/{ToolCallParseError.js → generate-tool-call/ToolCallParseError.js} +1 -1
- package/tool/generate-tool-call/index.cjs +1 -0
- package/tool/generate-tool-call/index.d.ts +1 -0
- package/tool/generate-tool-call/index.js +1 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs +60 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +41 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js +56 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.cjs +36 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.d.ts +15 -0
- package/tool/generate-tool-calls-or-text/ToolCallsOrTextParseError.js +32 -0
- package/tool/generate-tool-calls-or-text/index.cjs +2 -0
- package/tool/generate-tool-calls-or-text/index.d.ts +2 -0
- package/tool/generate-tool-calls-or-text/index.js +2 -0
- 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
- /package/tool/{ToolCallParseError.d.ts → generate-tool-call/ToolCallParseError.d.ts} +0 -0
@@ -1,13 +1,13 @@
|
|
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("./ChatPrompt.cjs");
|
5
5
|
/**
|
6
6
|
* Formats a text prompt as a basic text prompt. Does not change the text prompt in any way.
|
7
7
|
*/
|
8
8
|
const text = () => ({
|
9
9
|
stopSequences: [],
|
10
|
-
format: (
|
10
|
+
format: (prompt) => prompt,
|
11
11
|
});
|
12
12
|
exports.text = text;
|
13
13
|
/**
|
@@ -15,12 +15,12 @@ exports.text = text;
|
|
15
15
|
*/
|
16
16
|
const instruction = () => ({
|
17
17
|
stopSequences: [],
|
18
|
-
format
|
18
|
+
format(prompt) {
|
19
19
|
let text = "";
|
20
|
-
if (
|
21
|
-
text += `${
|
20
|
+
if (prompt.system != null) {
|
21
|
+
text += `${prompt.system}\n\n`;
|
22
22
|
}
|
23
|
-
text +=
|
23
|
+
text += prompt.instruction;
|
24
24
|
return text;
|
25
25
|
},
|
26
26
|
});
|
@@ -33,12 +33,12 @@ exports.instruction = instruction;
|
|
33
33
|
* @param system The label of the system in the chat. Optional, defaults to no prefix.
|
34
34
|
*/
|
35
35
|
const chat = ({ user = "user", assistant = "assistant", system, } = {}) => ({
|
36
|
-
format
|
37
|
-
(0,
|
38
|
-
let text =
|
39
|
-
? `${system != null ? `${system}:` : ""}${
|
36
|
+
format(prompt) {
|
37
|
+
(0, ChatPrompt_js_1.validateChatPrompt)(prompt);
|
38
|
+
let text = prompt.system != null
|
39
|
+
? `${system != null ? `${system}:` : ""}${prompt.system}\n\n`
|
40
40
|
: "";
|
41
|
-
for (const { role, content } of
|
41
|
+
for (const { role, content } of prompt.messages) {
|
42
42
|
switch (role) {
|
43
43
|
case "user": {
|
44
44
|
text += `${user}:\n${content}\n\n`;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { ChatPrompt } from "./ChatPrompt.js";
|
2
|
-
import { InstructionPrompt } from "./InstructionPrompt.js";
|
3
1
|
import { TextGenerationPromptFormat } from "../TextGenerationPromptFormat.js";
|
2
|
+
import { ChatPrompt } from "./ChatPrompt.js";
|
3
|
+
import { TextInstructionPrompt } from "./InstructionPrompt.js";
|
4
4
|
/**
|
5
5
|
* Formats a text prompt as a basic text prompt. Does not change the text prompt in any way.
|
6
6
|
*/
|
@@ -8,7 +8,7 @@ export declare const text: () => TextGenerationPromptFormat<string, string>;
|
|
8
8
|
/**
|
9
9
|
* Formats an instruction prompt as a basic text prompt.
|
10
10
|
*/
|
11
|
-
export declare const instruction: () => TextGenerationPromptFormat<
|
11
|
+
export declare const instruction: () => TextGenerationPromptFormat<TextInstructionPrompt, string>;
|
12
12
|
/**
|
13
13
|
* Formats a chat prompt as a basic text prompt.
|
14
14
|
*
|
@@ -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
|
};
|
@@ -8,6 +8,7 @@ const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
|
8
8
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
9
9
|
const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
|
10
10
|
const TextGenerationToolCallModel_js_1 = require("../../tool/generate-tool-call/TextGenerationToolCallModel.cjs");
|
11
|
+
const TextGenerationToolCallsOrGenerateTextModel_js_1 = require("../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs");
|
11
12
|
const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
|
12
13
|
const parseJsonStream_js_1 = require("../../util/streaming/parseJsonStream.cjs");
|
13
14
|
const OllamaApiConfiguration_js_1 = require("./OllamaApiConfiguration.cjs");
|
@@ -101,6 +102,12 @@ class OllamaTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
101
102
|
format: promptFormat,
|
102
103
|
});
|
103
104
|
}
|
105
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
106
|
+
return new TextGenerationToolCallsOrGenerateTextModel_js_1.TextGenerationToolCallsOrGenerateTextModel({
|
107
|
+
model: this,
|
108
|
+
format: promptFormat,
|
109
|
+
});
|
110
|
+
}
|
104
111
|
withPromptFormat(promptFormat) {
|
105
112
|
return new PromptFormatTextStreamingModel_js_1.PromptFormatTextStreamingModel({
|
106
113
|
model: this.withSettings({
|
@@ -8,6 +8,7 @@ import { PromptFormatTextStreamingModel } from "../../model-function/generate-te
|
|
8
8
|
import { TextGenerationModelSettings, TextStreamingModel } from "../../model-function/generate-text/TextGenerationModel.js";
|
9
9
|
import { TextGenerationPromptFormat } from "../../model-function/generate-text/TextGenerationPromptFormat.js";
|
10
10
|
import { TextGenerationToolCallModel, ToolCallPromptFormat } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
11
|
+
import { TextGenerationToolCallsOrGenerateTextModel, ToolCallsOrGenerateTextPromptFormat } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
11
12
|
/**
|
12
13
|
* @see https://github.com/jmorganca/ollama/blob/main/docs/api.md#generate-a-completion
|
13
14
|
*/
|
@@ -137,6 +138,7 @@ export declare class OllamaTextGenerationModel<CONTEXT_WINDOW_SIZE extends numbe
|
|
137
138
|
}>;
|
138
139
|
doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
|
139
140
|
asToolCallGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallPromptFormat<INPUT_PROMPT, string>): TextGenerationToolCallModel<INPUT_PROMPT, string, this>;
|
141
|
+
asToolCallsOrTextGenerationModel<INPUT_PROMPT>(promptFormat: ToolCallsOrGenerateTextPromptFormat<INPUT_PROMPT, string>): TextGenerationToolCallsOrGenerateTextModel<INPUT_PROMPT, string, this>;
|
140
142
|
withPromptFormat<INPUT_PROMPT>(promptFormat: TextGenerationPromptFormat<INPUT_PROMPT, string>): PromptFormatTextStreamingModel<INPUT_PROMPT, string, OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>, this>;
|
141
143
|
withSettings(additionalSettings: Partial<OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>>): this;
|
142
144
|
}
|
@@ -5,6 +5,7 @@ import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
|
5
5
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
6
6
|
import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
|
7
7
|
import { TextGenerationToolCallModel, } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
8
|
+
import { TextGenerationToolCallsOrGenerateTextModel, } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
8
9
|
import { AsyncQueue } from "../../util/AsyncQueue.js";
|
9
10
|
import { parseJsonStream } from "../../util/streaming/parseJsonStream.js";
|
10
11
|
import { OllamaApiConfiguration } from "./OllamaApiConfiguration.js";
|
@@ -98,6 +99,12 @@ export class OllamaTextGenerationModel extends AbstractModel {
|
|
98
99
|
format: promptFormat,
|
99
100
|
});
|
100
101
|
}
|
102
|
+
asToolCallsOrTextGenerationModel(promptFormat) {
|
103
|
+
return new TextGenerationToolCallsOrGenerateTextModel({
|
104
|
+
model: this,
|
105
|
+
format: promptFormat,
|
106
|
+
});
|
107
|
+
}
|
101
108
|
withPromptFormat(promptFormat) {
|
102
109
|
return new PromptFormatTextStreamingModel({
|
103
110
|
model: this.withSettings({
|
@@ -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.
|