modelfusion 0.47.0 → 0.47.2
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 +37 -36
- package/core/structure/Schema.d.ts +5 -5
- package/core/structure/UncheckedSchema.cjs +2 -2
- package/core/structure/UncheckedSchema.d.ts +2 -2
- package/core/structure/UncheckedSchema.js +2 -2
- package/core/structure/ZodSchema.cjs +2 -5
- package/core/structure/ZodSchema.d.ts +2 -2
- package/core/structure/ZodSchema.js +2 -5
- package/event-source/readEventSource.cjs +5 -8
- package/event-source/readEventSource.d.ts +1 -1
- package/event-source/readEventSource.js +5 -5
- package/event-source/readEventSourceStream.cjs +3 -6
- package/event-source/readEventSourceStream.js +3 -3
- package/guard/fixStructure.cjs +50 -0
- package/guard/fixStructure.d.ts +50 -0
- package/guard/fixStructure.js +50 -0
- package/guard/guard.d.ts +1 -1
- package/model-function/generate-structure/fixJson.test.cjs +183 -181
- package/model-function/generate-structure/fixJson.test.js +181 -182
- package/model-function/generate-structure/generateStructure.cjs +1 -1
- package/model-function/generate-structure/generateStructure.js +1 -1
- package/model-function/generate-structure/generateStructureOrText.cjs +1 -1
- package/model-function/generate-structure/generateStructureOrText.js +1 -1
- package/model-function/generate-structure/streamStructure.cjs +3 -8
- package/model-function/generate-structure/streamStructure.js +3 -5
- package/model-provider/anthropic/AnthropicError.cjs +7 -14
- package/model-provider/anthropic/AnthropicError.js +7 -11
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +2 -15
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +2 -12
- package/model-provider/automatic1111/Automatic1111Error.cjs +2 -5
- package/model-provider/automatic1111/Automatic1111Error.d.ts +1 -1
- package/model-provider/automatic1111/Automatic1111Error.js +2 -2
- package/model-provider/cohere/CohereError.cjs +2 -5
- package/model-provider/cohere/CohereError.js +2 -2
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +8 -11
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +1 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.js +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.cjs +22 -21
- package/model-provider/cohere/CohereTextGenerationModel.js +22 -18
- package/model-provider/cohere/CohereTokenizer.cjs +12 -15
- package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
- package/model-provider/cohere/CohereTokenizer.js +1 -1
- package/model-provider/huggingface/HuggingFaceError.cjs +7 -31
- package/model-provider/huggingface/HuggingFaceError.js +7 -28
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.cjs +3 -6
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.js +1 -1
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +2 -5
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +3 -6
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +1 -1
- package/model-provider/llamacpp/LlamaCppError.cjs +7 -30
- package/model-provider/llamacpp/LlamaCppError.js +7 -27
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +3 -6
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +1 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +53 -66
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +3 -13
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +3 -6
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppTokenizer.js +1 -1
- package/model-provider/openai/OpenAIError.cjs +2 -5
- package/model-provider/openai/OpenAIError.js +2 -2
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +11 -14
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +1 -1
- package/model-provider/openai/OpenAITextEmbeddingModel.js +1 -1
- package/model-provider/openai/OpenAITextGenerationModel.cjs +26 -39
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAITextGenerationModel.js +3 -13
- package/model-provider/openai/OpenAITranscriptionModel.cjs +20 -23
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -1
- package/model-provider/openai/OpenAITranscriptionModel.js +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.cjs +21 -21
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.js +2 -2
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +2 -6
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +2 -3
- package/model-provider/stability/StabilityError.cjs +2 -5
- package/model-provider/stability/StabilityError.js +2 -2
- package/package.json +4 -4
- package/util/JSONParseError.cjs +33 -0
- package/util/JSONParseError.d.ts +9 -0
- package/util/JSONParseError.js +29 -0
- package/util/index.cjs +2 -0
- package/util/index.d.ts +2 -0
- package/util/index.js +2 -0
- package/util/isDeepEqualData.cjs +53 -0
- package/util/isDeepEqualData.d.ts +8 -0
- package/util/isDeepEqualData.js +49 -0
- package/util/isDeepEqualData.test.cjs +108 -0
- package/util/isDeepEqualData.test.d.ts +1 -0
- package/util/isDeepEqualData.test.js +103 -0
- package/util/parseJSON.cjs +67 -0
- package/util/parseJSON.d.ts +18 -0
- package/util/parseJSON.js +58 -0
- package/vector-index/memory/MemoryVectorIndex.cjs +7 -10
- package/vector-index/memory/MemoryVectorIndex.js +3 -3
@@ -1,12 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.failedAutomatic1111CallResponseHandler = exports.Automatic1111Error = exports.automatic1111ErrorDataSchema = void 0;
|
7
4
|
const zod_1 = require("zod");
|
8
|
-
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
9
5
|
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const parseJSON_js_1 = require("../../util/parseJSON.cjs");
|
10
7
|
exports.automatic1111ErrorDataSchema = zod_1.z.object({
|
11
8
|
error: zod_1.z.string(),
|
12
9
|
detail: zod_1.z.string(),
|
@@ -28,7 +25,7 @@ class Automatic1111Error extends ApiCallError_js_1.ApiCallError {
|
|
28
25
|
exports.Automatic1111Error = Automatic1111Error;
|
29
26
|
const failedAutomatic1111CallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
30
27
|
const responseBody = await response.text();
|
31
|
-
const parsedError =
|
28
|
+
const parsedError = (0, parseJSON_js_1.parseJsonWithZod)(responseBody, exports.automatic1111ErrorDataSchema);
|
32
29
|
return new Automatic1111Error({
|
33
30
|
url,
|
34
31
|
requestBodyValues,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
-
import { ResponseHandler } from "../../core/api/postToApi.js";
|
3
2
|
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
3
|
+
import { ResponseHandler } from "../../core/api/postToApi.js";
|
4
4
|
export declare const automatic1111ErrorDataSchema: z.ZodObject<{
|
5
5
|
error: z.ZodString;
|
6
6
|
detail: z.ZodString;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
-
import SecureJSON from "secure-json-parse";
|
3
2
|
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
3
|
+
import { parseJsonWithZod } from "../../util/parseJSON.js";
|
4
4
|
export const automatic1111ErrorDataSchema = z.object({
|
5
5
|
error: z.string(),
|
6
6
|
detail: z.string(),
|
@@ -21,7 +21,7 @@ export class Automatic1111Error extends ApiCallError {
|
|
21
21
|
}
|
22
22
|
export const failedAutomatic1111CallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
23
23
|
const responseBody = await response.text();
|
24
|
-
const parsedError =
|
24
|
+
const parsedError = parseJsonWithZod(responseBody, automatic1111ErrorDataSchema);
|
25
25
|
return new Automatic1111Error({
|
26
26
|
url,
|
27
27
|
requestBodyValues,
|
@@ -1,12 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.failedCohereCallResponseHandler = exports.CohereError = exports.cohereErrorDataSchema = void 0;
|
7
|
-
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
4
|
const zod_1 = require("zod");
|
9
5
|
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const parseJSON_js_1 = require("../../util/parseJSON.cjs");
|
10
7
|
exports.cohereErrorDataSchema = zod_1.z.object({
|
11
8
|
message: zod_1.z.string(),
|
12
9
|
});
|
@@ -36,7 +33,7 @@ const failedCohereCallResponseHandler = async ({ response, url, requestBodyValue
|
|
36
33
|
},
|
37
34
|
});
|
38
35
|
}
|
39
|
-
const parsedError =
|
36
|
+
const parsedError = (0, parseJSON_js_1.parseJsonWithZod)(responseBody, exports.cohereErrorDataSchema);
|
40
37
|
return new CohereError({
|
41
38
|
url,
|
42
39
|
requestBodyValues,
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import SecureJSON from "secure-json-parse";
|
2
1
|
import { z } from "zod";
|
3
2
|
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
3
|
+
import { parseJsonWithZod } from "../../util/parseJSON.js";
|
4
4
|
export const cohereErrorDataSchema = z.object({
|
5
5
|
message: z.string(),
|
6
6
|
});
|
@@ -29,7 +29,7 @@ export const failedCohereCallResponseHandler = async ({ response, url, requestBo
|
|
29
29
|
},
|
30
30
|
});
|
31
31
|
}
|
32
|
-
const parsedError =
|
32
|
+
const parsedError = parseJsonWithZod(responseBody, cohereErrorDataSchema);
|
33
33
|
return new CohereError({
|
34
34
|
url,
|
35
35
|
requestBodyValues,
|
@@ -1,10 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.CohereTextEmbeddingModel = exports.COHERE_TEXT_EMBEDDING_MODELS = void 0;
|
7
|
-
const zod_1 =
|
4
|
+
const zod_1 = require("zod");
|
8
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
9
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
7
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
@@ -124,13 +121,13 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
124
121
|
}
|
125
122
|
}
|
126
123
|
exports.CohereTextEmbeddingModel = CohereTextEmbeddingModel;
|
127
|
-
const cohereTextEmbeddingResponseSchema = zod_1.
|
128
|
-
id: zod_1.
|
129
|
-
texts: zod_1.
|
130
|
-
embeddings: zod_1.
|
131
|
-
meta: zod_1.
|
132
|
-
api_version: zod_1.
|
133
|
-
version: zod_1.
|
124
|
+
const cohereTextEmbeddingResponseSchema = zod_1.z.object({
|
125
|
+
id: zod_1.z.string(),
|
126
|
+
texts: zod_1.z.array(zod_1.z.string()),
|
127
|
+
embeddings: zod_1.z.array(zod_1.z.array(zod_1.z.number())),
|
128
|
+
meta: zod_1.z.object({
|
129
|
+
api_version: zod_1.z.object({
|
130
|
+
version: zod_1.z.string(),
|
134
131
|
}),
|
135
132
|
}),
|
136
133
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import z from "zod";
|
1
|
+
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";
|
@@ -1,10 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.CohereTextGenerationResponseFormat = exports.CohereTextGenerationModel = exports.COHERE_TEXT_GENERATION_MODELS = void 0;
|
7
|
-
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
4
|
const zod_1 = require("zod");
|
9
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
10
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
@@ -13,6 +9,7 @@ const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
|
13
9
|
const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
|
14
10
|
const TextPromptFormat_js_1 = require("../../model-function/generate-text/TextPromptFormat.cjs");
|
15
11
|
const countTokens_js_1 = require("../../model-function/tokenize-text/countTokens.cjs");
|
12
|
+
const parseJSON_js_1 = require("../../util/parseJSON.cjs");
|
16
13
|
const CohereApiConfiguration_js_1 = require("./CohereApiConfiguration.cjs");
|
17
14
|
const CohereError_js_1 = require("./CohereError.cjs");
|
18
15
|
const CohereTokenizer_js_1 = require("./CohereTokenizer.cjs");
|
@@ -220,7 +217,7 @@ async function createCohereTextGenerationFullDeltaIterableQueue(stream) {
|
|
220
217
|
const queue = new AsyncQueue_js_1.AsyncQueue();
|
221
218
|
let accumulatedText = "";
|
222
219
|
function processLine(line) {
|
223
|
-
const event =
|
220
|
+
const event = (0, parseJSON_js_1.parseJsonWithZod)(line, cohereTextStreamingResponseSchema);
|
224
221
|
if (event.is_finished === true) {
|
225
222
|
queue.push({
|
226
223
|
type: "delta",
|
@@ -247,25 +244,29 @@ async function createCohereTextGenerationFullDeltaIterableQueue(stream) {
|
|
247
244
|
}
|
248
245
|
// process the stream asynchonously (no 'await' on purpose):
|
249
246
|
(async () => {
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
247
|
+
try {
|
248
|
+
let unprocessedText = "";
|
249
|
+
const reader = new ReadableStreamDefaultReader(stream);
|
250
|
+
const utf8Decoder = new TextDecoder("utf-8");
|
251
|
+
// eslint-disable-next-line no-constant-condition
|
252
|
+
while (true) {
|
253
|
+
const { value: chunk, done } = await reader.read();
|
254
|
+
if (done) {
|
255
|
+
break;
|
256
|
+
}
|
257
|
+
unprocessedText += utf8Decoder.decode(chunk, { stream: true });
|
258
|
+
const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
|
259
|
+
unprocessedText = processableLines.pop() || "";
|
260
|
+
processableLines.forEach(processLine);
|
261
|
+
}
|
262
|
+
// processing remaining text:
|
263
|
+
if (unprocessedText) {
|
264
|
+
processLine(unprocessedText);
|
258
265
|
}
|
259
|
-
unprocessedText += utf8Decoder.decode(chunk, { stream: true });
|
260
|
-
const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
|
261
|
-
unprocessedText = processableLines.pop() || "";
|
262
|
-
processableLines.forEach(processLine);
|
263
266
|
}
|
264
|
-
|
265
|
-
|
266
|
-
processLine(unprocessedText);
|
267
|
+
finally {
|
268
|
+
queue.close();
|
267
269
|
}
|
268
|
-
queue.close();
|
269
270
|
})();
|
270
271
|
return queue;
|
271
272
|
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import SecureJSON from "secure-json-parse";
|
2
1
|
import { z } from "zod";
|
3
2
|
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
4
3
|
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
@@ -7,6 +6,7 @@ import { AbstractModel } from "../../model-function/AbstractModel.js";
|
|
7
6
|
import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
|
8
7
|
import { mapChatPromptToTextFormat, mapInstructionPromptToTextFormat, } from "../../model-function/generate-text/TextPromptFormat.js";
|
9
8
|
import { countTokens } from "../../model-function/tokenize-text/countTokens.js";
|
9
|
+
import { parseJsonWithZod } from "../../util/parseJSON.js";
|
10
10
|
import { CohereApiConfiguration } from "./CohereApiConfiguration.js";
|
11
11
|
import { failedCohereCallResponseHandler } from "./CohereError.js";
|
12
12
|
import { CohereTokenizer } from "./CohereTokenizer.js";
|
@@ -213,7 +213,7 @@ async function createCohereTextGenerationFullDeltaIterableQueue(stream) {
|
|
213
213
|
const queue = new AsyncQueue();
|
214
214
|
let accumulatedText = "";
|
215
215
|
function processLine(line) {
|
216
|
-
const event =
|
216
|
+
const event = parseJsonWithZod(line, cohereTextStreamingResponseSchema);
|
217
217
|
if (event.is_finished === true) {
|
218
218
|
queue.push({
|
219
219
|
type: "delta",
|
@@ -240,25 +240,29 @@ async function createCohereTextGenerationFullDeltaIterableQueue(stream) {
|
|
240
240
|
}
|
241
241
|
// process the stream asynchonously (no 'await' on purpose):
|
242
242
|
(async () => {
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
243
|
+
try {
|
244
|
+
let unprocessedText = "";
|
245
|
+
const reader = new ReadableStreamDefaultReader(stream);
|
246
|
+
const utf8Decoder = new TextDecoder("utf-8");
|
247
|
+
// eslint-disable-next-line no-constant-condition
|
248
|
+
while (true) {
|
249
|
+
const { value: chunk, done } = await reader.read();
|
250
|
+
if (done) {
|
251
|
+
break;
|
252
|
+
}
|
253
|
+
unprocessedText += utf8Decoder.decode(chunk, { stream: true });
|
254
|
+
const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
|
255
|
+
unprocessedText = processableLines.pop() || "";
|
256
|
+
processableLines.forEach(processLine);
|
257
|
+
}
|
258
|
+
// processing remaining text:
|
259
|
+
if (unprocessedText) {
|
260
|
+
processLine(unprocessedText);
|
251
261
|
}
|
252
|
-
unprocessedText += utf8Decoder.decode(chunk, { stream: true });
|
253
|
-
const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
|
254
|
-
unprocessedText = processableLines.pop() || "";
|
255
|
-
processableLines.forEach(processLine);
|
256
262
|
}
|
257
|
-
|
258
|
-
|
259
|
-
processLine(unprocessedText);
|
263
|
+
finally {
|
264
|
+
queue.close();
|
260
265
|
}
|
261
|
-
queue.close();
|
262
266
|
})();
|
263
267
|
return queue;
|
264
268
|
}
|
@@ -1,10 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.CohereTokenizer = void 0;
|
7
|
-
const zod_1 =
|
4
|
+
const zod_1 = require("zod");
|
8
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
9
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
7
|
const CohereError_js_1 = require("./CohereError.cjs");
|
@@ -73,11 +70,11 @@ class CohereTokenizer {
|
|
73
70
|
}
|
74
71
|
}
|
75
72
|
exports.CohereTokenizer = CohereTokenizer;
|
76
|
-
const cohereDetokenizationResponseSchema = zod_1.
|
77
|
-
text: zod_1.
|
78
|
-
meta: zod_1.
|
79
|
-
api_version: zod_1.
|
80
|
-
version: zod_1.
|
73
|
+
const cohereDetokenizationResponseSchema = zod_1.z.object({
|
74
|
+
text: zod_1.z.string(),
|
75
|
+
meta: zod_1.z.object({
|
76
|
+
api_version: zod_1.z.object({
|
77
|
+
version: zod_1.z.string(),
|
81
78
|
}),
|
82
79
|
}),
|
83
80
|
});
|
@@ -94,12 +91,12 @@ async function callCohereDetokenizeAPI({ api = new CohereApiConfiguration_js_1.C
|
|
94
91
|
abortSignal,
|
95
92
|
});
|
96
93
|
}
|
97
|
-
const cohereTokenizationResponseSchema = zod_1.
|
98
|
-
tokens: zod_1.
|
99
|
-
token_strings: zod_1.
|
100
|
-
meta: zod_1.
|
101
|
-
api_version: zod_1.
|
102
|
-
version: zod_1.
|
94
|
+
const cohereTokenizationResponseSchema = zod_1.z.object({
|
95
|
+
tokens: zod_1.z.array(zod_1.z.number()),
|
96
|
+
token_strings: zod_1.z.array(zod_1.z.string()),
|
97
|
+
meta: zod_1.z.object({
|
98
|
+
api_version: zod_1.z.object({
|
99
|
+
version: zod_1.z.string(),
|
103
100
|
}),
|
104
101
|
}),
|
105
102
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import z from "zod";
|
1
|
+
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 { failedCohereCallResponseHandler } from "./CohereError.js";
|
@@ -1,12 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.failedHuggingFaceCallResponseHandler = exports.HuggingFaceError = exports.huggingFaceErrorDataSchema = void 0;
|
7
|
-
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
4
|
const zod_1 = require("zod");
|
9
5
|
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const parseJSON_js_1 = require("../../util/parseJSON.cjs");
|
10
7
|
exports.huggingFaceErrorDataSchema = zod_1.z.object({
|
11
8
|
error: zod_1.z.array(zod_1.z.string()).or(zod_1.z.string()),
|
12
9
|
});
|
@@ -25,31 +22,10 @@ class HuggingFaceError extends ApiCallError_js_1.ApiCallError {
|
|
25
22
|
}
|
26
23
|
}
|
27
24
|
exports.HuggingFaceError = HuggingFaceError;
|
28
|
-
const failedHuggingFaceCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
url,
|
35
|
-
requestBodyValues,
|
36
|
-
statusCode: response.status,
|
37
|
-
data: parsedError,
|
38
|
-
});
|
39
|
-
}
|
40
|
-
catch (error) {
|
41
|
-
if (error instanceof Error) {
|
42
|
-
if (error.name === "AbortError" || error instanceof ApiCallError_js_1.ApiCallError) {
|
43
|
-
throw error;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
throw new ApiCallError_js_1.ApiCallError({
|
47
|
-
message: responseBody,
|
48
|
-
cause: error,
|
49
|
-
statusCode: response.status,
|
50
|
-
url,
|
51
|
-
requestBodyValues,
|
52
|
-
});
|
53
|
-
}
|
54
|
-
};
|
25
|
+
const failedHuggingFaceCallResponseHandler = async ({ response, url, requestBodyValues }) => new HuggingFaceError({
|
26
|
+
url,
|
27
|
+
requestBodyValues,
|
28
|
+
statusCode: response.status,
|
29
|
+
data: (0, parseJSON_js_1.parseJsonWithZod)(await response.text(), exports.huggingFaceErrorDataSchema),
|
30
|
+
});
|
55
31
|
exports.failedHuggingFaceCallResponseHandler = failedHuggingFaceCallResponseHandler;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import SecureJSON from "secure-json-parse";
|
2
1
|
import { z } from "zod";
|
3
2
|
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
3
|
+
import { parseJsonWithZod } from "../../util/parseJSON.js";
|
4
4
|
export const huggingFaceErrorDataSchema = z.object({
|
5
5
|
error: z.array(z.string()).or(z.string()),
|
6
6
|
});
|
@@ -18,30 +18,9 @@ export class HuggingFaceError extends ApiCallError {
|
|
18
18
|
this.data = data;
|
19
19
|
}
|
20
20
|
}
|
21
|
-
export const failedHuggingFaceCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
url,
|
28
|
-
requestBodyValues,
|
29
|
-
statusCode: response.status,
|
30
|
-
data: parsedError,
|
31
|
-
});
|
32
|
-
}
|
33
|
-
catch (error) {
|
34
|
-
if (error instanceof Error) {
|
35
|
-
if (error.name === "AbortError" || error instanceof ApiCallError) {
|
36
|
-
throw error;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
throw new ApiCallError({
|
40
|
-
message: responseBody,
|
41
|
-
cause: error,
|
42
|
-
statusCode: response.status,
|
43
|
-
url,
|
44
|
-
requestBodyValues,
|
45
|
-
});
|
46
|
-
}
|
47
|
-
};
|
21
|
+
export const failedHuggingFaceCallResponseHandler = async ({ response, url, requestBodyValues }) => new HuggingFaceError({
|
22
|
+
url,
|
23
|
+
requestBodyValues,
|
24
|
+
statusCode: response.status,
|
25
|
+
data: parseJsonWithZod(await response.text(), huggingFaceErrorDataSchema),
|
26
|
+
});
|
@@ -1,10 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.HuggingFaceImageDescriptionModel = void 0;
|
7
|
-
const zod_1 =
|
4
|
+
const zod_1 = require("zod");
|
8
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
9
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
7
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
@@ -60,8 +57,8 @@ class HuggingFaceImageDescriptionModel extends AbstractModel_js_1.AbstractModel
|
|
60
57
|
}
|
61
58
|
}
|
62
59
|
exports.HuggingFaceImageDescriptionModel = HuggingFaceImageDescriptionModel;
|
63
|
-
const huggingFaceImageDescriptionResponseSchema = zod_1.
|
64
|
-
generated_text: zod_1.
|
60
|
+
const huggingFaceImageDescriptionResponseSchema = zod_1.z.array(zod_1.z.object({
|
61
|
+
generated_text: zod_1.z.string(),
|
65
62
|
}));
|
66
63
|
async function callHuggingFaceImageDescriptionAPI({ api = new HuggingFaceApiConfiguration_js_1.HuggingFaceApiConfiguration(), abortSignal, model, data, }) {
|
67
64
|
return (0, postToApi_js_1.postToApi)({
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import z from "zod";
|
2
|
+
import { z } from "zod";
|
3
3
|
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
4
4
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
5
|
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import z from "zod";
|
1
|
+
import { z } from "zod";
|
2
2
|
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
3
3
|
import { createJsonResponseHandler, postToApi, } from "../../core/api/postToApi.js";
|
4
4
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
@@ -1,10 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.HuggingFaceTextEmbeddingModel = void 0;
|
7
|
-
const zod_1 =
|
4
|
+
const zod_1 = require("zod");
|
8
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
9
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
7
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
@@ -112,7 +109,7 @@ class HuggingFaceTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
112
109
|
}
|
113
110
|
}
|
114
111
|
exports.HuggingFaceTextEmbeddingModel = HuggingFaceTextEmbeddingModel;
|
115
|
-
const huggingFaceTextEmbeddingResponseSchema = zod_1.
|
112
|
+
const huggingFaceTextEmbeddingResponseSchema = zod_1.z.array(zod_1.z.array(zod_1.z.number()));
|
116
113
|
async function callHuggingFaceTextGenerationAPI({ api = new HuggingFaceApiConfiguration_js_1.HuggingFaceApiConfiguration(), abortSignal, model, inputs, options, }) {
|
117
114
|
return (0, postToApi_js_1.postJsonToApi)({
|
118
115
|
url: api.assembleUrl(`/${model}`),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import z from "zod";
|
1
|
+
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";
|
@@ -1,10 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.HuggingFaceTextGenerationModel = void 0;
|
7
|
-
const zod_1 =
|
4
|
+
const zod_1 = require("zod");
|
8
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
9
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
10
7
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
@@ -109,8 +106,8 @@ class HuggingFaceTextGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
109
106
|
}
|
110
107
|
}
|
111
108
|
exports.HuggingFaceTextGenerationModel = HuggingFaceTextGenerationModel;
|
112
|
-
const huggingFaceTextGenerationResponseSchema = zod_1.
|
113
|
-
generated_text: zod_1.
|
109
|
+
const huggingFaceTextGenerationResponseSchema = zod_1.z.array(zod_1.z.object({
|
110
|
+
generated_text: zod_1.z.string(),
|
114
111
|
}));
|
115
112
|
async function callHuggingFaceTextGenerationAPI({ api = new HuggingFaceApiConfiguration_js_1.HuggingFaceApiConfiguration(), abortSignal, model, inputs, topK, topP, temperature, repetitionPenalty, maxNewTokens, maxTime, numReturnSequences, doSample, options, }) {
|
116
113
|
return (0, postToApi_js_1.postJsonToApi)({
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import z from "zod";
|
1
|
+
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";
|
@@ -1,12 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
exports.failedLlamaCppCallResponseHandler = exports.LlamaCppError = exports.llamaCppErrorDataSchema = void 0;
|
7
|
-
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
4
|
const zod_1 = require("zod");
|
9
5
|
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const parseJSON_js_1 = require("../../util/parseJSON.cjs");
|
10
7
|
exports.llamaCppErrorDataSchema = zod_1.z.object({
|
11
8
|
error: zod_1.z.string(),
|
12
9
|
});
|
@@ -23,30 +20,10 @@ class LlamaCppError extends ApiCallError_js_1.ApiCallError {
|
|
23
20
|
}
|
24
21
|
}
|
25
22
|
exports.LlamaCppError = LlamaCppError;
|
26
|
-
const failedLlamaCppCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
requestBodyValues,
|
33
|
-
statusCode: response.status,
|
34
|
-
data: parsedError,
|
35
|
-
});
|
36
|
-
}
|
37
|
-
catch (error) {
|
38
|
-
if (error instanceof Error) {
|
39
|
-
if (error.name === "AbortError" || error instanceof ApiCallError_js_1.ApiCallError) {
|
40
|
-
throw error;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
throw new ApiCallError_js_1.ApiCallError({
|
44
|
-
message: responseBody,
|
45
|
-
cause: error,
|
46
|
-
statusCode: response.status,
|
47
|
-
url,
|
48
|
-
requestBodyValues,
|
49
|
-
});
|
50
|
-
}
|
51
|
-
};
|
23
|
+
const failedLlamaCppCallResponseHandler = async ({ response, url, requestBodyValues }) => new LlamaCppError({
|
24
|
+
url,
|
25
|
+
requestBodyValues,
|
26
|
+
statusCode: response.status,
|
27
|
+
data: (0, parseJSON_js_1.parseJsonWithZod)(await response.text(), exports.llamaCppErrorDataSchema),
|
28
|
+
});
|
52
29
|
exports.failedLlamaCppCallResponseHandler = failedLlamaCppCallResponseHandler;
|