modelfusion 0.46.0 → 0.47.1

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 (143) hide show
  1. package/README.md +23 -2
  2. package/index.cjs +0 -1
  3. package/index.d.ts +0 -1
  4. package/index.js +0 -1
  5. package/model-function/ModelFunctionPromise.cjs +37 -0
  6. package/model-function/ModelFunctionPromise.d.ts +18 -0
  7. package/model-function/ModelFunctionPromise.js +33 -0
  8. package/{prompt → model-function}/PromptFormat.d.ts +0 -5
  9. package/model-function/describe-image/describeImage.cjs +3 -2
  10. package/model-function/describe-image/describeImage.d.ts +1 -1
  11. package/model-function/describe-image/describeImage.js +3 -2
  12. package/model-function/embed/embed.cjs +5 -4
  13. package/model-function/embed/embed.d.ts +1 -1
  14. package/model-function/embed/embed.js +5 -4
  15. package/model-function/executeCall.cjs +3 -46
  16. package/model-function/executeCall.d.ts +5 -18
  17. package/model-function/executeCall.js +1 -43
  18. package/model-function/generate-image/ImageGenerationModel.d.ts +2 -0
  19. package/model-function/generate-image/ImageGenerationPromise.cjs +50 -0
  20. package/model-function/generate-image/ImageGenerationPromise.d.ts +22 -0
  21. package/model-function/generate-image/ImageGenerationPromise.js +46 -0
  22. package/model-function/generate-image/PromptFormatImageGenerationModel.cjs +44 -0
  23. package/model-function/generate-image/PromptFormatImageGenerationModel.d.ts +20 -0
  24. package/model-function/generate-image/PromptFormatImageGenerationModel.js +40 -0
  25. package/model-function/generate-image/generateImage.cjs +3 -2
  26. package/model-function/generate-image/generateImage.d.ts +2 -2
  27. package/model-function/generate-image/generateImage.js +3 -2
  28. package/model-function/generate-structure/fixJson.test.cjs +183 -181
  29. package/model-function/generate-structure/fixJson.test.js +181 -182
  30. package/model-function/generate-structure/generateStructure.cjs +3 -2
  31. package/model-function/generate-structure/generateStructure.d.ts +1 -1
  32. package/model-function/generate-structure/generateStructure.js +3 -2
  33. package/model-function/generate-structure/generateStructureOrText.cjs +3 -2
  34. package/model-function/generate-structure/generateStructureOrText.d.ts +1 -1
  35. package/model-function/generate-structure/generateStructureOrText.js +3 -2
  36. package/model-function/generate-structure/streamStructure.cjs +2 -7
  37. package/model-function/generate-structure/streamStructure.js +2 -4
  38. package/{prompt → model-function/generate-text}/AlpacaPromptFormat.d.ts +2 -2
  39. package/{prompt → model-function/generate-text}/Llama2PromptFormat.cjs +1 -1
  40. package/model-function/generate-text/Llama2PromptFormat.d.ts +13 -0
  41. package/{prompt → model-function/generate-text}/Llama2PromptFormat.js +1 -1
  42. package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.d.ts +7 -7
  43. package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.d.ts +6 -6
  44. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  45. package/model-function/generate-text/TextGenerationPromptFormat.cjs +2 -0
  46. package/model-function/generate-text/TextGenerationPromptFormat.d.ts +11 -0
  47. package/model-function/generate-text/TextGenerationPromptFormat.js +1 -0
  48. package/{prompt → model-function/generate-text}/TextPromptFormat.cjs +1 -1
  49. package/{prompt → model-function/generate-text}/TextPromptFormat.d.ts +4 -4
  50. package/{prompt → model-function/generate-text}/TextPromptFormat.js +1 -1
  51. package/{prompt → model-function/generate-text}/VicunaPromptFormat.cjs +1 -1
  52. package/{prompt → model-function/generate-text}/VicunaPromptFormat.d.ts +3 -3
  53. package/{prompt → model-function/generate-text}/VicunaPromptFormat.js +1 -1
  54. package/model-function/generate-text/generateText.cjs +6 -3
  55. package/model-function/generate-text/generateText.d.ts +1 -1
  56. package/model-function/generate-text/generateText.js +6 -3
  57. package/{prompt → model-function/generate-text}/index.cjs +9 -4
  58. package/model-function/generate-text/index.d.ts +16 -0
  59. package/model-function/generate-text/index.js +16 -0
  60. package/{prompt/chat → model-function/generate-text}/trimChatPrompt.d.ts +1 -1
  61. package/model-function/index.cjs +3 -5
  62. package/model-function/index.d.ts +3 -5
  63. package/model-function/index.js +3 -5
  64. package/model-function/synthesize-speech/synthesizeSpeech.cjs +3 -2
  65. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +1 -1
  66. package/model-function/synthesize-speech/synthesizeSpeech.js +3 -2
  67. package/model-function/transcribe-speech/transcribe.cjs +3 -2
  68. package/model-function/transcribe-speech/transcribe.d.ts +1 -1
  69. package/model-function/transcribe-speech/transcribe.js +3 -2
  70. package/model-provider/anthropic/AnthropicPromptFormat.cjs +1 -1
  71. package/model-provider/anthropic/AnthropicPromptFormat.d.ts +5 -5
  72. package/model-provider/anthropic/AnthropicPromptFormat.js +1 -1
  73. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +1 -1
  74. package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +3 -3
  75. package/model-provider/anthropic/AnthropicTextGenerationModel.js +1 -1
  76. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +11 -0
  77. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +12 -12
  78. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +11 -0
  79. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.cjs +12 -0
  80. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.d.ts +10 -0
  81. package/model-provider/automatic1111/Automatic1111ImageGenerationPrompt.js +8 -0
  82. package/model-provider/automatic1111/index.cjs +1 -0
  83. package/model-provider/automatic1111/index.d.ts +1 -0
  84. package/model-provider/automatic1111/index.js +1 -0
  85. package/model-provider/cohere/CohereTextGenerationModel.cjs +2 -2
  86. package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
  87. package/model-provider/cohere/CohereTextGenerationModel.js +2 -2
  88. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +2 -2
  89. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +5 -5
  90. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +2 -2
  91. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +1 -1
  92. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
  93. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +1 -1
  94. package/model-provider/openai/OpenAIImageGenerationModel.cjs +8 -1
  95. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +6 -3
  96. package/model-provider/openai/OpenAIImageGenerationModel.js +8 -1
  97. package/model-provider/openai/OpenAITextGenerationModel.cjs +2 -2
  98. package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
  99. package/model-provider/openai/OpenAITextGenerationModel.js +2 -2
  100. package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
  101. package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
  102. package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
  103. package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +1 -1
  104. package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +5 -5
  105. package/model-provider/openai/chat/OpenAIChatPromptFormat.js +1 -1
  106. package/model-provider/stability/StabilityImageGenerationModel.cjs +11 -0
  107. package/model-provider/stability/StabilityImageGenerationModel.d.ts +15 -14
  108. package/model-provider/stability/StabilityImageGenerationModel.js +11 -0
  109. package/model-provider/stability/StabilityImageGenerationPrompt.cjs +12 -0
  110. package/model-provider/stability/StabilityImageGenerationPrompt.d.ts +9 -0
  111. package/model-provider/stability/StabilityImageGenerationPrompt.js +8 -0
  112. package/model-provider/stability/index.cjs +1 -0
  113. package/model-provider/stability/index.d.ts +1 -0
  114. package/model-provider/stability/index.js +1 -0
  115. package/package.json +4 -4
  116. package/util/isDeepEqualData.cjs +53 -0
  117. package/util/isDeepEqualData.d.ts +8 -0
  118. package/util/isDeepEqualData.js +49 -0
  119. package/util/isDeepEqualData.test.cjs +108 -0
  120. package/util/isDeepEqualData.test.d.ts +1 -0
  121. package/util/isDeepEqualData.test.js +103 -0
  122. package/prompt/Llama2PromptFormat.d.ts +0 -13
  123. package/prompt/index.d.ts +0 -11
  124. package/prompt/index.js +0 -11
  125. /package/{prompt → model-function}/PromptFormat.cjs +0 -0
  126. /package/{prompt → model-function}/PromptFormat.js +0 -0
  127. /package/{prompt → model-function/generate-text}/AlpacaPromptFormat.cjs +0 -0
  128. /package/{prompt → model-function/generate-text}/AlpacaPromptFormat.js +0 -0
  129. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.cjs +0 -0
  130. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.d.ts +0 -0
  131. /package/{prompt/chat → model-function/generate-text}/ChatPrompt.js +0 -0
  132. /package/{prompt → model-function/generate-text}/InstructionPrompt.cjs +0 -0
  133. /package/{prompt → model-function/generate-text}/InstructionPrompt.d.ts +0 -0
  134. /package/{prompt → model-function/generate-text}/InstructionPrompt.js +0 -0
  135. /package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.cjs +0 -0
  136. /package/{prompt → model-function/generate-text}/PromptFormatTextGenerationModel.js +0 -0
  137. /package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.cjs +0 -0
  138. /package/{prompt → model-function/generate-text}/PromptFormatTextStreamingModel.js +0 -0
  139. /package/{prompt/chat → model-function/generate-text}/trimChatPrompt.cjs +0 -0
  140. /package/{prompt/chat → model-function/generate-text}/trimChatPrompt.js +0 -0
  141. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.cjs +0 -0
  142. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.d.ts +0 -0
  143. /package/{prompt/chat → model-function/generate-text}/validateChatPrompt.js +0 -0
@@ -2,8 +2,10 @@ import { z } from "zod";
2
2
  import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
3
3
  import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
4
4
  import { AbstractModel } from "../../model-function/AbstractModel.js";
5
+ import { PromptFormatImageGenerationModel } from "../../model-function/generate-image/PromptFormatImageGenerationModel.js";
5
6
  import { StabilityApiConfiguration } from "./StabilityApiConfiguration.js";
6
7
  import { failedStabilityCallResponseHandler } from "./StabilityError.js";
8
+ import { mapBasicPromptToStabilityFormat, } from "./StabilityImageGenerationPrompt.js";
7
9
  /**
8
10
  * Create an image generation model that calls the Stability AI image generation API.
9
11
  *
@@ -73,6 +75,15 @@ export class StabilityImageGenerationModel extends AbstractModel {
73
75
  base64Image: response.artifacts[0].base64,
74
76
  };
75
77
  }
78
+ withBasicPrompt() {
79
+ return this.withPromptFormat(mapBasicPromptToStabilityFormat());
80
+ }
81
+ withPromptFormat(promptFormat) {
82
+ return new PromptFormatImageGenerationModel({
83
+ model: this,
84
+ promptFormat,
85
+ });
86
+ }
76
87
  withSettings(additionalSettings) {
77
88
  return new StabilityImageGenerationModel(Object.assign({}, this.settings, additionalSettings));
78
89
  }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapBasicPromptToStabilityFormat = void 0;
4
+ /**
5
+ * Formats a basic text prompt as a Stability prompt.
6
+ */
7
+ function mapBasicPromptToStabilityFormat() {
8
+ return {
9
+ format: (description) => [{ text: description }],
10
+ };
11
+ }
12
+ exports.mapBasicPromptToStabilityFormat = mapBasicPromptToStabilityFormat;
@@ -0,0 +1,9 @@
1
+ import { PromptFormat } from "../../model-function/PromptFormat.js";
2
+ export type StabilityImageGenerationPrompt = Array<{
3
+ text: string;
4
+ weight?: number;
5
+ }>;
6
+ /**
7
+ * Formats a basic text prompt as a Stability prompt.
8
+ */
9
+ export declare function mapBasicPromptToStabilityFormat(): PromptFormat<string, StabilityImageGenerationPrompt>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formats a basic text prompt as a Stability prompt.
3
+ */
4
+ export function mapBasicPromptToStabilityFormat() {
5
+ return {
6
+ format: (description) => [{ text: description }],
7
+ };
8
+ }
@@ -19,3 +19,4 @@ __exportStar(require("./StabilityApiConfiguration.cjs"), exports);
19
19
  var StabilityError_js_1 = require("./StabilityError.cjs");
20
20
  Object.defineProperty(exports, "StabilityError", { enumerable: true, get: function () { return StabilityError_js_1.StabilityError; } });
21
21
  __exportStar(require("./StabilityImageGenerationModel.cjs"), exports);
22
+ __exportStar(require("./StabilityImageGenerationPrompt.cjs"), exports);
@@ -1,3 +1,4 @@
1
1
  export * from "./StabilityApiConfiguration.js";
2
2
  export { StabilityError, StabilityErrorData } from "./StabilityError.js";
3
3
  export * from "./StabilityImageGenerationModel.js";
4
+ export * from "./StabilityImageGenerationPrompt.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./StabilityApiConfiguration.js";
2
2
  export { StabilityError } from "./StabilityError.js";
3
3
  export * from "./StabilityImageGenerationModel.js";
4
+ export * from "./StabilityImageGenerationPrompt.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.46.0",
4
+ "version": "0.47.1",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -47,12 +47,12 @@
47
47
  "build": "npm run build:esm && npm run build:cjs",
48
48
  "build:esm": "tsc --outDir dist/",
49
49
  "build:cjs": "tsc --outDir build/cjs/ -p tsconfig.cjs.json && node bin/prepare-cjs.js",
50
- "test": "vitest",
51
- "dist": "npm run clean && npm run lint && npm run build && npm run dist:copy-files",
50
+ "test": "vitest run src",
51
+ "test-interactive": "vitest run",
52
+ "dist": "npm run clean && npm run lint && npm run test && npm run build && npm run dist:copy-files",
52
53
  "dist:copy-files": "copyfiles package.json README.md LICENSE dist"
53
54
  },
54
55
  "dependencies": {
55
- "deep-equal": "2.2.2",
56
56
  "eventsource-parser": "1.1.1",
57
57
  "js-tiktoken": "1.0.7",
58
58
  "nanoid": "3.3.6",
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeepEqualData = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ /**
6
+ * Performs a deep-equal comparison of two parsed JSON structures.
7
+ *
8
+ * @param {any} obj1 - The first object to compare.
9
+ * @param {any} obj2 - The second object to compare.
10
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
11
+ */
12
+ function isDeepEqualData(obj1, obj2) {
13
+ // Check for strict equality first
14
+ if (obj1 === obj2)
15
+ return true;
16
+ // Check if either is null or undefined
17
+ if (obj1 == null || obj2 == null)
18
+ return false;
19
+ // Check if both are objects
20
+ if (typeof obj1 !== "object" && typeof obj2 !== "object")
21
+ return obj1 === obj2;
22
+ // If they are not strictly equal, they both need to be Objects
23
+ if (obj1.constructor !== obj2.constructor)
24
+ return false;
25
+ // Special handling for Date objects
26
+ if (obj1 instanceof Date && obj2 instanceof Date) {
27
+ return obj1.getTime() === obj2.getTime();
28
+ }
29
+ // Handle arrays: compare length and then perform a recursive deep comparison on each item
30
+ if (Array.isArray(obj1)) {
31
+ if (obj1.length !== obj2.length)
32
+ return false;
33
+ for (let i = 0; i < obj1.length; i++) {
34
+ if (!isDeepEqualData(obj1[i], obj2[i]))
35
+ return false;
36
+ }
37
+ return true; // All array elements matched
38
+ }
39
+ // Compare the set of keys in each object
40
+ const keys1 = Object.keys(obj1);
41
+ const keys2 = Object.keys(obj2);
42
+ if (keys1.length !== keys2.length)
43
+ return false;
44
+ // Check each key-value pair recursively
45
+ for (const key of keys1) {
46
+ if (!keys2.includes(key))
47
+ return false;
48
+ if (!isDeepEqualData(obj1[key], obj2[key]))
49
+ return false;
50
+ }
51
+ return true; // All keys and values matched
52
+ }
53
+ exports.isDeepEqualData = isDeepEqualData;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Performs a deep-equal comparison of two parsed JSON structures.
3
+ *
4
+ * @param {any} obj1 - The first object to compare.
5
+ * @param {any} obj2 - The second object to compare.
6
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
7
+ */
8
+ export declare function isDeepEqualData(obj1: any, obj2: any): boolean;
@@ -0,0 +1,49 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Performs a deep-equal comparison of two parsed JSON structures.
4
+ *
5
+ * @param {any} obj1 - The first object to compare.
6
+ * @param {any} obj2 - The second object to compare.
7
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
8
+ */
9
+ export function isDeepEqualData(obj1, obj2) {
10
+ // Check for strict equality first
11
+ if (obj1 === obj2)
12
+ return true;
13
+ // Check if either is null or undefined
14
+ if (obj1 == null || obj2 == null)
15
+ return false;
16
+ // Check if both are objects
17
+ if (typeof obj1 !== "object" && typeof obj2 !== "object")
18
+ return obj1 === obj2;
19
+ // If they are not strictly equal, they both need to be Objects
20
+ if (obj1.constructor !== obj2.constructor)
21
+ return false;
22
+ // Special handling for Date objects
23
+ if (obj1 instanceof Date && obj2 instanceof Date) {
24
+ return obj1.getTime() === obj2.getTime();
25
+ }
26
+ // Handle arrays: compare length and then perform a recursive deep comparison on each item
27
+ if (Array.isArray(obj1)) {
28
+ if (obj1.length !== obj2.length)
29
+ return false;
30
+ for (let i = 0; i < obj1.length; i++) {
31
+ if (!isDeepEqualData(obj1[i], obj2[i]))
32
+ return false;
33
+ }
34
+ return true; // All array elements matched
35
+ }
36
+ // Compare the set of keys in each object
37
+ const keys1 = Object.keys(obj1);
38
+ const keys2 = Object.keys(obj2);
39
+ if (keys1.length !== keys2.length)
40
+ return false;
41
+ // Check each key-value pair recursively
42
+ for (const key of keys1) {
43
+ if (!keys2.includes(key))
44
+ return false;
45
+ if (!isDeepEqualData(obj1[key], obj2[key]))
46
+ return false;
47
+ }
48
+ return true; // All keys and values matched
49
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const vitest_1 = require("vitest");
8
+ const isDeepEqualData_js_1 = require("./isDeepEqualData.cjs");
9
+ (0, vitest_1.test)("checks if two primitives are equal", async () => {
10
+ let x = 1;
11
+ let y = 1;
12
+ let result = (0, isDeepEqualData_js_1.isDeepEqualData)(x, y);
13
+ node_assert_1.default.equal(result, true);
14
+ x = 1;
15
+ y = 2;
16
+ result = (0, isDeepEqualData_js_1.isDeepEqualData)(x, y);
17
+ node_assert_1.default.equal(result, false);
18
+ });
19
+ (0, vitest_1.test)("returns false for different types", async () => {
20
+ const obj = { a: 1 };
21
+ const num = 1;
22
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, num);
23
+ node_assert_1.default.equal(result, false);
24
+ });
25
+ (0, vitest_1.test)("returns false for null values compared with objects", async () => {
26
+ const obj = { a: 1 };
27
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, null);
28
+ node_assert_1.default.equal(result, false);
29
+ });
30
+ (0, vitest_1.test)("identifies two equal objects", async () => {
31
+ const obj1 = { a: 1, b: 2 };
32
+ const obj2 = { a: 1, b: 2 };
33
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
34
+ node_assert_1.default.equal(result, true);
35
+ });
36
+ (0, vitest_1.test)("identifies two objects with different values", async () => {
37
+ const obj1 = { a: 1, b: 2 };
38
+ const obj2 = { a: 1, b: 3 };
39
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
40
+ node_assert_1.default.equal(result, false);
41
+ });
42
+ (0, vitest_1.test)("identifies two objects with different number of keys", async () => {
43
+ const obj1 = { a: 1, b: 2 };
44
+ const obj2 = { a: 1, b: 2, c: 3 };
45
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
46
+ node_assert_1.default.equal(result, false);
47
+ });
48
+ (0, vitest_1.test)("handles nested objects", async () => {
49
+ const obj1 = { a: { c: 1 }, b: 2 };
50
+ const obj2 = { a: { c: 1 }, b: 2 };
51
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
52
+ node_assert_1.default.equal(result, true);
53
+ });
54
+ (0, vitest_1.test)("detects inequality in nested objects", async () => {
55
+ const obj1 = { a: { c: 1 }, b: 2 };
56
+ const obj2 = { a: { c: 2 }, b: 2 };
57
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
58
+ node_assert_1.default.equal(result, false);
59
+ });
60
+ (0, vitest_1.test)("compares arrays correctly", async () => {
61
+ const arr1 = [1, 2, 3];
62
+ const arr2 = [1, 2, 3];
63
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(arr1, arr2);
64
+ node_assert_1.default.equal(result, true);
65
+ const arr3 = [1, 2, 3];
66
+ const arr4 = [1, 2, 4];
67
+ const result2 = (0, isDeepEqualData_js_1.isDeepEqualData)(arr3, arr4);
68
+ node_assert_1.default.equal(result2, false);
69
+ });
70
+ (0, vitest_1.test)("returns false for null comparison with object", () => {
71
+ const obj = { a: 1 };
72
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, null);
73
+ node_assert_1.default.equal(result, false);
74
+ });
75
+ (0, vitest_1.test)("distinguishes between array and object with same enumerable properties", () => {
76
+ const obj = { 0: "one", 1: "two", length: 2 };
77
+ const arr = ["one", "two"];
78
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, arr);
79
+ node_assert_1.default.equal(result, false);
80
+ });
81
+ (0, vitest_1.test)("returns false when comparing objects with different prototypes", () => {
82
+ const obj1 = Object.create({ a: 1 });
83
+ const obj2 = Object.create(null);
84
+ obj1.b = 2;
85
+ obj2.b = 2;
86
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
87
+ node_assert_1.default.equal(result, false);
88
+ });
89
+ (0, vitest_1.test)("handles date object comparisons correctly", () => {
90
+ const date1 = new Date(2000, 0, 1);
91
+ const date2 = new Date(2000, 0, 1);
92
+ const date3 = new Date(2000, 0, 2);
93
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(date1, date2), true);
94
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(date1, date3), false);
95
+ });
96
+ (0, vitest_1.test)("handles function comparisons", () => {
97
+ const func1 = () => {
98
+ console.log("hello");
99
+ };
100
+ const func2 = () => {
101
+ console.log("hello");
102
+ };
103
+ const func3 = () => {
104
+ console.log("world");
105
+ };
106
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(func1, func2), false);
107
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(func1, func3), false);
108
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,103 @@
1
+ import assert from "node:assert";
2
+ import { test } from "vitest";
3
+ import { isDeepEqualData } from "./isDeepEqualData.js";
4
+ test("checks if two primitives are equal", async () => {
5
+ let x = 1;
6
+ let y = 1;
7
+ let result = isDeepEqualData(x, y);
8
+ assert.equal(result, true);
9
+ x = 1;
10
+ y = 2;
11
+ result = isDeepEqualData(x, y);
12
+ assert.equal(result, false);
13
+ });
14
+ test("returns false for different types", async () => {
15
+ const obj = { a: 1 };
16
+ const num = 1;
17
+ const result = isDeepEqualData(obj, num);
18
+ assert.equal(result, false);
19
+ });
20
+ test("returns false for null values compared with objects", async () => {
21
+ const obj = { a: 1 };
22
+ const result = isDeepEqualData(obj, null);
23
+ assert.equal(result, false);
24
+ });
25
+ test("identifies two equal objects", async () => {
26
+ const obj1 = { a: 1, b: 2 };
27
+ const obj2 = { a: 1, b: 2 };
28
+ const result = isDeepEqualData(obj1, obj2);
29
+ assert.equal(result, true);
30
+ });
31
+ test("identifies two objects with different values", async () => {
32
+ const obj1 = { a: 1, b: 2 };
33
+ const obj2 = { a: 1, b: 3 };
34
+ const result = isDeepEqualData(obj1, obj2);
35
+ assert.equal(result, false);
36
+ });
37
+ test("identifies two objects with different number of keys", async () => {
38
+ const obj1 = { a: 1, b: 2 };
39
+ const obj2 = { a: 1, b: 2, c: 3 };
40
+ const result = isDeepEqualData(obj1, obj2);
41
+ assert.equal(result, false);
42
+ });
43
+ test("handles nested objects", async () => {
44
+ const obj1 = { a: { c: 1 }, b: 2 };
45
+ const obj2 = { a: { c: 1 }, b: 2 };
46
+ const result = isDeepEqualData(obj1, obj2);
47
+ assert.equal(result, true);
48
+ });
49
+ test("detects inequality in nested objects", async () => {
50
+ const obj1 = { a: { c: 1 }, b: 2 };
51
+ const obj2 = { a: { c: 2 }, b: 2 };
52
+ const result = isDeepEqualData(obj1, obj2);
53
+ assert.equal(result, false);
54
+ });
55
+ test("compares arrays correctly", async () => {
56
+ const arr1 = [1, 2, 3];
57
+ const arr2 = [1, 2, 3];
58
+ const result = isDeepEqualData(arr1, arr2);
59
+ assert.equal(result, true);
60
+ const arr3 = [1, 2, 3];
61
+ const arr4 = [1, 2, 4];
62
+ const result2 = isDeepEqualData(arr3, arr4);
63
+ assert.equal(result2, false);
64
+ });
65
+ test("returns false for null comparison with object", () => {
66
+ const obj = { a: 1 };
67
+ const result = isDeepEqualData(obj, null);
68
+ assert.equal(result, false);
69
+ });
70
+ test("distinguishes between array and object with same enumerable properties", () => {
71
+ const obj = { 0: "one", 1: "two", length: 2 };
72
+ const arr = ["one", "two"];
73
+ const result = isDeepEqualData(obj, arr);
74
+ assert.equal(result, false);
75
+ });
76
+ test("returns false when comparing objects with different prototypes", () => {
77
+ const obj1 = Object.create({ a: 1 });
78
+ const obj2 = Object.create(null);
79
+ obj1.b = 2;
80
+ obj2.b = 2;
81
+ const result = isDeepEqualData(obj1, obj2);
82
+ assert.equal(result, false);
83
+ });
84
+ test("handles date object comparisons correctly", () => {
85
+ const date1 = new Date(2000, 0, 1);
86
+ const date2 = new Date(2000, 0, 1);
87
+ const date3 = new Date(2000, 0, 2);
88
+ assert.equal(isDeepEqualData(date1, date2), true);
89
+ assert.equal(isDeepEqualData(date1, date3), false);
90
+ });
91
+ test("handles function comparisons", () => {
92
+ const func1 = () => {
93
+ console.log("hello");
94
+ };
95
+ const func2 = () => {
96
+ console.log("hello");
97
+ };
98
+ const func3 = () => {
99
+ console.log("world");
100
+ };
101
+ assert.equal(isDeepEqualData(func1, func2), false);
102
+ assert.equal(isDeepEqualData(func1, func3), false);
103
+ });
@@ -1,13 +0,0 @@
1
- import { PromptFormat } from "./PromptFormat.js";
2
- import { InstructionPrompt } from "./InstructionPrompt.js";
3
- import { ChatPrompt } from "./chat/ChatPrompt.js";
4
- /**
5
- * Formats an instruction prompt as a Llama 2 prompt.
6
- *
7
- * @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
8
- */
9
- export declare function mapInstructionPromptToLlama2Format(): PromptFormat<InstructionPrompt, string>;
10
- /**
11
- * Formats a chat prompt as a Llama 2 prompt.
12
- */
13
- export declare function mapChatPromptToLlama2Format(): PromptFormat<ChatPrompt, string>;
package/prompt/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from "./AlpacaPromptFormat.js";
2
- export * from "./InstructionPrompt.js";
3
- export * from "./Llama2PromptFormat.js";
4
- export * from "./PromptFormat.js";
5
- export * from "./PromptFormatTextGenerationModel.js";
6
- export * from "./PromptFormatTextStreamingModel.js";
7
- export * from "./TextPromptFormat.js";
8
- export * from "./VicunaPromptFormat.js";
9
- export * from "./chat/ChatPrompt.js";
10
- export * from "./chat/trimChatPrompt.js";
11
- export * from "./chat/validateChatPrompt.js";
package/prompt/index.js DELETED
@@ -1,11 +0,0 @@
1
- export * from "./AlpacaPromptFormat.js";
2
- export * from "./InstructionPrompt.js";
3
- export * from "./Llama2PromptFormat.js";
4
- export * from "./PromptFormat.js";
5
- export * from "./PromptFormatTextGenerationModel.js";
6
- export * from "./PromptFormatTextStreamingModel.js";
7
- export * from "./TextPromptFormat.js";
8
- export * from "./VicunaPromptFormat.js";
9
- export * from "./chat/ChatPrompt.js";
10
- export * from "./chat/trimChatPrompt.js";
11
- export * from "./chat/validateChatPrompt.js";
File without changes
File without changes