modelfusion 0.103.0 → 0.104.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.cjs +2 -1
  3. package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.d.ts +2 -2
  4. package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.js +2 -1
  5. package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.cjs +5 -4
  6. package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.d.ts +4 -4
  7. package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.js +5 -4
  8. package/model-function/generate-text/prompt-template/ChatPrompt.cjs +0 -24
  9. package/model-function/generate-text/prompt-template/ChatPrompt.d.ts +11 -34
  10. package/model-function/generate-text/prompt-template/ChatPrompt.js +1 -22
  11. package/model-function/generate-text/prompt-template/Content.cjs +9 -0
  12. package/model-function/generate-text/prompt-template/Content.d.ts +9 -4
  13. package/model-function/generate-text/prompt-template/Content.js +7 -1
  14. package/model-function/generate-text/prompt-template/InstructionPrompt.d.ts +6 -22
  15. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +36 -5
  16. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +16 -4
  17. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +34 -4
  18. package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.cjs +5 -4
  19. package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.d.ts +4 -4
  20. package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js +5 -4
  21. package/model-function/generate-text/prompt-template/TextPromptTemplate.cjs +3 -4
  22. package/model-function/generate-text/prompt-template/TextPromptTemplate.d.ts +4 -4
  23. package/model-function/generate-text/prompt-template/TextPromptTemplate.js +3 -4
  24. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +3 -3
  25. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.d.ts +2 -2
  26. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +3 -3
  27. package/model-function/generate-text/prompt-template/trimChatPrompt.cjs +0 -2
  28. package/model-function/generate-text/prompt-template/trimChatPrompt.d.ts +4 -4
  29. package/model-function/generate-text/prompt-template/trimChatPrompt.js +0 -2
  30. package/model-provider/anthropic/AnthropicPromptTemplate.cjs +5 -4
  31. package/model-provider/anthropic/AnthropicPromptTemplate.d.ts +4 -4
  32. package/model-provider/anthropic/AnthropicPromptTemplate.js +5 -4
  33. package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +2 -2
  34. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +1 -1
  35. package/model-provider/cohere/CohereTextGenerationModel.d.ts +2 -2
  36. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.cjs +23 -16
  37. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.d.ts +4 -4
  38. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.js +23 -16
  39. package/model-provider/mistral/MistralChatModel.d.ts +2 -2
  40. package/model-provider/mistral/MistralPromptTemplate.cjs +5 -4
  41. package/model-provider/mistral/MistralPromptTemplate.d.ts +4 -4
  42. package/model-provider/mistral/MistralPromptTemplate.js +5 -4
  43. package/model-provider/ollama/OllamaChatModel.d.ts +2 -2
  44. package/model-provider/ollama/OllamaChatPromptTemplate.cjs +9 -13
  45. package/model-provider/ollama/OllamaChatPromptTemplate.d.ts +4 -4
  46. package/model-provider/ollama/OllamaChatPromptTemplate.js +9 -13
  47. package/model-provider/openai/OpenAICompletionModel.d.ts +2 -2
  48. package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +2 -2
  49. package/model-provider/openai/chat/OpenAIChatMessage.d.ts +2 -2
  50. package/model-provider/openai/chat/OpenAIChatModel.d.ts +2 -2
  51. package/model-provider/openai/chat/OpenAIChatPromptTemplate.cjs +0 -2
  52. package/model-provider/openai/chat/OpenAIChatPromptTemplate.d.ts +4 -4
  53. package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +0 -2
  54. package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +2 -2
  55. package/model-provider/stability/StabilityImageGenerationModel.d.ts +1 -1
  56. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
4
+ const Content_js_1 = require("./Content.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
  */
@@ -20,7 +20,7 @@ const instruction = () => ({
20
20
  if (prompt.system != null) {
21
21
  text += `${prompt.system}\n\n`;
22
22
  }
23
- text += `${prompt.instruction}\n\n`;
23
+ text += `${(0, Content_js_1.validateContentIsString)(prompt.instruction, prompt)}\n\n`;
24
24
  if (prompt.responsePrefix != null) {
25
25
  text += prompt.responsePrefix;
26
26
  }
@@ -37,14 +37,13 @@ exports.instruction = instruction;
37
37
  */
38
38
  const chat = ({ user = "user", assistant = "assistant", system, } = {}) => ({
39
39
  format(prompt) {
40
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
41
40
  let text = prompt.system != null
42
41
  ? `${system != null ? `${system}:` : ""}${prompt.system}\n\n`
43
42
  : "";
44
43
  for (const { role, content } of prompt.messages) {
45
44
  switch (role) {
46
45
  case "user": {
47
- text += `${user}:\n${content}\n\n`;
46
+ text += `${user}:\n${(0, Content_js_1.validateContentIsString)(content, prompt)}\n\n`;
48
47
  break;
49
48
  }
50
49
  case "assistant": {
@@ -1,6 +1,6 @@
1
1
  import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
2
- import { TextChatPrompt } from "./ChatPrompt.js";
3
- import { TextInstructionPrompt } from "./InstructionPrompt.js";
2
+ import { ChatPrompt } from "./ChatPrompt.js";
3
+ import { InstructionPrompt } 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: () => TextGenerationPromptTemplate<string, string>;
8
8
  /**
9
9
  * Formats an instruction prompt as a basic text prompt.
10
10
  */
11
- export declare const instruction: () => TextGenerationPromptTemplate<TextInstructionPrompt, string>;
11
+ export declare const instruction: () => TextGenerationPromptTemplate<InstructionPrompt, string>;
12
12
  /**
13
13
  * Formats a chat prompt as a basic text prompt.
14
14
  *
@@ -20,4 +20,4 @@ export declare const chat: (options?: {
20
20
  user?: string;
21
21
  assistant?: string;
22
22
  system?: string;
23
- }) => TextGenerationPromptTemplate<TextChatPrompt, string>;
23
+ }) => TextGenerationPromptTemplate<ChatPrompt, string>;
@@ -1,4 +1,4 @@
1
- import { validateChatPrompt } from "./ChatPrompt.js";
1
+ import { validateContentIsString } from "./Content.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
  */
@@ -16,7 +16,7 @@ export const instruction = () => ({
16
16
  if (prompt.system != null) {
17
17
  text += `${prompt.system}\n\n`;
18
18
  }
19
- text += `${prompt.instruction}\n\n`;
19
+ text += `${validateContentIsString(prompt.instruction, prompt)}\n\n`;
20
20
  if (prompt.responsePrefix != null) {
21
21
  text += prompt.responsePrefix;
22
22
  }
@@ -32,14 +32,13 @@ export const instruction = () => ({
32
32
  */
33
33
  export const chat = ({ user = "user", assistant = "assistant", system, } = {}) => ({
34
34
  format(prompt) {
35
- validateChatPrompt(prompt);
36
35
  let text = prompt.system != null
37
36
  ? `${system != null ? `${system}:` : ""}${prompt.system}\n\n`
38
37
  : "";
39
38
  for (const { role, content } of prompt.messages) {
40
39
  switch (role) {
41
40
  case "user": {
42
- text += `${user}:\n${content}\n\n`;
41
+ text += `${user}:\n${validateContentIsString(content, prompt)}\n\n`;
43
42
  break;
44
43
  }
45
44
  case "assistant": {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = void 0;
4
- const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
4
+ const Content_js_1 = require("./Content.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.";
@@ -21,14 +21,14 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
21
21
  function chat() {
22
22
  return {
23
23
  format(prompt) {
24
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
25
24
  let text = prompt.system != null
26
25
  ? `${prompt.system}\n\n`
27
26
  : `${DEFAULT_SYSTEM_MESSAGE}\n\n`;
28
27
  for (const { role, content } of prompt.messages) {
29
28
  switch (role) {
30
29
  case "user": {
31
- text += `USER: ${content}\n`;
30
+ const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
31
+ text += `USER: ${textContent}\n`;
32
32
  break;
33
33
  }
34
34
  case "assistant": {
@@ -1,5 +1,5 @@
1
1
  import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
2
- import { TextChatPrompt } from "./ChatPrompt.js";
2
+ import { ChatPrompt } from "./ChatPrompt.js";
3
3
  /**
4
4
  * Formats a chat prompt as a Vicuna prompt.
5
5
  *
@@ -13,4 +13,4 @@ import { TextChatPrompt } from "./ChatPrompt.js";
13
13
  * ASSISTANT:
14
14
  * ```
15
15
  */
16
- export declare function chat(): TextGenerationPromptTemplate<TextChatPrompt, string>;
16
+ export declare function chat(): TextGenerationPromptTemplate<ChatPrompt, string>;
@@ -1,4 +1,4 @@
1
- import { validateChatPrompt } from "./ChatPrompt.js";
1
+ import { validateContentIsString } from "./Content.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.";
@@ -18,14 +18,14 @@ const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial
18
18
  export function chat() {
19
19
  return {
20
20
  format(prompt) {
21
- validateChatPrompt(prompt);
22
21
  let text = prompt.system != null
23
22
  ? `${prompt.system}\n\n`
24
23
  : `${DEFAULT_SYSTEM_MESSAGE}\n\n`;
25
24
  for (const { role, content } of prompt.messages) {
26
25
  switch (role) {
27
26
  case "user": {
28
- text += `USER: ${content}\n`;
27
+ const textContent = validateContentIsString(content, prompt);
28
+ text += `USER: ${textContent}\n`;
29
29
  break;
30
30
  }
31
31
  case "assistant": {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.trimChatPrompt = void 0;
4
- const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
5
4
  /**
6
5
  * Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
7
6
  *
@@ -14,7 +13,6 @@ const ChatPrompt_js_1 = require("./ChatPrompt.cjs");
14
13
  */
15
14
  async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
16
15
  (model.settings.maxGenerationTokens ?? model.contextWindowSize / 4), }) {
17
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
18
16
  let minimalPrompt = {
19
17
  system: prompt.system,
20
18
  messages: [prompt.messages[prompt.messages.length - 1]], // last user message
@@ -1,5 +1,5 @@
1
1
  import { HasContextWindowSize, HasTokenizer, TextGenerationModel, TextGenerationModelSettings } from "../TextGenerationModel.js";
2
- import { TextChatPrompt } from "./ChatPrompt.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
  *
@@ -11,7 +11,7 @@ import { TextChatPrompt } from "./ChatPrompt.js";
11
11
  * @see https://modelfusion.dev/guide/function/generate-text#limiting-the-chat-length
12
12
  */
13
13
  export declare function trimChatPrompt({ prompt, model, tokenLimit, }: {
14
- prompt: TextChatPrompt;
15
- model: TextGenerationModel<TextChatPrompt, TextGenerationModelSettings> & HasTokenizer<TextChatPrompt> & HasContextWindowSize;
14
+ prompt: ChatPrompt;
15
+ model: TextGenerationModel<ChatPrompt, TextGenerationModelSettings> & HasTokenizer<ChatPrompt> & HasContextWindowSize;
16
16
  tokenLimit?: number;
17
- }): Promise<TextChatPrompt>;
17
+ }): Promise<ChatPrompt>;
@@ -1,4 +1,3 @@
1
- import { validateChatPrompt } from "./ChatPrompt.js";
2
1
  /**
3
2
  * Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
4
3
  *
@@ -11,7 +10,6 @@ import { validateChatPrompt } from "./ChatPrompt.js";
11
10
  */
12
11
  export async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
13
12
  (model.settings.maxGenerationTokens ?? model.contextWindowSize / 4), }) {
14
- validateChatPrompt(prompt);
15
13
  let minimalPrompt = {
16
14
  system: prompt.system,
17
15
  messages: [prompt.messages[prompt.messages.length - 1]], // last user message
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const ChatPrompt_js_1 = require("../../model-function/generate-text/prompt-template/ChatPrompt.cjs");
4
+ const Content_js_1 = require("../../model-function/generate-text/prompt-template/Content.cjs");
5
5
  const HUMAN_PREFIX = "\n\nHuman:";
6
6
  const ASSISTANT_PREFIX = "\n\nAssistant:";
7
7
  /**
@@ -26,9 +26,10 @@ exports.text = text;
26
26
  function instruction() {
27
27
  return {
28
28
  format(prompt) {
29
+ const instruction = (0, Content_js_1.validateContentIsString)(prompt.instruction, prompt);
29
30
  let text = prompt.system ?? "";
30
31
  text += HUMAN_PREFIX;
31
- text += prompt.instruction;
32
+ text += instruction;
32
33
  text += ASSISTANT_PREFIX;
33
34
  if (prompt.responsePrefix != null) {
34
35
  text += prompt.responsePrefix;
@@ -47,13 +48,13 @@ exports.instruction = instruction;
47
48
  function chat() {
48
49
  return {
49
50
  format(prompt) {
50
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
51
51
  let text = prompt.system ?? "";
52
52
  for (const { role, content } of prompt.messages) {
53
53
  switch (role) {
54
54
  case "user": {
55
+ const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
55
56
  text += HUMAN_PREFIX;
56
- text += content;
57
+ text += textContent;
57
58
  break;
58
59
  }
59
60
  case "assistant": {
@@ -1,6 +1,6 @@
1
1
  import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
2
- import { TextChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
- import { TextInstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
2
+ import { ChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
+ import { InstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
4
4
  /**
5
5
  * Formats a text prompt as an Anthropic prompt.
6
6
  */
@@ -8,10 +8,10 @@ export declare function text(): TextGenerationPromptTemplate<string, string>;
8
8
  /**
9
9
  * Formats an instruction prompt as an Anthropic prompt.
10
10
  */
11
- export declare function instruction(): TextGenerationPromptTemplate<TextInstructionPrompt, string>;
11
+ export declare function instruction(): TextGenerationPromptTemplate<InstructionPrompt, string>;
12
12
  /**
13
13
  * Formats a chat prompt as an Anthropic prompt.
14
14
  *
15
15
  * @see https://docs.anthropic.com/claude/docs/constructing-a-prompt
16
16
  */
17
- export declare function chat(): TextGenerationPromptTemplate<TextChatPrompt, string>;
17
+ export declare function chat(): TextGenerationPromptTemplate<ChatPrompt, string>;
@@ -1,4 +1,4 @@
1
- import { validateChatPrompt, } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
1
+ import { validateContentIsString } from "../../model-function/generate-text/prompt-template/Content.js";
2
2
  const HUMAN_PREFIX = "\n\nHuman:";
3
3
  const ASSISTANT_PREFIX = "\n\nAssistant:";
4
4
  /**
@@ -22,9 +22,10 @@ export function text() {
22
22
  export function instruction() {
23
23
  return {
24
24
  format(prompt) {
25
+ const instruction = validateContentIsString(prompt.instruction, prompt);
25
26
  let text = prompt.system ?? "";
26
27
  text += HUMAN_PREFIX;
27
- text += prompt.instruction;
28
+ text += instruction;
28
29
  text += ASSISTANT_PREFIX;
29
30
  if (prompt.responsePrefix != null) {
30
31
  text += prompt.responsePrefix;
@@ -42,13 +43,13 @@ export function instruction() {
42
43
  export function chat() {
43
44
  return {
44
45
  format(prompt) {
45
- validateChatPrompt(prompt);
46
46
  let text = prompt.system ?? "";
47
47
  for (const { role, content } of prompt.messages) {
48
48
  switch (role) {
49
49
  case "user": {
50
+ const textContent = validateContentIsString(content, prompt);
50
51
  text += HUMAN_PREFIX;
51
- text += content;
52
+ text += textContent;
52
53
  break;
53
54
  }
54
55
  case "assistant": {
@@ -70,11 +70,11 @@ export declare class AnthropicTextGenerationModel extends AbstractModel<Anthropi
70
70
  /**
71
71
  * Returns this model with an instruction prompt template.
72
72
  */
73
- withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextInstructionPrompt, string, AnthropicTextGenerationModelSettings, this>;
73
+ withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").InstructionPrompt, string, AnthropicTextGenerationModelSettings, this>;
74
74
  /**
75
75
  * Returns this model with a chat prompt template.
76
76
  */
77
- withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextChatPrompt, string, AnthropicTextGenerationModelSettings, this>;
77
+ withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").ChatPrompt, string, AnthropicTextGenerationModelSettings, this>;
78
78
  withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, string>): PromptTemplateTextStreamingModel<INPUT_PROMPT, string, AnthropicTextGenerationModelSettings, this>;
79
79
  withSettings(additionalSettings: Partial<AnthropicTextGenerationModelSettings>): this;
80
80
  }
@@ -49,7 +49,7 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
49
49
  }>;
50
50
  withTextPrompt(): PromptTemplateImageGenerationModel<string, Automatic1111ImageGenerationPrompt, Automatic1111ImageGenerationSettings, this>;
51
51
  withPromptTemplate<INPUT_PROMPT>(promptTemplate: PromptTemplate<INPUT_PROMPT, Automatic1111ImageGenerationPrompt>): PromptTemplateImageGenerationModel<INPUT_PROMPT, Automatic1111ImageGenerationPrompt, Automatic1111ImageGenerationSettings, this>;
52
- withSettings(additionalSettings: Automatic1111ImageGenerationSettings): this;
52
+ withSettings(additionalSettings: Partial<Automatic1111ImageGenerationSettings>): this;
53
53
  }
54
54
  declare const Automatic1111ImageGenerationResponseSchema: z.ZodObject<{
55
55
  images: z.ZodArray<z.ZodString, "many">;
@@ -91,14 +91,14 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
91
91
  /**
92
92
  * Returns this model with an instruction prompt template.
93
93
  */
94
- withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextInstructionPrompt, string, CohereTextGenerationModelSettings, this>;
94
+ withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").InstructionPrompt, string, CohereTextGenerationModelSettings, this>;
95
95
  /**
96
96
  * Returns this model with a chat prompt template.
97
97
  */
98
98
  withChatPrompt(options?: {
99
99
  user?: string;
100
100
  assistant?: string;
101
- }): PromptTemplateTextStreamingModel<import("../../index.js").TextChatPrompt, string, CohereTextGenerationModelSettings, this>;
101
+ }): PromptTemplateTextStreamingModel<import("../../index.js").ChatPrompt, string, CohereTextGenerationModelSettings, this>;
102
102
  withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, string>): PromptTemplateTextStreamingModel<INPUT_PROMPT, string, CohereTextGenerationModelSettings, this>;
103
103
  withSettings(additionalSettings: Partial<CohereTextGenerationModelSettings>): this;
104
104
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = void 0;
4
- const ChatPrompt_js_1 = require("../../model-function/generate-text/prompt-template/ChatPrompt.cjs");
5
4
  // default Vicuna 1 system message
6
5
  const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
7
6
  "The assistant gives helpful, detailed, and polite answers to the user's questions.";
@@ -16,23 +15,28 @@ function instruction() {
16
15
  let text = "";
17
16
  text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
18
17
  text += `USER: `;
19
- // construct text and image mapping:
20
- let imageCounter = 1;
21
18
  const images = {};
22
- for (const content of prompt.instruction) {
23
- switch (content.type) {
24
- case "text": {
25
- text += content.text;
26
- break;
27
- }
28
- case "image": {
29
- text += `[img-${imageCounter}]`;
30
- images[imageCounter.toString()] = content.base64Image;
31
- imageCounter++;
32
- break;
19
+ if (typeof prompt.instruction === "string") {
20
+ text += `${prompt.instruction}\n`;
21
+ }
22
+ else {
23
+ // construct text and image mapping:
24
+ let imageCounter = 1;
25
+ for (const content of prompt.instruction) {
26
+ switch (content.type) {
27
+ case "text": {
28
+ text += content.text;
29
+ break;
30
+ }
31
+ case "image": {
32
+ text += `[img-${imageCounter}]`;
33
+ images[imageCounter.toString()] = content.base64Image;
34
+ imageCounter++;
35
+ break;
36
+ }
33
37
  }
38
+ text += `${content}\n`;
34
39
  }
35
- text += `${content}\n`;
36
40
  }
37
41
  text += `\nASSISTANT: `;
38
42
  return { text, images };
@@ -44,7 +48,6 @@ exports.instruction = instruction;
44
48
  function chat() {
45
49
  return {
46
50
  format(prompt) {
47
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
48
51
  let text = "";
49
52
  text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
50
53
  // construct text and image mapping:
@@ -54,6 +57,10 @@ function chat() {
54
57
  switch (role) {
55
58
  case "user": {
56
59
  text += `USER: `;
60
+ if (typeof content === "string") {
61
+ text += content;
62
+ break;
63
+ }
57
64
  for (const part of content) {
58
65
  switch (part.type) {
59
66
  case "text": {
@@ -1,11 +1,11 @@
1
1
  import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
2
- import { MultiModalChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
- import { MultiModalInstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
2
+ import { ChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
+ import { InstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
4
4
  import { LlamaCppTextGenerationPrompt } from "./LlamaCppTextGenerationModel.js";
5
5
  /**
6
6
  * BakLLaVA 1 uses a Vicuna 1 prompt. This mapping combines it with the LlamaCpp prompt structure.
7
7
  *
8
8
  * @see https://github.com/SkunkworksAI/BakLLaVA
9
9
  */
10
- export declare function instruction(): TextGenerationPromptTemplate<MultiModalInstructionPrompt, LlamaCppTextGenerationPrompt>;
11
- export declare function chat(): TextGenerationPromptTemplate<MultiModalChatPrompt, LlamaCppTextGenerationPrompt>;
10
+ export declare function instruction(): TextGenerationPromptTemplate<InstructionPrompt, LlamaCppTextGenerationPrompt>;
11
+ export declare function chat(): TextGenerationPromptTemplate<ChatPrompt, LlamaCppTextGenerationPrompt>;
@@ -1,4 +1,3 @@
1
- import { validateChatPrompt, } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
2
1
  // default Vicuna 1 system message
3
2
  const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
4
3
  "The assistant gives helpful, detailed, and polite answers to the user's questions.";
@@ -13,23 +12,28 @@ export function instruction() {
13
12
  let text = "";
14
13
  text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
15
14
  text += `USER: `;
16
- // construct text and image mapping:
17
- let imageCounter = 1;
18
15
  const images = {};
19
- for (const content of prompt.instruction) {
20
- switch (content.type) {
21
- case "text": {
22
- text += content.text;
23
- break;
24
- }
25
- case "image": {
26
- text += `[img-${imageCounter}]`;
27
- images[imageCounter.toString()] = content.base64Image;
28
- imageCounter++;
29
- break;
16
+ if (typeof prompt.instruction === "string") {
17
+ text += `${prompt.instruction}\n`;
18
+ }
19
+ else {
20
+ // construct text and image mapping:
21
+ let imageCounter = 1;
22
+ for (const content of prompt.instruction) {
23
+ switch (content.type) {
24
+ case "text": {
25
+ text += content.text;
26
+ break;
27
+ }
28
+ case "image": {
29
+ text += `[img-${imageCounter}]`;
30
+ images[imageCounter.toString()] = content.base64Image;
31
+ imageCounter++;
32
+ break;
33
+ }
30
34
  }
35
+ text += `${content}\n`;
31
36
  }
32
- text += `${content}\n`;
33
37
  }
34
38
  text += `\nASSISTANT: `;
35
39
  return { text, images };
@@ -40,7 +44,6 @@ export function instruction() {
40
44
  export function chat() {
41
45
  return {
42
46
  format(prompt) {
43
- validateChatPrompt(prompt);
44
47
  let text = "";
45
48
  text += `${prompt.system ?? DEFAULT_SYSTEM_MESSAGE}\n\n`;
46
49
  // construct text and image mapping:
@@ -50,6 +53,10 @@ export function chat() {
50
53
  switch (role) {
51
54
  case "user": {
52
55
  text += `USER: `;
56
+ if (typeof content === "string") {
57
+ text += content;
58
+ break;
59
+ }
53
60
  for (const part of content) {
54
61
  switch (part.type) {
55
62
  case "text": {
@@ -93,11 +93,11 @@ export declare class MistralChatModel extends AbstractModel<MistralChatModelSett
93
93
  /**
94
94
  * Returns this model with an instruction prompt template.
95
95
  */
96
- withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextInstructionPrompt, MistralChatPrompt, MistralChatModelSettings, this>;
96
+ withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").InstructionPrompt, MistralChatPrompt, MistralChatModelSettings, this>;
97
97
  /**
98
98
  * Returns this model with a chat prompt template.
99
99
  */
100
- withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextChatPrompt, MistralChatPrompt, MistralChatModelSettings, this>;
100
+ withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").ChatPrompt, MistralChatPrompt, MistralChatModelSettings, this>;
101
101
  withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, MistralChatPrompt>): PromptTemplateTextStreamingModel<INPUT_PROMPT, MistralChatPrompt, MistralChatModelSettings, this>;
102
102
  withSettings(additionalSettings: Partial<MistralChatModelSettings>): this;
103
103
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const ChatPrompt_js_1 = require("../../model-function/generate-text/prompt-template/ChatPrompt.cjs");
4
+ const Content_js_1 = require("../../model-function/generate-text/prompt-template/Content.cjs");
5
5
  /**
6
6
  * Formats a text prompt as a Mistral prompt.
7
7
  */
@@ -22,7 +22,8 @@ function instruction() {
22
22
  if (prompt.system != null) {
23
23
  messages.push({ role: "system", content: prompt.system });
24
24
  }
25
- messages.push({ role: "user", content: prompt.instruction });
25
+ const instruction = (0, Content_js_1.validateContentIsString)(prompt.instruction, prompt);
26
+ messages.push({ role: "user", content: instruction });
26
27
  return messages;
27
28
  },
28
29
  stopSequences: [],
@@ -35,7 +36,6 @@ exports.instruction = instruction;
35
36
  function chat() {
36
37
  return {
37
38
  format(prompt) {
38
- (0, ChatPrompt_js_1.validateChatPrompt)(prompt);
39
39
  const messages = [];
40
40
  if (prompt.system != null) {
41
41
  messages.push({ role: "system", content: prompt.system });
@@ -43,7 +43,8 @@ function chat() {
43
43
  for (const { role, content } of prompt.messages) {
44
44
  switch (role) {
45
45
  case "user": {
46
- messages.push({ role: "user", content });
46
+ const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
47
+ messages.push({ role: "user", content: textContent });
47
48
  break;
48
49
  }
49
50
  case "assistant": {
@@ -1,6 +1,6 @@
1
1
  import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
2
- import { TextChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
- import { TextInstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
2
+ import { ChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
3
+ import { InstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
4
4
  import { MistralChatPrompt } from "./MistralChatModel.js";
5
5
  /**
6
6
  * Formats a text prompt as a Mistral prompt.
@@ -9,8 +9,8 @@ export declare function text(): TextGenerationPromptTemplate<string, MistralChat
9
9
  /**
10
10
  * Formats an instruction prompt as a Mistral prompt.
11
11
  */
12
- export declare function instruction(): TextGenerationPromptTemplate<TextInstructionPrompt, MistralChatPrompt>;
12
+ export declare function instruction(): TextGenerationPromptTemplate<InstructionPrompt, MistralChatPrompt>;
13
13
  /**
14
14
  * Formats a chat prompt as a Mistral prompt.
15
15
  */
16
- export declare function chat(): TextGenerationPromptTemplate<TextChatPrompt, MistralChatPrompt>;
16
+ export declare function chat(): TextGenerationPromptTemplate<ChatPrompt, MistralChatPrompt>;
@@ -1,4 +1,4 @@
1
- import { validateChatPrompt, } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
1
+ import { validateContentIsString } from "../../model-function/generate-text/prompt-template/Content.js";
2
2
  /**
3
3
  * Formats a text prompt as a Mistral prompt.
4
4
  */
@@ -18,7 +18,8 @@ export function instruction() {
18
18
  if (prompt.system != null) {
19
19
  messages.push({ role: "system", content: prompt.system });
20
20
  }
21
- messages.push({ role: "user", content: prompt.instruction });
21
+ const instruction = validateContentIsString(prompt.instruction, prompt);
22
+ messages.push({ role: "user", content: instruction });
22
23
  return messages;
23
24
  },
24
25
  stopSequences: [],
@@ -30,7 +31,6 @@ export function instruction() {
30
31
  export function chat() {
31
32
  return {
32
33
  format(prompt) {
33
- validateChatPrompt(prompt);
34
34
  const messages = [];
35
35
  if (prompt.system != null) {
36
36
  messages.push({ role: "system", content: prompt.system });
@@ -38,7 +38,8 @@ export function chat() {
38
38
  for (const { role, content } of prompt.messages) {
39
39
  switch (role) {
40
40
  case "user": {
41
- messages.push({ role: "user", content });
41
+ const textContent = validateContentIsString(content, prompt);
42
+ messages.push({ role: "user", content: textContent });
42
43
  break;
43
44
  }
44
45
  case "assistant": {
@@ -67,11 +67,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
67
67
  /**
68
68
  * Returns this model with an instruction prompt template.
69
69
  */
70
- withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").MultiModalInstructionPrompt | import("../../index.js").TextInstructionPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
70
+ withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").InstructionPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
71
71
  /**
72
72
  * Returns this model with a chat prompt template.
73
73
  */
74
- withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextChatPrompt | import("../../index.js").MultiModalChatPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
74
+ withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").ChatPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
75
75
  withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, OllamaChatPrompt>): PromptTemplateTextStreamingModel<INPUT_PROMPT, OllamaChatPrompt, OllamaChatModelSettings, this>;
76
76
  withSettings(additionalSettings: Partial<OllamaChatModelSettings>): this;
77
77
  }