modelfusion 0.56.0 → 0.57.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.
- package/core/api/ApiCallError.cjs +11 -0
- package/core/api/ApiCallError.d.ts +9 -0
- package/core/api/ApiCallError.js +11 -0
- package/core/api/LoadAPIKeyError.cjs +16 -0
- package/core/api/LoadAPIKeyError.d.ts +9 -0
- package/core/api/LoadAPIKeyError.js +12 -0
- package/core/api/RetryError.cjs +8 -0
- package/core/api/RetryError.d.ts +6 -0
- package/core/api/RetryError.js +8 -0
- package/core/api/loadApiKey.cjs +7 -2
- package/core/api/loadApiKey.js +7 -2
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +21 -4
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +18 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.js +21 -4
- package/package.json +1 -1
- package/server/fastify/FileSystemLogger.cjs +7 -6
- package/server/fastify/FileSystemLogger.d.ts +1 -1
- package/server/fastify/FileSystemLogger.js +7 -6
- package/server/fastify/modelFusionFlowPlugin.cjs +1 -0
- package/server/fastify/modelFusionFlowPlugin.js +1 -0
- package/util/JSONParseError.cjs +8 -0
- package/util/JSONParseError.d.ts +6 -0
- package/util/JSONParseError.js +8 -0
@@ -41,5 +41,16 @@ class ApiCallError extends Error {
|
|
41
41
|
this.cause = cause;
|
42
42
|
this.isRetryable = isRetryable;
|
43
43
|
}
|
44
|
+
toJSON() {
|
45
|
+
return {
|
46
|
+
name: this.name,
|
47
|
+
message: this.message,
|
48
|
+
url: this.url,
|
49
|
+
requestBodyValues: this.requestBodyValues,
|
50
|
+
statusCode: this.statusCode,
|
51
|
+
cause: this.cause,
|
52
|
+
isRetryable: this.isRetryable,
|
53
|
+
};
|
54
|
+
}
|
44
55
|
}
|
45
56
|
exports.ApiCallError = ApiCallError;
|
@@ -12,4 +12,13 @@ export declare class ApiCallError extends Error {
|
|
12
12
|
cause?: unknown;
|
13
13
|
isRetryable?: boolean;
|
14
14
|
});
|
15
|
+
toJSON(): {
|
16
|
+
name: string;
|
17
|
+
message: string;
|
18
|
+
url: string;
|
19
|
+
requestBodyValues: unknown;
|
20
|
+
statusCode: number;
|
21
|
+
cause: unknown;
|
22
|
+
isRetryable: boolean;
|
23
|
+
};
|
15
24
|
}
|
package/core/api/ApiCallError.js
CHANGED
@@ -38,4 +38,15 @@ export class ApiCallError extends Error {
|
|
38
38
|
this.cause = cause;
|
39
39
|
this.isRetryable = isRetryable;
|
40
40
|
}
|
41
|
+
toJSON() {
|
42
|
+
return {
|
43
|
+
name: this.name,
|
44
|
+
message: this.message,
|
45
|
+
url: this.url,
|
46
|
+
requestBodyValues: this.requestBodyValues,
|
47
|
+
statusCode: this.statusCode,
|
48
|
+
cause: this.cause,
|
49
|
+
isRetryable: this.isRetryable,
|
50
|
+
};
|
51
|
+
}
|
41
52
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LoadAPIKeyError = void 0;
|
4
|
+
class LoadAPIKeyError extends Error {
|
5
|
+
constructor({ message }) {
|
6
|
+
super(message);
|
7
|
+
this.name = "LoadAPIKeyError";
|
8
|
+
}
|
9
|
+
toJSON() {
|
10
|
+
return {
|
11
|
+
name: this.name,
|
12
|
+
message: this.message,
|
13
|
+
};
|
14
|
+
}
|
15
|
+
}
|
16
|
+
exports.LoadAPIKeyError = LoadAPIKeyError;
|
package/core/api/RetryError.cjs
CHANGED
@@ -20,5 +20,13 @@ class RetryError extends Error {
|
|
20
20
|
this.reason = reason;
|
21
21
|
this.errors = errors;
|
22
22
|
}
|
23
|
+
toJSON() {
|
24
|
+
return {
|
25
|
+
name: this.name,
|
26
|
+
message: this.message,
|
27
|
+
reason: this.reason,
|
28
|
+
errors: this.errors,
|
29
|
+
};
|
30
|
+
}
|
23
31
|
}
|
24
32
|
exports.RetryError = RetryError;
|
package/core/api/RetryError.d.ts
CHANGED
package/core/api/RetryError.js
CHANGED
package/core/api/loadApiKey.cjs
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.loadApiKey = void 0;
|
4
|
+
const LoadAPIKeyError_1 = require("./LoadAPIKeyError");
|
4
5
|
function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
|
5
6
|
if (apiKey != null) {
|
6
7
|
return apiKey;
|
7
8
|
}
|
8
9
|
if (typeof process === "undefined") {
|
9
|
-
throw new
|
10
|
+
throw new LoadAPIKeyError_1.LoadAPIKeyError({
|
11
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration. Environment variables is not supported in this environment.`,
|
12
|
+
});
|
10
13
|
}
|
11
14
|
apiKey = process.env[environmentVariableName];
|
12
15
|
if (apiKey == null) {
|
13
|
-
throw new
|
16
|
+
throw new LoadAPIKeyError_1.LoadAPIKeyError({
|
17
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration or set it as an environment variable named ${environmentVariableName}.`,
|
18
|
+
});
|
14
19
|
}
|
15
20
|
return apiKey;
|
16
21
|
}
|
package/core/api/loadApiKey.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
import { LoadAPIKeyError } from "./LoadAPIKeyError";
|
1
2
|
export function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description, }) {
|
2
3
|
if (apiKey != null) {
|
3
4
|
return apiKey;
|
4
5
|
}
|
5
6
|
if (typeof process === "undefined") {
|
6
|
-
throw new
|
7
|
+
throw new LoadAPIKeyError({
|
8
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration. Environment variables is not supported in this environment.`,
|
9
|
+
});
|
7
10
|
}
|
8
11
|
apiKey = process.env[environmentVariableName];
|
9
12
|
if (apiKey == null) {
|
10
|
-
throw new
|
13
|
+
throw new LoadAPIKeyError({
|
14
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter into the API configuration or set it as an environment variable named ${environmentVariableName}.`,
|
15
|
+
});
|
11
16
|
}
|
12
17
|
return apiKey;
|
13
18
|
}
|
@@ -10,17 +10,33 @@ const CohereError_js_1 = require("./CohereError.cjs");
|
|
10
10
|
const CohereTokenizer_js_1 = require("./CohereTokenizer.cjs");
|
11
11
|
exports.COHERE_TEXT_EMBEDDING_MODELS = {
|
12
12
|
"embed-english-light-v2.0": {
|
13
|
-
contextWindowSize:
|
13
|
+
contextWindowSize: 512,
|
14
14
|
embeddingDimensions: 1024,
|
15
15
|
},
|
16
16
|
"embed-english-v2.0": {
|
17
|
-
contextWindowSize:
|
17
|
+
contextWindowSize: 512,
|
18
18
|
embeddingDimensions: 4096,
|
19
19
|
},
|
20
20
|
"embed-multilingual-v2.0": {
|
21
|
-
contextWindowSize:
|
21
|
+
contextWindowSize: 512,
|
22
22
|
embeddingDimensions: 768,
|
23
23
|
},
|
24
|
+
"embed-english-v3.0": {
|
25
|
+
contextWindowSize: 512,
|
26
|
+
embeddingDimensions: 1024,
|
27
|
+
},
|
28
|
+
"embed-english-light-v3.0": {
|
29
|
+
contextWindowSize: 512,
|
30
|
+
embeddingDimensions: 384,
|
31
|
+
},
|
32
|
+
"embed-multilingual-v3.0": {
|
33
|
+
contextWindowSize: 512,
|
34
|
+
embeddingDimensions: 1024,
|
35
|
+
},
|
36
|
+
"embed-multilingual-light-v3.0": {
|
37
|
+
contextWindowSize: 512,
|
38
|
+
embeddingDimensions: 384,
|
39
|
+
},
|
24
40
|
};
|
25
41
|
/**
|
26
42
|
* Create a text embedding model that calls the Cohere Co.Embed API.
|
@@ -137,13 +153,14 @@ const cohereTextEmbeddingResponseSchema = zod_1.z.object({
|
|
137
153
|
}),
|
138
154
|
}),
|
139
155
|
});
|
140
|
-
async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration_js_1.CohereApiConfiguration(), abortSignal, model, texts, truncate, }) {
|
156
|
+
async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration_js_1.CohereApiConfiguration(), abortSignal, model, texts, inputType, truncate, }) {
|
141
157
|
return (0, postToApi_js_1.postJsonToApi)({
|
142
158
|
url: api.assembleUrl(`/embed`),
|
143
159
|
headers: api.headers,
|
144
160
|
body: {
|
145
161
|
model,
|
146
162
|
texts,
|
163
|
+
input_type: inputType,
|
147
164
|
truncate,
|
148
165
|
},
|
149
166
|
failedResponseHandler: CohereError_js_1.failedCohereCallResponseHandler,
|
@@ -17,11 +17,28 @@ export declare const COHERE_TEXT_EMBEDDING_MODELS: {
|
|
17
17
|
contextWindowSize: number;
|
18
18
|
embeddingDimensions: number;
|
19
19
|
};
|
20
|
+
"embed-english-v3.0": {
|
21
|
+
contextWindowSize: number;
|
22
|
+
embeddingDimensions: number;
|
23
|
+
};
|
24
|
+
"embed-english-light-v3.0": {
|
25
|
+
contextWindowSize: number;
|
26
|
+
embeddingDimensions: number;
|
27
|
+
};
|
28
|
+
"embed-multilingual-v3.0": {
|
29
|
+
contextWindowSize: number;
|
30
|
+
embeddingDimensions: number;
|
31
|
+
};
|
32
|
+
"embed-multilingual-light-v3.0": {
|
33
|
+
contextWindowSize: number;
|
34
|
+
embeddingDimensions: number;
|
35
|
+
};
|
20
36
|
};
|
21
37
|
export type CohereTextEmbeddingModelType = keyof typeof COHERE_TEXT_EMBEDDING_MODELS;
|
22
38
|
export interface CohereTextEmbeddingModelSettings extends EmbeddingModelSettings {
|
23
39
|
api?: ApiConfiguration;
|
24
40
|
model: CohereTextEmbeddingModelType;
|
41
|
+
inputType?: "search_document" | "search_query" | "classification" | "clustering";
|
25
42
|
truncate?: "NONE" | "START" | "END";
|
26
43
|
}
|
27
44
|
/**
|
@@ -41,7 +58,7 @@ export interface CohereTextEmbeddingModelSettings extends EmbeddingModelSettings
|
|
41
58
|
export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEmbeddingModelSettings> implements EmbeddingModel<string, CohereTextEmbeddingModelSettings>, FullTokenizer {
|
42
59
|
constructor(settings: CohereTextEmbeddingModelSettings);
|
43
60
|
readonly provider: "cohere";
|
44
|
-
get modelName(): "embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0";
|
61
|
+
get modelName(): "embed-english-light-v2.0" | "embed-english-v2.0" | "embed-multilingual-v2.0" | "embed-english-v3.0" | "embed-english-light-v3.0" | "embed-multilingual-v3.0" | "embed-multilingual-light-v3.0";
|
45
62
|
readonly maxValuesPerCall = 96;
|
46
63
|
readonly isParallizable = true;
|
47
64
|
readonly embeddingDimensions: number;
|
@@ -7,17 +7,33 @@ import { failedCohereCallResponseHandler } from "./CohereError.js";
|
|
7
7
|
import { CohereTokenizer } from "./CohereTokenizer.js";
|
8
8
|
export const COHERE_TEXT_EMBEDDING_MODELS = {
|
9
9
|
"embed-english-light-v2.0": {
|
10
|
-
contextWindowSize:
|
10
|
+
contextWindowSize: 512,
|
11
11
|
embeddingDimensions: 1024,
|
12
12
|
},
|
13
13
|
"embed-english-v2.0": {
|
14
|
-
contextWindowSize:
|
14
|
+
contextWindowSize: 512,
|
15
15
|
embeddingDimensions: 4096,
|
16
16
|
},
|
17
17
|
"embed-multilingual-v2.0": {
|
18
|
-
contextWindowSize:
|
18
|
+
contextWindowSize: 512,
|
19
19
|
embeddingDimensions: 768,
|
20
20
|
},
|
21
|
+
"embed-english-v3.0": {
|
22
|
+
contextWindowSize: 512,
|
23
|
+
embeddingDimensions: 1024,
|
24
|
+
},
|
25
|
+
"embed-english-light-v3.0": {
|
26
|
+
contextWindowSize: 512,
|
27
|
+
embeddingDimensions: 384,
|
28
|
+
},
|
29
|
+
"embed-multilingual-v3.0": {
|
30
|
+
contextWindowSize: 512,
|
31
|
+
embeddingDimensions: 1024,
|
32
|
+
},
|
33
|
+
"embed-multilingual-light-v3.0": {
|
34
|
+
contextWindowSize: 512,
|
35
|
+
embeddingDimensions: 384,
|
36
|
+
},
|
21
37
|
};
|
22
38
|
/**
|
23
39
|
* Create a text embedding model that calls the Cohere Co.Embed API.
|
@@ -133,13 +149,14 @@ const cohereTextEmbeddingResponseSchema = z.object({
|
|
133
149
|
}),
|
134
150
|
}),
|
135
151
|
});
|
136
|
-
async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration(), abortSignal, model, texts, truncate, }) {
|
152
|
+
async function callCohereEmbeddingAPI({ api = new CohereApiConfiguration(), abortSignal, model, texts, inputType, truncate, }) {
|
137
153
|
return postJsonToApi({
|
138
154
|
url: api.assembleUrl(`/embed`),
|
139
155
|
headers: api.headers,
|
140
156
|
body: {
|
141
157
|
model,
|
142
158
|
texts,
|
159
|
+
input_type: inputType,
|
143
160
|
truncate,
|
144
161
|
},
|
145
162
|
failedResponseHandler: failedCohereCallResponseHandler,
|
package/package.json
CHANGED
@@ -28,15 +28,16 @@ class FileSystemLogger {
|
|
28
28
|
});
|
29
29
|
}
|
30
30
|
}
|
31
|
-
async logError(
|
31
|
+
async logError({ run, error, message, }) {
|
32
32
|
const timestamp = Date.now();
|
33
33
|
try {
|
34
|
-
const logPath = this.logPath(
|
35
|
-
|
34
|
+
const logPath = this.logPath(run);
|
35
|
+
await node_fs_1.promises.mkdir(logPath, { recursive: true });
|
36
|
+
await node_fs_1.promises.writeFile((0, node_path_1.join)(logPath, `${timestamp}-error.json`), JSON.stringify({
|
36
37
|
timestamp: new Date(timestamp).toISOString(),
|
37
|
-
runId:
|
38
|
-
message
|
39
|
-
error
|
38
|
+
runId: run.runId,
|
39
|
+
message,
|
40
|
+
error,
|
40
41
|
}));
|
41
42
|
}
|
42
43
|
catch (error) {
|
@@ -25,15 +25,16 @@ export class FileSystemLogger {
|
|
25
25
|
});
|
26
26
|
}
|
27
27
|
}
|
28
|
-
async logError(
|
28
|
+
async logError({ run, error, message, }) {
|
29
29
|
const timestamp = Date.now();
|
30
30
|
try {
|
31
|
-
const logPath = this.logPath(
|
32
|
-
|
31
|
+
const logPath = this.logPath(run);
|
32
|
+
await fs.mkdir(logPath, { recursive: true });
|
33
|
+
await fs.writeFile(join(logPath, `${timestamp}-error.json`), JSON.stringify({
|
33
34
|
timestamp: new Date(timestamp).toISOString(),
|
34
|
-
runId:
|
35
|
-
message
|
36
|
-
error
|
35
|
+
runId: run.runId,
|
36
|
+
message,
|
37
|
+
error,
|
37
38
|
}));
|
38
39
|
}
|
39
40
|
catch (error) {
|
package/util/JSONParseError.cjs
CHANGED
@@ -29,5 +29,13 @@ class JSONParseError extends Error {
|
|
29
29
|
this.cause = cause;
|
30
30
|
this.valueText = valueText;
|
31
31
|
}
|
32
|
+
toJSON() {
|
33
|
+
return {
|
34
|
+
name: this.name,
|
35
|
+
message: this.message,
|
36
|
+
cause: this.cause,
|
37
|
+
valueText: this.valueText,
|
38
|
+
};
|
39
|
+
}
|
32
40
|
}
|
33
41
|
exports.JSONParseError = JSONParseError;
|
package/util/JSONParseError.d.ts
CHANGED
package/util/JSONParseError.js
CHANGED