modelfusion 0.91.0 → 0.92.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/README.md +4 -2
- package/core/FunctionOptions.d.ts +3 -11
- package/core/LogFormat.cjs +10 -0
- package/core/LogFormat.d.ts +9 -0
- package/core/LogFormat.js +9 -0
- package/core/ModelFusionConfiguration.cjs +21 -0
- package/core/ModelFusionConfiguration.d.ts +6 -0
- package/core/ModelFusionConfiguration.js +14 -0
- package/core/api/ApiCallError.cjs +9 -1
- package/core/api/ApiCallError.d.ts +4 -1
- package/core/api/ApiCallError.js +9 -1
- package/core/executeFunctionCall.cjs +4 -4
- package/core/executeFunctionCall.js +4 -4
- package/core/getFunctionCallLogger.cjs +21 -5
- package/core/getFunctionCallLogger.js +21 -5
- package/core/index.cjs +15 -2
- package/core/index.d.ts +2 -2
- package/core/index.js +2 -2
- package/model-function/executeStandardCall.cjs +4 -4
- package/model-function/executeStandardCall.js +4 -4
- package/model-function/executeStreamCall.cjs +4 -4
- package/model-function/executeStreamCall.js +4 -4
- package/model-provider/ollama/OllamaError.cjs +25 -24
- package/model-provider/ollama/OllamaError.d.ts +1 -11
- package/model-provider/ollama/OllamaError.js +24 -22
- package/model-provider/ollama/OllamaTextGenerationModel.cjs +38 -1
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +5 -1
- package/model-provider/ollama/OllamaTextGenerationModel.js +39 -2
- package/model-provider/ollama/OllamaTextGenerationModel.test.cjs +63 -0
- package/model-provider/ollama/OllamaTextGenerationModel.test.d.ts +1 -0
- package/model-provider/ollama/OllamaTextGenerationModel.test.js +61 -0
- package/model-provider/ollama/index.cjs +1 -3
- package/model-provider/ollama/index.d.ts +1 -1
- package/model-provider/ollama/index.js +0 -1
- package/model-provider/openai/OpenAIError.cjs +13 -29
- package/model-provider/openai/OpenAIError.d.ts +2 -11
- package/model-provider/openai/OpenAIError.js +11 -26
- package/model-provider/openai/index.cjs +1 -3
- package/model-provider/openai/index.d.ts +1 -1
- package/model-provider/openai/index.js +0 -1
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.cjs +5 -8
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.js +5 -8
- package/package.json +5 -4
- package/tool/execute-tool/executeTool.cjs +3 -4
- package/tool/execute-tool/executeTool.js +3 -4
- package/util/AsyncQueue.test.cjs +20 -21
- package/util/AsyncQueue.test.js +9 -10
- package/util/isDeepEqualData.test.cjs +14 -15
- package/util/isDeepEqualData.test.js +14 -15
- package/util/runSafe.test.cjs +12 -13
- package/util/runSafe.test.js +6 -7
- package/core/GlobalFunctionLogging.cjs +0 -12
- package/core/GlobalFunctionLogging.d.ts +0 -3
- package/core/GlobalFunctionLogging.js +0 -7
- package/core/GlobalFunctionObservers.cjs +0 -12
- package/core/GlobalFunctionObservers.d.ts +0 -3
- package/core/GlobalFunctionObservers.js +0 -7
package/README.md
CHANGED
@@ -40,7 +40,7 @@ Or use a template:
|
|
40
40
|
|
41
41
|
## Usage Examples
|
42
42
|
|
43
|
-
>
|
43
|
+
> [!TIP]
|
44
44
|
> The basic examples are a great way to get started and to explore in parallel with the [documentation](https://modelfusion.dev/). You can find them in the [examples/basic](https://github.com/lgrammel/modelfusion/tree/main/examples/basic) folder.
|
45
45
|
|
46
46
|
You can provide API keys for the different [integrations](https://modelfusion.dev/integration/model-provider/) using environment variables (e.g., `OPENAI_API_KEY`) or pass them into the model constructors as options.
|
@@ -636,7 +636,9 @@ ModelFusion provides an [observer framework](https://modelfusion.dev/guide/util/
|
|
636
636
|
#### Global Logging Example
|
637
637
|
|
638
638
|
```ts
|
639
|
-
|
639
|
+
import { modelfusion } from "modelfusion";
|
640
|
+
|
641
|
+
modelfusion.setLogFormat("detailed-object"); // log full events
|
640
642
|
```
|
641
643
|
|
642
644
|
### [Server](https://modelfusion.dev/guide/server/)
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import { Run } from "./Run.js";
|
2
1
|
import { FunctionObserver } from "./FunctionObserver.js";
|
2
|
+
import { LogFormat } from "./LogFormat.js";
|
3
|
+
import { Run } from "./Run.js";
|
3
4
|
/**
|
4
5
|
* Additional settings for ModelFusion functions.
|
5
6
|
*/
|
@@ -12,7 +13,7 @@ export type FunctionOptions = {
|
|
12
13
|
* Optional logging to use for the function. Logs are sent to the console.
|
13
14
|
* Overrides the global function logging setting.
|
14
15
|
*/
|
15
|
-
logging?:
|
16
|
+
logging?: LogFormat;
|
16
17
|
/**
|
17
18
|
* Optional observers that are called when the function is invoked.
|
18
19
|
*/
|
@@ -27,12 +28,3 @@ export type FunctionOptions = {
|
|
27
28
|
*/
|
28
29
|
parentCallId?: string | undefined;
|
29
30
|
};
|
30
|
-
/**
|
31
|
-
* The logging to use for the function. Logs are sent to the console.
|
32
|
-
*
|
33
|
-
* - `off` or undefined: No logging.
|
34
|
-
* - `basic-text`: Log the timestamp and the type of event as a single line of text.
|
35
|
-
* - `detailed-object`: Log everything except the original response as an object to the console.
|
36
|
-
* - `detailed-json`: Log everything except the original response as a JSON string to the console.
|
37
|
-
*/
|
38
|
-
export type FunctionLogging = undefined | "off" | "basic-text" | "detailed-object" | "detailed-json";
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* The logging output format to use, e.g. for functions. Logs are sent to the console.
|
4
|
+
*
|
5
|
+
* - `off` or undefined: No logging.
|
6
|
+
* - `basic-text`: Log the timestamp and the type of event as a single line of text.
|
7
|
+
* - `detailed-object`: Log everything except the original response as an object to the console.
|
8
|
+
* - `detailed-json`: Log everything except the original response as a JSON string to the console.
|
9
|
+
*/
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* The logging output format to use, e.g. for functions. Logs are sent to the console.
|
3
|
+
*
|
4
|
+
* - `off` or undefined: No logging.
|
5
|
+
* - `basic-text`: Log the timestamp and the type of event as a single line of text.
|
6
|
+
* - `detailed-object`: Log everything except the original response as an object to the console.
|
7
|
+
* - `detailed-json`: Log everything except the original response as a JSON string to the console.
|
8
|
+
*/
|
9
|
+
export type LogFormat = undefined | "off" | "basic-text" | "detailed-object" | "detailed-json";
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* The logging output format to use, e.g. for functions. Logs are sent to the console.
|
3
|
+
*
|
4
|
+
* - `off` or undefined: No logging.
|
5
|
+
* - `basic-text`: Log the timestamp and the type of event as a single line of text.
|
6
|
+
* - `detailed-object`: Log everything except the original response as an object to the console.
|
7
|
+
* - `detailed-json`: Log everything except the original response as a JSON string to the console.
|
8
|
+
*/
|
9
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getLogFormat = exports.setLogFormat = exports.getFunctionObservers = exports.setFunctionObservers = void 0;
|
4
|
+
let globalLogFormat = undefined;
|
5
|
+
let globalFunctionObservers = [];
|
6
|
+
function setFunctionObservers(functionObservers) {
|
7
|
+
globalFunctionObservers = functionObservers;
|
8
|
+
}
|
9
|
+
exports.setFunctionObservers = setFunctionObservers;
|
10
|
+
function getFunctionObservers() {
|
11
|
+
return globalFunctionObservers;
|
12
|
+
}
|
13
|
+
exports.getFunctionObservers = getFunctionObservers;
|
14
|
+
function setLogFormat(format) {
|
15
|
+
globalLogFormat = format;
|
16
|
+
}
|
17
|
+
exports.setLogFormat = setLogFormat;
|
18
|
+
function getLogFormat() {
|
19
|
+
return globalLogFormat;
|
20
|
+
}
|
21
|
+
exports.getLogFormat = getLogFormat;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { FunctionObserver } from "./FunctionObserver.js";
|
2
|
+
import { LogFormat } from "./LogFormat.js";
|
3
|
+
export declare function setFunctionObservers(functionObservers: FunctionObserver[]): void;
|
4
|
+
export declare function getFunctionObservers(): FunctionObserver[];
|
5
|
+
export declare function setLogFormat(format: LogFormat): void;
|
6
|
+
export declare function getLogFormat(): LogFormat;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
let globalLogFormat = undefined;
|
2
|
+
let globalFunctionObservers = [];
|
3
|
+
export function setFunctionObservers(functionObservers) {
|
4
|
+
globalFunctionObservers = functionObservers;
|
5
|
+
}
|
6
|
+
export function getFunctionObservers() {
|
7
|
+
return globalFunctionObservers;
|
8
|
+
}
|
9
|
+
export function setLogFormat(format) {
|
10
|
+
globalLogFormat = format;
|
11
|
+
}
|
12
|
+
export function getLogFormat() {
|
13
|
+
return globalLogFormat;
|
14
|
+
}
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiCallError = void 0;
|
4
4
|
class ApiCallError extends Error {
|
5
5
|
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable = statusCode != null &&
|
6
|
-
(statusCode === 429 || statusCode >= 500), }) {
|
6
|
+
(statusCode === 429 || statusCode >= 500), data, }) {
|
7
7
|
super(message);
|
8
8
|
Object.defineProperty(this, "url", {
|
9
9
|
enumerable: true,
|
@@ -41,6 +41,12 @@ class ApiCallError extends Error {
|
|
41
41
|
writable: true,
|
42
42
|
value: void 0
|
43
43
|
});
|
44
|
+
Object.defineProperty(this, "data", {
|
45
|
+
enumerable: true,
|
46
|
+
configurable: true,
|
47
|
+
writable: true,
|
48
|
+
value: void 0
|
49
|
+
});
|
44
50
|
this.name = "ApiCallError";
|
45
51
|
this.url = url;
|
46
52
|
this.requestBodyValues = requestBodyValues;
|
@@ -48,6 +54,7 @@ class ApiCallError extends Error {
|
|
48
54
|
this.responseBody = responseBody;
|
49
55
|
this.cause = cause;
|
50
56
|
this.isRetryable = isRetryable;
|
57
|
+
this.data = data;
|
51
58
|
}
|
52
59
|
toJSON() {
|
53
60
|
return {
|
@@ -59,6 +66,7 @@ class ApiCallError extends Error {
|
|
59
66
|
responseBody: this.responseBody,
|
60
67
|
cause: this.cause,
|
61
68
|
isRetryable: this.isRetryable,
|
69
|
+
data: this.data,
|
62
70
|
};
|
63
71
|
}
|
64
72
|
}
|
@@ -5,7 +5,8 @@ export declare class ApiCallError extends Error {
|
|
5
5
|
readonly responseBody?: string;
|
6
6
|
readonly cause?: unknown;
|
7
7
|
readonly isRetryable: boolean;
|
8
|
-
|
8
|
+
readonly data?: unknown;
|
9
|
+
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable, data, }: {
|
9
10
|
message: string;
|
10
11
|
url: string;
|
11
12
|
requestBodyValues: unknown;
|
@@ -13,6 +14,7 @@ export declare class ApiCallError extends Error {
|
|
13
14
|
responseBody?: string;
|
14
15
|
cause?: unknown;
|
15
16
|
isRetryable?: boolean;
|
17
|
+
data?: unknown;
|
16
18
|
});
|
17
19
|
toJSON(): {
|
18
20
|
name: string;
|
@@ -23,5 +25,6 @@ export declare class ApiCallError extends Error {
|
|
23
25
|
responseBody: string | undefined;
|
24
26
|
cause: unknown;
|
25
27
|
isRetryable: boolean;
|
28
|
+
data: unknown;
|
26
29
|
};
|
27
30
|
}
|
package/core/api/ApiCallError.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export class ApiCallError extends Error {
|
2
2
|
constructor({ message, url, requestBodyValues, statusCode, responseBody, cause, isRetryable = statusCode != null &&
|
3
|
-
(statusCode === 429 || statusCode >= 500), }) {
|
3
|
+
(statusCode === 429 || statusCode >= 500), data, }) {
|
4
4
|
super(message);
|
5
5
|
Object.defineProperty(this, "url", {
|
6
6
|
enumerable: true,
|
@@ -38,6 +38,12 @@ export class ApiCallError extends Error {
|
|
38
38
|
writable: true,
|
39
39
|
value: void 0
|
40
40
|
});
|
41
|
+
Object.defineProperty(this, "data", {
|
42
|
+
enumerable: true,
|
43
|
+
configurable: true,
|
44
|
+
writable: true,
|
45
|
+
value: void 0
|
46
|
+
});
|
41
47
|
this.name = "ApiCallError";
|
42
48
|
this.url = url;
|
43
49
|
this.requestBodyValues = requestBodyValues;
|
@@ -45,6 +51,7 @@ export class ApiCallError extends Error {
|
|
45
51
|
this.responseBody = responseBody;
|
46
52
|
this.cause = cause;
|
47
53
|
this.isRetryable = isRetryable;
|
54
|
+
this.data = data;
|
48
55
|
}
|
49
56
|
toJSON() {
|
50
57
|
return {
|
@@ -56,6 +63,7 @@ export class ApiCallError extends Error {
|
|
56
63
|
responseBody: this.responseBody,
|
57
64
|
cause: this.cause,
|
58
65
|
isRetryable: this.isRetryable,
|
66
|
+
data: this.data,
|
59
67
|
};
|
60
68
|
}
|
61
69
|
}
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeFunctionCall = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
5
|
const FunctionEventSource_js_1 = require("./FunctionEventSource.cjs");
|
6
|
-
const
|
7
|
-
const
|
6
|
+
const ModelFusionConfiguration_js_1 = require("./ModelFusionConfiguration.cjs");
|
7
|
+
const ModelFusionConfiguration_js_2 = require("./ModelFusionConfiguration.cjs");
|
8
8
|
const AbortError_js_1 = require("./api/AbortError.cjs");
|
9
9
|
const getFunctionCallLogger_js_1 = require("./getFunctionCallLogger.cjs");
|
10
10
|
const getRun_js_1 = require("./getRun.cjs");
|
@@ -14,8 +14,8 @@ async function executeFunctionCall({ options, input, functionType, execute, inpu
|
|
14
14
|
const run = await (0, getRun_js_1.getRun)(options?.run);
|
15
15
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
16
16
|
observers: [
|
17
|
-
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0,
|
18
|
-
...(0,
|
17
|
+
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
|
18
|
+
...(0, ModelFusionConfiguration_js_2.getFunctionObservers)(),
|
19
19
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
20
20
|
...(options?.observers ?? []),
|
21
21
|
],
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
2
|
import { FunctionEventSource } from "./FunctionEventSource.js";
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { getLogFormat } from "./ModelFusionConfiguration.js";
|
4
|
+
import { getFunctionObservers } from "./ModelFusionConfiguration.js";
|
5
5
|
import { AbortError } from "./api/AbortError.js";
|
6
6
|
import { getFunctionCallLogger } from "./getFunctionCallLogger.js";
|
7
7
|
import { getRun } from "./getRun.js";
|
@@ -11,8 +11,8 @@ export async function executeFunctionCall({ options, input, functionType, execut
|
|
11
11
|
const run = await getRun(options?.run);
|
12
12
|
const eventSource = new FunctionEventSource({
|
13
13
|
observers: [
|
14
|
-
...getFunctionCallLogger(options?.logging ??
|
15
|
-
...
|
14
|
+
...getFunctionCallLogger(options?.logging ?? getLogFormat()),
|
15
|
+
...getFunctionObservers(),
|
16
16
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
17
17
|
...(options?.observers ?? []),
|
18
18
|
],
|
@@ -45,11 +45,27 @@ const detailedObjectObserver = {
|
|
45
45
|
),
|
46
46
|
};
|
47
47
|
}
|
48
|
-
// filter all
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
// filter all hard-to-read properties from event for cleaner console output:
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
50
|
+
function cleanObject(obj) {
|
51
|
+
if (obj instanceof Date || typeof obj === "string") {
|
52
|
+
return obj;
|
53
|
+
}
|
54
|
+
if (obj !== null && typeof obj === "object") {
|
55
|
+
return Object.fromEntries(Object.entries(obj)
|
56
|
+
.filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
|
57
|
+
) => v !== undefined && // filter all undefined properties
|
58
|
+
!(v instanceof Buffer) // remove all buffers
|
59
|
+
)
|
60
|
+
.map(([k, v]) => [k, cleanObject(v)])
|
61
|
+
.filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
|
62
|
+
);
|
63
|
+
}
|
64
|
+
return obj;
|
65
|
+
}
|
66
|
+
// Clean the event object
|
67
|
+
const cleanedEvent = cleanObject(event);
|
68
|
+
console.log(cleanedEvent);
|
53
69
|
},
|
54
70
|
};
|
55
71
|
const detailedJsonObserver = {
|
@@ -41,11 +41,27 @@ const detailedObjectObserver = {
|
|
41
41
|
),
|
42
42
|
};
|
43
43
|
}
|
44
|
-
// filter all
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
// filter all hard-to-read properties from event for cleaner console output:
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
46
|
+
function cleanObject(obj) {
|
47
|
+
if (obj instanceof Date || typeof obj === "string") {
|
48
|
+
return obj;
|
49
|
+
}
|
50
|
+
if (obj !== null && typeof obj === "object") {
|
51
|
+
return Object.fromEntries(Object.entries(obj)
|
52
|
+
.filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
|
53
|
+
) => v !== undefined && // filter all undefined properties
|
54
|
+
!(v instanceof Buffer) // remove all buffers
|
55
|
+
)
|
56
|
+
.map(([k, v]) => [k, cleanObject(v)])
|
57
|
+
.filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
|
58
|
+
);
|
59
|
+
}
|
60
|
+
return obj;
|
61
|
+
}
|
62
|
+
// Clean the event object
|
63
|
+
const cleanedEvent = cleanObject(event);
|
64
|
+
console.log(cleanedEvent);
|
49
65
|
},
|
50
66
|
};
|
51
67
|
const detailedJsonObserver = {
|
package/core/index.cjs
CHANGED
@@ -10,18 +10,31 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
11
11
|
o[k2] = m[k];
|
12
12
|
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
20
|
};
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
22
|
+
if (mod && mod.__esModule) return mod;
|
23
|
+
var result = {};
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
25
|
+
__setModuleDefault(result, mod);
|
26
|
+
return result;
|
27
|
+
};
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.modelfusion = void 0;
|
17
30
|
__exportStar(require("./DefaultRun.cjs"), exports);
|
18
31
|
__exportStar(require("./ExecuteFunctionEvent.cjs"), exports);
|
19
32
|
__exportStar(require("./FunctionEvent.cjs"), exports);
|
20
33
|
__exportStar(require("./FunctionEventSource.cjs"), exports);
|
21
34
|
__exportStar(require("./FunctionObserver.cjs"), exports);
|
22
35
|
__exportStar(require("./FunctionOptions.cjs"), exports);
|
23
|
-
__exportStar(require("./
|
24
|
-
|
36
|
+
__exportStar(require("./LogFormat.cjs"), exports);
|
37
|
+
exports.modelfusion = __importStar(require("./ModelFusionConfiguration.cjs"));
|
25
38
|
__exportStar(require("./Run.cjs"), exports);
|
26
39
|
__exportStar(require("./Vector.cjs"), exports);
|
27
40
|
__exportStar(require("./api/index.cjs"), exports);
|
package/core/index.d.ts
CHANGED
@@ -4,8 +4,8 @@ export * from "./FunctionEvent.js";
|
|
4
4
|
export * from "./FunctionEventSource.js";
|
5
5
|
export * from "./FunctionObserver.js";
|
6
6
|
export * from "./FunctionOptions.js";
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
7
|
+
export * from "./LogFormat.js";
|
8
|
+
export * as modelfusion from "./ModelFusionConfiguration.js";
|
9
9
|
export * from "./Run.js";
|
10
10
|
export * from "./Vector.js";
|
11
11
|
export * from "./api/index.js";
|
package/core/index.js
CHANGED
@@ -4,8 +4,8 @@ export * from "./FunctionEvent.js";
|
|
4
4
|
export * from "./FunctionEventSource.js";
|
5
5
|
export * from "./FunctionObserver.js";
|
6
6
|
export * from "./FunctionOptions.js";
|
7
|
-
export * from "./
|
8
|
-
export * from "./
|
7
|
+
export * from "./LogFormat.js";
|
8
|
+
export * as modelfusion from "./ModelFusionConfiguration.js";
|
9
9
|
export * from "./Run.js";
|
10
10
|
export * from "./Vector.js";
|
11
11
|
export * from "./api/index.js";
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeStandardCall = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
5
|
const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
|
6
|
-
const
|
7
|
-
const
|
6
|
+
const ModelFusionConfiguration_js_1 = require("../core/ModelFusionConfiguration.cjs");
|
7
|
+
const ModelFusionConfiguration_js_2 = require("../core/ModelFusionConfiguration.cjs");
|
8
8
|
const AbortError_js_1 = require("../core/api/AbortError.cjs");
|
9
9
|
const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
|
10
10
|
const getRun_js_1 = require("../core/getRun.cjs");
|
@@ -15,8 +15,8 @@ async function executeStandardCall({ model, options, input, functionType, genera
|
|
15
15
|
const settings = model.settings;
|
16
16
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
17
17
|
observers: [
|
18
|
-
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0,
|
19
|
-
...(0,
|
18
|
+
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
|
19
|
+
...(0, ModelFusionConfiguration_js_2.getFunctionObservers)(),
|
20
20
|
...(settings.observers ?? []),
|
21
21
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
22
22
|
...(options?.observers ?? []),
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
2
|
import { FunctionEventSource } from "../core/FunctionEventSource.js";
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { getLogFormat } from "../core/ModelFusionConfiguration.js";
|
4
|
+
import { getFunctionObservers } from "../core/ModelFusionConfiguration.js";
|
5
5
|
import { AbortError } from "../core/api/AbortError.js";
|
6
6
|
import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
|
7
7
|
import { getRun } from "../core/getRun.js";
|
@@ -12,8 +12,8 @@ export async function executeStandardCall({ model, options, input, functionType,
|
|
12
12
|
const settings = model.settings;
|
13
13
|
const eventSource = new FunctionEventSource({
|
14
14
|
observers: [
|
15
|
-
...getFunctionCallLogger(options?.logging ??
|
16
|
-
...
|
15
|
+
...getFunctionCallLogger(options?.logging ?? getLogFormat()),
|
16
|
+
...getFunctionObservers(),
|
17
17
|
...(settings.observers ?? []),
|
18
18
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
19
19
|
...(options?.observers ?? []),
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeStreamCall = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
5
|
const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
|
6
|
-
const
|
7
|
-
const
|
6
|
+
const ModelFusionConfiguration_js_1 = require("../core/ModelFusionConfiguration.cjs");
|
7
|
+
const ModelFusionConfiguration_js_2 = require("../core/ModelFusionConfiguration.cjs");
|
8
8
|
const AbortError_js_1 = require("../core/api/AbortError.cjs");
|
9
9
|
const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
|
10
10
|
const getRun_js_1 = require("../core/getRun.cjs");
|
@@ -16,8 +16,8 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
16
16
|
const settings = model.settings;
|
17
17
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
18
18
|
observers: [
|
19
|
-
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0,
|
20
|
-
...(0,
|
19
|
+
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
|
20
|
+
...(0, ModelFusionConfiguration_js_2.getFunctionObservers)(),
|
21
21
|
...(settings.observers ?? []),
|
22
22
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
23
23
|
...(options?.observers ?? []),
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
2
|
import { FunctionEventSource } from "../core/FunctionEventSource.js";
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { getLogFormat } from "../core/ModelFusionConfiguration.js";
|
4
|
+
import { getFunctionObservers } from "../core/ModelFusionConfiguration.js";
|
5
5
|
import { AbortError } from "../core/api/AbortError.js";
|
6
6
|
import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
|
7
7
|
import { getRun } from "../core/getRun.js";
|
@@ -13,8 +13,8 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
13
13
|
const settings = model.settings;
|
14
14
|
const eventSource = new FunctionEventSource({
|
15
15
|
observers: [
|
16
|
-
...getFunctionCallLogger(options?.logging ??
|
17
|
-
...
|
16
|
+
...getFunctionCallLogger(options?.logging ?? getLogFormat()),
|
17
|
+
...getFunctionObservers(),
|
18
18
|
...(settings.observers ?? []),
|
19
19
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
20
20
|
...(options?.observers ?? []),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.failedOllamaCallResponseHandler =
|
3
|
+
exports.failedOllamaCallResponseHandler = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
6
|
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
@@ -8,30 +8,31 @@ const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
|
|
8
8
|
const ollamaErrorDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
|
9
9
|
error: zod_1.z.string(),
|
10
10
|
}));
|
11
|
-
class OllamaError extends ApiCallError_js_1.ApiCallError {
|
12
|
-
constructor({ statusCode, url, requestBodyValues, data, message = data.error, }) {
|
13
|
-
super({ message, statusCode, requestBodyValues, url });
|
14
|
-
Object.defineProperty(this, "data", {
|
15
|
-
enumerable: true,
|
16
|
-
configurable: true,
|
17
|
-
writable: true,
|
18
|
-
value: void 0
|
19
|
-
});
|
20
|
-
this.data = data;
|
21
|
-
}
|
22
|
-
}
|
23
|
-
exports.OllamaError = OllamaError;
|
24
11
|
const failedOllamaCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
25
12
|
const responseBody = await response.text();
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
13
|
+
// resilient parsing in case the response is not JSON or does not match the schema:
|
14
|
+
try {
|
15
|
+
const parsedError = (0, parseJSON_js_1.parseJSON)({
|
16
|
+
text: responseBody,
|
17
|
+
schema: ollamaErrorDataSchema,
|
18
|
+
});
|
19
|
+
return new ApiCallError_js_1.ApiCallError({
|
20
|
+
message: parsedError.error,
|
21
|
+
url,
|
22
|
+
requestBodyValues,
|
23
|
+
statusCode: response.status,
|
24
|
+
responseBody,
|
25
|
+
data: parsedError,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
catch (parseError) {
|
29
|
+
return new ApiCallError_js_1.ApiCallError({
|
30
|
+
message: responseBody.trim() !== "" ? responseBody : response.statusText,
|
31
|
+
url,
|
32
|
+
requestBodyValues,
|
33
|
+
statusCode: response.status,
|
34
|
+
responseBody,
|
35
|
+
});
|
36
|
+
}
|
36
37
|
};
|
37
38
|
exports.failedOllamaCallResponseHandler = failedOllamaCallResponseHandler;
|
@@ -4,16 +4,6 @@ import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
|
4
4
|
declare const ollamaErrorDataSchema: ZodSchema<{
|
5
5
|
error: string;
|
6
6
|
}>;
|
7
|
-
type OllamaErrorData = (typeof ollamaErrorDataSchema)["_type"];
|
8
|
-
export declare class OllamaError extends ApiCallError {
|
9
|
-
readonly data: OllamaErrorData;
|
10
|
-
constructor({ statusCode, url, requestBodyValues, data, message, }: {
|
11
|
-
message?: string;
|
12
|
-
statusCode: number;
|
13
|
-
url: string;
|
14
|
-
requestBodyValues: unknown;
|
15
|
-
data: OllamaErrorData;
|
16
|
-
});
|
17
|
-
}
|
7
|
+
export type OllamaErrorData = (typeof ollamaErrorDataSchema)["_type"];
|
18
8
|
export declare const failedOllamaCallResponseHandler: ResponseHandler<ApiCallError>;
|
19
9
|
export {};
|
@@ -5,28 +5,30 @@ import { parseJSON } from "../../core/schema/parseJSON.js";
|
|
5
5
|
const ollamaErrorDataSchema = new ZodSchema(z.object({
|
6
6
|
error: z.string(),
|
7
7
|
}));
|
8
|
-
export class OllamaError extends ApiCallError {
|
9
|
-
constructor({ statusCode, url, requestBodyValues, data, message = data.error, }) {
|
10
|
-
super({ message, statusCode, requestBodyValues, url });
|
11
|
-
Object.defineProperty(this, "data", {
|
12
|
-
enumerable: true,
|
13
|
-
configurable: true,
|
14
|
-
writable: true,
|
15
|
-
value: void 0
|
16
|
-
});
|
17
|
-
this.data = data;
|
18
|
-
}
|
19
|
-
}
|
20
8
|
export const failedOllamaCallResponseHandler = async ({ response, url, requestBodyValues }) => {
|
21
9
|
const responseBody = await response.text();
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
10
|
+
// resilient parsing in case the response is not JSON or does not match the schema:
|
11
|
+
try {
|
12
|
+
const parsedError = parseJSON({
|
13
|
+
text: responseBody,
|
14
|
+
schema: ollamaErrorDataSchema,
|
15
|
+
});
|
16
|
+
return new ApiCallError({
|
17
|
+
message: parsedError.error,
|
18
|
+
url,
|
19
|
+
requestBodyValues,
|
20
|
+
statusCode: response.status,
|
21
|
+
responseBody,
|
22
|
+
data: parsedError,
|
23
|
+
});
|
24
|
+
}
|
25
|
+
catch (parseError) {
|
26
|
+
return new ApiCallError({
|
27
|
+
message: responseBody.trim() !== "" ? responseBody : response.statusText,
|
28
|
+
url,
|
29
|
+
requestBodyValues,
|
30
|
+
statusCode: response.status,
|
31
|
+
responseBody,
|
32
|
+
});
|
33
|
+
}
|
32
34
|
};
|