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.
Files changed (54) hide show
  1. package/README.md +4 -3
  2. package/model-function/generate-text/prompt-format/AlpacaPromptFormat.cjs +10 -10
  3. package/model-function/generate-text/prompt-format/AlpacaPromptFormat.d.ts +2 -2
  4. package/model-function/generate-text/prompt-format/AlpacaPromptFormat.js +10 -10
  5. package/model-function/generate-text/prompt-format/ChatMLPromptFormat.cjs +15 -13
  6. package/model-function/generate-text/prompt-format/ChatMLPromptFormat.d.ts +3 -3
  7. package/model-function/generate-text/prompt-format/ChatMLPromptFormat.js +15 -13
  8. package/model-function/generate-text/prompt-format/ChatPrompt.cjs +24 -0
  9. package/model-function/generate-text/prompt-format/ChatPrompt.d.ts +6 -0
  10. package/model-function/generate-text/prompt-format/ChatPrompt.js +22 -1
  11. package/model-function/generate-text/prompt-format/Content.cjs +2 -0
  12. package/model-function/generate-text/prompt-format/Content.d.ts +20 -0
  13. package/model-function/generate-text/prompt-format/Content.js +1 -0
  14. package/model-function/generate-text/prompt-format/InstructionPrompt.d.ts +21 -16
  15. package/model-function/generate-text/prompt-format/InvalidPromptError.cjs +28 -0
  16. package/model-function/generate-text/prompt-format/InvalidPromptError.d.ts +13 -0
  17. package/model-function/generate-text/prompt-format/InvalidPromptError.js +24 -0
  18. package/model-function/generate-text/prompt-format/Llama2PromptFormat.cjs +14 -10
  19. package/model-function/generate-text/prompt-format/Llama2PromptFormat.d.ts +3 -3
  20. package/model-function/generate-text/prompt-format/Llama2PromptFormat.js +14 -10
  21. package/model-function/generate-text/prompt-format/TextPromptFormat.cjs +11 -11
  22. package/model-function/generate-text/prompt-format/TextPromptFormat.d.ts +3 -3
  23. package/model-function/generate-text/prompt-format/TextPromptFormat.js +11 -11
  24. package/model-function/generate-text/prompt-format/VicunaPromptFormat.cjs +6 -6
  25. package/model-function/generate-text/prompt-format/VicunaPromptFormat.d.ts +1 -1
  26. package/model-function/generate-text/prompt-format/VicunaPromptFormat.js +6 -6
  27. package/model-function/generate-text/prompt-format/index.cjs +2 -2
  28. package/model-function/generate-text/prompt-format/index.d.ts +2 -2
  29. package/model-function/generate-text/prompt-format/index.js +2 -2
  30. package/model-function/generate-text/prompt-format/trimChatPrompt.cjs +2 -2
  31. package/model-function/generate-text/prompt-format/trimChatPrompt.d.ts +1 -1
  32. package/model-function/generate-text/prompt-format/trimChatPrompt.js +1 -1
  33. package/model-provider/anthropic/AnthropicPromptFormat.cjs +10 -10
  34. package/model-provider/anthropic/AnthropicPromptFormat.d.ts +3 -3
  35. package/model-provider/anthropic/AnthropicPromptFormat.js +10 -10
  36. package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +1 -1
  37. package/model-provider/cohere/CohereTextGenerationModel.d.ts +1 -1
  38. package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.cjs +20 -11
  39. package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.js +20 -11
  40. package/model-provider/openai/OpenAICompletionModel.d.ts +1 -1
  41. package/model-provider/openai/chat/OpenAIChatMessage.cjs +19 -14
  42. package/model-provider/openai/chat/OpenAIChatMessage.d.ts +2 -5
  43. package/model-provider/openai/chat/OpenAIChatMessage.js +19 -14
  44. package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
  45. package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +11 -13
  46. package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +2 -2
  47. package/model-provider/openai/chat/OpenAIChatPromptFormat.js +11 -13
  48. package/package.json +1 -1
  49. package/model-function/generate-text/prompt-format/ChatPromptValidationError.cjs +0 -17
  50. package/model-function/generate-text/prompt-format/ChatPromptValidationError.d.ts +0 -8
  51. package/model-function/generate-text/prompt-format/ChatPromptValidationError.js +0 -13
  52. package/model-function/generate-text/prompt-format/validateChatPrompt.cjs +0 -24
  53. package/model-function/generate-text/prompt-format/validateChatPrompt.d.ts +0 -5
  54. 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/validateChatPrompt.js";
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: (instruction) => [OpenAIChatMessage.user(instruction)],
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: (instruction) => {
17
+ format(prompt) {
18
18
  const messages = [];
19
- if (instruction.system != null) {
20
- messages.push(OpenAIChatMessage.system(instruction.system));
19
+ if (prompt.system != null) {
20
+ messages.push(OpenAIChatMessage.system(prompt.system));
21
21
  }
22
- messages.push(OpenAIChatMessage.user(instruction.instruction, {
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: (chatPrompt) => {
36
- validateChatPrompt(chatPrompt);
33
+ format(prompt) {
34
+ validateChatPrompt(prompt);
37
35
  const messages = [];
38
- if (chatPrompt.system != null) {
39
- messages.push(OpenAIChatMessage.system(chatPrompt.system));
36
+ if (prompt.system != null) {
37
+ messages.push(OpenAIChatMessage.system(prompt.system));
40
38
  }
41
- for (const { role, content } of chatPrompt.messages) {
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,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building multi-modal AI applications.",
4
- "version": "0.79.0",
4
+ "version": "0.80.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -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,8 +0,0 @@
1
- export declare class ChatPromptValidationError extends Error {
2
- constructor(message: string);
3
- toJSON(): {
4
- name: string;
5
- message: string;
6
- stack: string | undefined;
7
- };
8
- }
@@ -1,13 +0,0 @@
1
- export class ChatPromptValidationError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = "ChatPromptValidationError";
5
- }
6
- toJSON() {
7
- return {
8
- name: this.name,
9
- message: this.message,
10
- stack: this.stack,
11
- };
12
- }
13
- }
@@ -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,5 +0,0 @@
1
- import { ChatPrompt } from "./ChatPrompt.js";
2
- /**
3
- * Checks if a chat prompt is valid. Throws a `ChatPromptValidationError` if it's not.
4
- */
5
- export declare function validateChatPrompt(chatPrompt: ChatPrompt): void;
@@ -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
- }