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,11 +1,11 @@
|
|
1
|
-
import { validateChatPrompt } from "../../../model-function/generate-text/prompt-format/
|
1
|
+
import { validateChatPrompt } from "../../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
2
2
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
3
3
|
/**
|
4
4
|
* Formats a text prompt as an OpenAI chat prompt.
|
5
5
|
*/
|
6
6
|
export function text() {
|
7
7
|
return {
|
8
|
-
format: (
|
8
|
+
format: (prompt) => [OpenAIChatMessage.user(prompt)],
|
9
9
|
stopSequences: [],
|
10
10
|
};
|
11
11
|
}
|
@@ -14,14 +14,12 @@ export function text() {
|
|
14
14
|
*/
|
15
15
|
export function instruction() {
|
16
16
|
return {
|
17
|
-
format
|
17
|
+
format(prompt) {
|
18
18
|
const messages = [];
|
19
|
-
if (
|
20
|
-
messages.push(OpenAIChatMessage.system(
|
19
|
+
if (prompt.system != null) {
|
20
|
+
messages.push(OpenAIChatMessage.system(prompt.system));
|
21
21
|
}
|
22
|
-
messages.push(OpenAIChatMessage.user(
|
23
|
-
image: instruction.image,
|
24
|
-
}));
|
22
|
+
messages.push(OpenAIChatMessage.user(prompt.instruction));
|
25
23
|
return messages;
|
26
24
|
},
|
27
25
|
stopSequences: [],
|
@@ -32,13 +30,13 @@ export function instruction() {
|
|
32
30
|
*/
|
33
31
|
export function chat() {
|
34
32
|
return {
|
35
|
-
format
|
36
|
-
validateChatPrompt(
|
33
|
+
format(prompt) {
|
34
|
+
validateChatPrompt(prompt);
|
37
35
|
const messages = [];
|
38
|
-
if (
|
39
|
-
messages.push(OpenAIChatMessage.system(
|
36
|
+
if (prompt.system != null) {
|
37
|
+
messages.push(OpenAIChatMessage.system(prompt.system));
|
40
38
|
}
|
41
|
-
for (const { role, content } of
|
39
|
+
for (const { role, content } of prompt.messages) {
|
42
40
|
switch (role) {
|
43
41
|
case "user": {
|
44
42
|
messages.push(OpenAIChatMessage.user(content));
|
package/package.json
CHANGED
@@ -1,17 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ChatPromptValidationError = void 0;
|
4
|
-
class ChatPromptValidationError extends Error {
|
5
|
-
constructor(message) {
|
6
|
-
super(message);
|
7
|
-
this.name = "ChatPromptValidationError";
|
8
|
-
}
|
9
|
-
toJSON() {
|
10
|
-
return {
|
11
|
-
name: this.name,
|
12
|
-
message: this.message,
|
13
|
-
stack: this.stack,
|
14
|
-
};
|
15
|
-
}
|
16
|
-
}
|
17
|
-
exports.ChatPromptValidationError = ChatPromptValidationError;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.validateChatPrompt = void 0;
|
4
|
-
const ChatPromptValidationError_js_1 = require("./ChatPromptValidationError.cjs");
|
5
|
-
/**
|
6
|
-
* Checks if a chat prompt is valid. Throws a `ChatPromptValidationError` if it's not.
|
7
|
-
*/
|
8
|
-
function validateChatPrompt(chatPrompt) {
|
9
|
-
const messages = chatPrompt.messages;
|
10
|
-
if (messages.length < 1) {
|
11
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError("ChatPrompt should have at least one message.");
|
12
|
-
}
|
13
|
-
for (let i = 0; i < messages.length; i++) {
|
14
|
-
const expectedRole = i % 2 === 0 ? "user" : "assistant";
|
15
|
-
const role = messages[i].role;
|
16
|
-
if (role !== expectedRole) {
|
17
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError(`Message at index ${i} should have role '${expectedRole}', but has role '${role}'.`);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
if (messages.length % 2 === 0) {
|
21
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError("The last message must be a user message.");
|
22
|
-
}
|
23
|
-
}
|
24
|
-
exports.validateChatPrompt = validateChatPrompt;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { ChatPromptValidationError } from "./ChatPromptValidationError.js";
|
2
|
-
/**
|
3
|
-
* Checks if a chat prompt is valid. Throws a `ChatPromptValidationError` if it's not.
|
4
|
-
*/
|
5
|
-
export function validateChatPrompt(chatPrompt) {
|
6
|
-
const messages = chatPrompt.messages;
|
7
|
-
if (messages.length < 1) {
|
8
|
-
throw new ChatPromptValidationError("ChatPrompt should have at least one message.");
|
9
|
-
}
|
10
|
-
for (let i = 0; i < messages.length; i++) {
|
11
|
-
const expectedRole = i % 2 === 0 ? "user" : "assistant";
|
12
|
-
const role = messages[i].role;
|
13
|
-
if (role !== expectedRole) {
|
14
|
-
throw new ChatPromptValidationError(`Message at index ${i} should have role '${expectedRole}', but has role '${role}'.`);
|
15
|
-
}
|
16
|
-
}
|
17
|
-
if (messages.length % 2 === 0) {
|
18
|
-
throw new ChatPromptValidationError("The last message must be a user message.");
|
19
|
-
}
|
20
|
-
}
|