modelfusion 0.90.0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- 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/api/RetryError.cjs +12 -2
- package/core/api/RetryError.d.ts +3 -1
- package/core/api/RetryError.js +12 -2
- package/core/api/postToApi.cjs +8 -1
- package/core/api/postToApi.d.ts +1 -0
- package/core/api/postToApi.js +8 -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/core/schema/JSONParseError.cjs +2 -7
- package/core/schema/JSONParseError.d.ts +1 -2
- package/core/schema/JSONParseError.js +2 -7
- 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/index.cjs +1 -0
- package/model-provider/index.d.ts +1 -0
- package/model-provider/index.js +1 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +1 -1
- package/model-provider/whispercpp/WhisperCppApiConfiguration.cjs +15 -0
- package/model-provider/whispercpp/WhisperCppApiConfiguration.d.ts +11 -0
- package/model-provider/whispercpp/WhisperCppApiConfiguration.js +11 -0
- package/model-provider/whispercpp/WhisperCppFacade.cjs +13 -0
- package/model-provider/whispercpp/WhisperCppFacade.d.ts +4 -0
- package/model-provider/whispercpp/WhisperCppFacade.js +8 -0
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.cjs +117 -0
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.d.ts +29 -0
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.js +113 -0
- package/model-provider/whispercpp/index.cjs +32 -0
- package/model-provider/whispercpp/index.d.ts +3 -0
- package/model-provider/whispercpp/index.js +3 -0
- package/package.json +1 -1
- package/tool/execute-tool/executeTool.cjs +3 -4
- package/tool/execute-tool/executeTool.js +3 -4
- 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
@@ -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 ?? []),
|
package/model-provider/index.cjs
CHANGED
@@ -25,3 +25,4 @@ __exportStar(require("./ollama/index.cjs"), exports);
|
|
25
25
|
__exportStar(require("./openai/index.cjs"), exports);
|
26
26
|
__exportStar(require("./openai-compatible/index.cjs"), exports);
|
27
27
|
__exportStar(require("./stability/index.cjs"), exports);
|
28
|
+
__exportStar(require("./whispercpp/index.cjs"), exports);
|
package/model-provider/index.js
CHANGED
@@ -50,7 +50,7 @@ const chatResponseStreamEventSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.union
|
|
50
50
|
chatCompletionChunkSchema,
|
51
51
|
zod_1.z.object({
|
52
52
|
object: zod_1.z.string().refine((obj) => obj !== "chat.completion.chunk", {
|
53
|
-
message: "Object must
|
53
|
+
message: "Object must be 'chat.completion.chunk'",
|
54
54
|
}),
|
55
55
|
}),
|
56
56
|
]));
|
@@ -47,7 +47,7 @@ const chatResponseStreamEventSchema = new ZodSchema(z.union([
|
|
47
47
|
chatCompletionChunkSchema,
|
48
48
|
z.object({
|
49
49
|
object: z.string().refine((obj) => obj !== "chat.completion.chunk", {
|
50
|
-
message: "Object must
|
50
|
+
message: "Object must be 'chat.completion.chunk'",
|
51
51
|
}),
|
52
52
|
}),
|
53
53
|
]));
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WhisperCppApiConfiguration = void 0;
|
4
|
+
const BaseUrlApiConfiguration_js_1 = require("../../core/api/BaseUrlApiConfiguration.cjs");
|
5
|
+
class WhisperCppApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlApiConfiguration {
|
6
|
+
constructor({ baseUrl = "http://127.0.0.1:8080", retry, throttle, } = {}) {
|
7
|
+
super({
|
8
|
+
baseUrl,
|
9
|
+
headers: {},
|
10
|
+
retry,
|
11
|
+
throttle,
|
12
|
+
});
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.WhisperCppApiConfiguration = WhisperCppApiConfiguration;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BaseUrlApiConfiguration } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
+
import { RetryFunction } from "../../core/api/RetryFunction.js";
|
3
|
+
import { ThrottleFunction } from "../../core/api/ThrottleFunction.js";
|
4
|
+
export type WhisperCppApiConfigurationSettings = {
|
5
|
+
baseUrl?: string;
|
6
|
+
retry?: RetryFunction;
|
7
|
+
throttle?: ThrottleFunction;
|
8
|
+
};
|
9
|
+
export declare class WhisperCppApiConfiguration extends BaseUrlApiConfiguration {
|
10
|
+
constructor({ baseUrl, retry, throttle, }?: WhisperCppApiConfigurationSettings);
|
11
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BaseUrlApiConfiguration } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
+
export class WhisperCppApiConfiguration extends BaseUrlApiConfiguration {
|
3
|
+
constructor({ baseUrl = "http://127.0.0.1:8080", retry, throttle, } = {}) {
|
4
|
+
super({
|
5
|
+
baseUrl,
|
6
|
+
headers: {},
|
7
|
+
retry,
|
8
|
+
throttle,
|
9
|
+
});
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Api = exports.Transcriber = void 0;
|
4
|
+
const WhisperCppApiConfiguration_js_1 = require("./WhisperCppApiConfiguration.cjs");
|
5
|
+
const WhisperCppTranscriptionModel_js_1 = require("./WhisperCppTranscriptionModel.cjs");
|
6
|
+
function Transcriber(settings = {}) {
|
7
|
+
return new WhisperCppTranscriptionModel_js_1.WhisperCppTranscriptionModel(settings);
|
8
|
+
}
|
9
|
+
exports.Transcriber = Transcriber;
|
10
|
+
function Api(settings) {
|
11
|
+
return new WhisperCppApiConfiguration_js_1.WhisperCppApiConfiguration(settings);
|
12
|
+
}
|
13
|
+
exports.Api = Api;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { WhisperCppApiConfiguration, WhisperCppApiConfigurationSettings } from "./WhisperCppApiConfiguration.js";
|
2
|
+
import { WhisperCppTranscriptionModel, WhisperCppTranscriptionModelSettings } from "./WhisperCppTranscriptionModel.js";
|
3
|
+
export declare function Transcriber(settings?: WhisperCppTranscriptionModelSettings): WhisperCppTranscriptionModel;
|
4
|
+
export declare function Api(settings: WhisperCppApiConfigurationSettings): WhisperCppApiConfiguration;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { WhisperCppApiConfiguration, } from "./WhisperCppApiConfiguration.js";
|
2
|
+
import { WhisperCppTranscriptionModel, } from "./WhisperCppTranscriptionModel.js";
|
3
|
+
export function Transcriber(settings = {}) {
|
4
|
+
return new WhisperCppTranscriptionModel(settings);
|
5
|
+
}
|
6
|
+
export function Api(settings) {
|
7
|
+
return new WhisperCppApiConfiguration(settings);
|
8
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WhisperCppTranscriptionModel = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
7
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
8
|
+
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
9
|
+
const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
|
10
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
11
|
+
const WhisperCppApiConfiguration_js_1 = require("./WhisperCppApiConfiguration.cjs");
|
12
|
+
class WhisperCppTranscriptionModel extends AbstractModel_js_1.AbstractModel {
|
13
|
+
constructor(settings) {
|
14
|
+
super({ settings });
|
15
|
+
Object.defineProperty(this, "provider", {
|
16
|
+
enumerable: true,
|
17
|
+
configurable: true,
|
18
|
+
writable: true,
|
19
|
+
value: "whispercpp"
|
20
|
+
});
|
21
|
+
Object.defineProperty(this, "modelName", {
|
22
|
+
enumerable: true,
|
23
|
+
configurable: true,
|
24
|
+
writable: true,
|
25
|
+
value: null
|
26
|
+
});
|
27
|
+
}
|
28
|
+
async doTranscribe(data, options) {
|
29
|
+
const response = await this.callAPI(data, {
|
30
|
+
functionId: options?.functionId,
|
31
|
+
run: options?.run,
|
32
|
+
});
|
33
|
+
return {
|
34
|
+
response,
|
35
|
+
transcription: response.text,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
async callAPI(data, options) {
|
39
|
+
const { temperature } = this.settings;
|
40
|
+
const api = this.settings.api ?? new WhisperCppApiConfiguration_js_1.WhisperCppApiConfiguration();
|
41
|
+
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
42
|
+
retry: api.retry,
|
43
|
+
throttle: api.throttle,
|
44
|
+
call: async () => {
|
45
|
+
const formData = new FormData();
|
46
|
+
formData.append("file", new Blob([data.data]), `audio.${data.type}`);
|
47
|
+
formData.append("response_format", "json");
|
48
|
+
if (temperature != null) {
|
49
|
+
formData.append("temperature", temperature.toString());
|
50
|
+
}
|
51
|
+
return (0, postToApi_js_1.postToApi)({
|
52
|
+
url: api.assembleUrl("/inference"),
|
53
|
+
headers: api.headers,
|
54
|
+
body: {
|
55
|
+
content: formData,
|
56
|
+
values: { temperature },
|
57
|
+
},
|
58
|
+
failedResponseHandler,
|
59
|
+
successfulResponseHandler,
|
60
|
+
abortSignal: options?.run?.abortSignal,
|
61
|
+
});
|
62
|
+
},
|
63
|
+
});
|
64
|
+
}
|
65
|
+
get settingsForEvent() {
|
66
|
+
return {
|
67
|
+
temperature: this.settings.temperature,
|
68
|
+
};
|
69
|
+
}
|
70
|
+
withSettings(additionalSettings) {
|
71
|
+
return new WhisperCppTranscriptionModel(Object.assign({}, this.settings, additionalSettings));
|
72
|
+
}
|
73
|
+
}
|
74
|
+
exports.WhisperCppTranscriptionModel = WhisperCppTranscriptionModel;
|
75
|
+
const whisperCppTranscriptionJsonSchema = zod_1.z.union([
|
76
|
+
zod_1.z.object({ text: zod_1.z.string() }),
|
77
|
+
zod_1.z.object({ error: zod_1.z.string() }),
|
78
|
+
]);
|
79
|
+
const successfulResponseHandler = async ({ response, url, requestBodyValues }) => {
|
80
|
+
const responseBody = await response.text();
|
81
|
+
const parsedResult = (0, parseJSON_js_1.safeParseJSON)({
|
82
|
+
text: responseBody,
|
83
|
+
schema: new ZodSchema_js_1.ZodSchema(whisperCppTranscriptionJsonSchema),
|
84
|
+
});
|
85
|
+
if (!parsedResult.success) {
|
86
|
+
throw new ApiCallError_js_1.ApiCallError({
|
87
|
+
message: "Invalid JSON response",
|
88
|
+
cause: parsedResult.error,
|
89
|
+
statusCode: response.status,
|
90
|
+
responseBody,
|
91
|
+
url,
|
92
|
+
requestBodyValues,
|
93
|
+
});
|
94
|
+
}
|
95
|
+
if ("error" in parsedResult.data) {
|
96
|
+
throw new ApiCallError_js_1.ApiCallError({
|
97
|
+
message: parsedResult.data.error,
|
98
|
+
statusCode: response.status,
|
99
|
+
responseBody,
|
100
|
+
url,
|
101
|
+
requestBodyValues,
|
102
|
+
});
|
103
|
+
}
|
104
|
+
return {
|
105
|
+
text: parsedResult.data.text.trim(),
|
106
|
+
};
|
107
|
+
};
|
108
|
+
const failedResponseHandler = async ({ response, url, requestBodyValues, }) => {
|
109
|
+
const message = await response.text();
|
110
|
+
return new ApiCallError_js_1.ApiCallError({
|
111
|
+
message,
|
112
|
+
url,
|
113
|
+
requestBodyValues,
|
114
|
+
statusCode: response.status,
|
115
|
+
responseBody: message,
|
116
|
+
});
|
117
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
3
|
+
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
4
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
|
+
import { TranscriptionModel, TranscriptionModelSettings } from "../../model-function/generate-transcription/TranscriptionModel.js";
|
6
|
+
export interface WhisperCppTranscriptionModelSettings extends TranscriptionModelSettings {
|
7
|
+
api?: ApiConfiguration;
|
8
|
+
temperature?: number;
|
9
|
+
}
|
10
|
+
export type WhisperCppTranscriptionInput = {
|
11
|
+
type: "wav";
|
12
|
+
data: Buffer;
|
13
|
+
};
|
14
|
+
export declare class WhisperCppTranscriptionModel extends AbstractModel<WhisperCppTranscriptionModelSettings> implements TranscriptionModel<WhisperCppTranscriptionInput, WhisperCppTranscriptionModelSettings> {
|
15
|
+
constructor(settings: WhisperCppTranscriptionModelSettings);
|
16
|
+
readonly provider: "whispercpp";
|
17
|
+
readonly modelName: null;
|
18
|
+
doTranscribe(data: WhisperCppTranscriptionInput, options?: FunctionOptions): Promise<{
|
19
|
+
response: {
|
20
|
+
text: string;
|
21
|
+
};
|
22
|
+
transcription: string;
|
23
|
+
}>;
|
24
|
+
callAPI(data: WhisperCppTranscriptionInput, options: FunctionOptions): Promise<{
|
25
|
+
text: string;
|
26
|
+
}>;
|
27
|
+
get settingsForEvent(): Partial<WhisperCppTranscriptionModelSettings>;
|
28
|
+
withSettings(additionalSettings: WhisperCppTranscriptionModelSettings): this;
|
29
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import { ApiCallError } from "../../core/api/ApiCallError.js";
|
3
|
+
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
4
|
+
import { postToApi } from "../../core/api/postToApi.js";
|
5
|
+
import { ZodSchema } from "../../core/schema/ZodSchema.js";
|
6
|
+
import { safeParseJSON } from "../../core/schema/parseJSON.js";
|
7
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
8
|
+
import { WhisperCppApiConfiguration } from "./WhisperCppApiConfiguration.js";
|
9
|
+
export class WhisperCppTranscriptionModel extends AbstractModel {
|
10
|
+
constructor(settings) {
|
11
|
+
super({ settings });
|
12
|
+
Object.defineProperty(this, "provider", {
|
13
|
+
enumerable: true,
|
14
|
+
configurable: true,
|
15
|
+
writable: true,
|
16
|
+
value: "whispercpp"
|
17
|
+
});
|
18
|
+
Object.defineProperty(this, "modelName", {
|
19
|
+
enumerable: true,
|
20
|
+
configurable: true,
|
21
|
+
writable: true,
|
22
|
+
value: null
|
23
|
+
});
|
24
|
+
}
|
25
|
+
async doTranscribe(data, options) {
|
26
|
+
const response = await this.callAPI(data, {
|
27
|
+
functionId: options?.functionId,
|
28
|
+
run: options?.run,
|
29
|
+
});
|
30
|
+
return {
|
31
|
+
response,
|
32
|
+
transcription: response.text,
|
33
|
+
};
|
34
|
+
}
|
35
|
+
async callAPI(data, options) {
|
36
|
+
const { temperature } = this.settings;
|
37
|
+
const api = this.settings.api ?? new WhisperCppApiConfiguration();
|
38
|
+
return callWithRetryAndThrottle({
|
39
|
+
retry: api.retry,
|
40
|
+
throttle: api.throttle,
|
41
|
+
call: async () => {
|
42
|
+
const formData = new FormData();
|
43
|
+
formData.append("file", new Blob([data.data]), `audio.${data.type}`);
|
44
|
+
formData.append("response_format", "json");
|
45
|
+
if (temperature != null) {
|
46
|
+
formData.append("temperature", temperature.toString());
|
47
|
+
}
|
48
|
+
return postToApi({
|
49
|
+
url: api.assembleUrl("/inference"),
|
50
|
+
headers: api.headers,
|
51
|
+
body: {
|
52
|
+
content: formData,
|
53
|
+
values: { temperature },
|
54
|
+
},
|
55
|
+
failedResponseHandler,
|
56
|
+
successfulResponseHandler,
|
57
|
+
abortSignal: options?.run?.abortSignal,
|
58
|
+
});
|
59
|
+
},
|
60
|
+
});
|
61
|
+
}
|
62
|
+
get settingsForEvent() {
|
63
|
+
return {
|
64
|
+
temperature: this.settings.temperature,
|
65
|
+
};
|
66
|
+
}
|
67
|
+
withSettings(additionalSettings) {
|
68
|
+
return new WhisperCppTranscriptionModel(Object.assign({}, this.settings, additionalSettings));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
const whisperCppTranscriptionJsonSchema = z.union([
|
72
|
+
z.object({ text: z.string() }),
|
73
|
+
z.object({ error: z.string() }),
|
74
|
+
]);
|
75
|
+
const successfulResponseHandler = async ({ response, url, requestBodyValues }) => {
|
76
|
+
const responseBody = await response.text();
|
77
|
+
const parsedResult = safeParseJSON({
|
78
|
+
text: responseBody,
|
79
|
+
schema: new ZodSchema(whisperCppTranscriptionJsonSchema),
|
80
|
+
});
|
81
|
+
if (!parsedResult.success) {
|
82
|
+
throw new ApiCallError({
|
83
|
+
message: "Invalid JSON response",
|
84
|
+
cause: parsedResult.error,
|
85
|
+
statusCode: response.status,
|
86
|
+
responseBody,
|
87
|
+
url,
|
88
|
+
requestBodyValues,
|
89
|
+
});
|
90
|
+
}
|
91
|
+
if ("error" in parsedResult.data) {
|
92
|
+
throw new ApiCallError({
|
93
|
+
message: parsedResult.data.error,
|
94
|
+
statusCode: response.status,
|
95
|
+
responseBody,
|
96
|
+
url,
|
97
|
+
requestBodyValues,
|
98
|
+
});
|
99
|
+
}
|
100
|
+
return {
|
101
|
+
text: parsedResult.data.text.trim(),
|
102
|
+
};
|
103
|
+
};
|
104
|
+
const failedResponseHandler = async ({ response, url, requestBodyValues, }) => {
|
105
|
+
const message = await response.text();
|
106
|
+
return new ApiCallError({
|
107
|
+
message,
|
108
|
+
url,
|
109
|
+
requestBodyValues,
|
110
|
+
statusCode: response.status,
|
111
|
+
responseBody: message,
|
112
|
+
});
|
113
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
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
|
+
});
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
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
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.whispercpp = void 0;
|
30
|
+
__exportStar(require("./WhisperCppApiConfiguration.cjs"), exports);
|
31
|
+
exports.whispercpp = __importStar(require("./WhisperCppFacade.cjs"));
|
32
|
+
__exportStar(require("./WhisperCppTranscriptionModel.cjs"), exports);
|
package/package.json
CHANGED
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeTool = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
5
|
const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
|
6
|
-
const
|
7
|
-
const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
|
6
|
+
const ModelFusionConfiguration_js_1 = require("../../core/ModelFusionConfiguration.cjs");
|
8
7
|
const AbortError_js_1 = require("../../core/api/AbortError.cjs");
|
9
8
|
const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
|
10
9
|
const getRun_js_1 = require("../../core/getRun.cjs");
|
@@ -22,8 +21,8 @@ async function doExecuteTool(tool, args, options) {
|
|
22
21
|
const run = await (0, getRun_js_1.getRun)(options?.run);
|
23
22
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
24
23
|
observers: [
|
25
|
-
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0,
|
26
|
-
...(0,
|
24
|
+
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, ModelFusionConfiguration_js_1.getLogFormat)()),
|
25
|
+
...(0, ModelFusionConfiguration_js_1.getFunctionObservers)(),
|
27
26
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
28
27
|
...(options?.observers ?? []),
|
29
28
|
],
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
2
|
import { FunctionEventSource } from "../../core/FunctionEventSource.js";
|
3
|
-
import {
|
4
|
-
import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
|
3
|
+
import { getFunctionObservers, getLogFormat, } from "../../core/ModelFusionConfiguration.js";
|
5
4
|
import { AbortError } from "../../core/api/AbortError.js";
|
6
5
|
import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
|
7
6
|
import { getRun } from "../../core/getRun.js";
|
@@ -18,8 +17,8 @@ async function doExecuteTool(tool, args, options) {
|
|
18
17
|
const run = await getRun(options?.run);
|
19
18
|
const eventSource = new FunctionEventSource({
|
20
19
|
observers: [
|
21
|
-
...getFunctionCallLogger(options?.logging ??
|
22
|
-
...
|
20
|
+
...getFunctionCallLogger(options?.logging ?? getLogFormat()),
|
21
|
+
...getFunctionObservers(),
|
23
22
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
24
23
|
...(options?.observers ?? []),
|
25
24
|
],
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getGlobalFunctionLogging = exports.setGlobalFunctionLogging = void 0;
|
4
|
-
let globalFunctionLogging = undefined;
|
5
|
-
function setGlobalFunctionLogging(logLevel) {
|
6
|
-
globalFunctionLogging = logLevel;
|
7
|
-
}
|
8
|
-
exports.setGlobalFunctionLogging = setGlobalFunctionLogging;
|
9
|
-
function getGlobalFunctionLogging() {
|
10
|
-
return globalFunctionLogging;
|
11
|
-
}
|
12
|
-
exports.getGlobalFunctionLogging = getGlobalFunctionLogging;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getGlobalFunctionObservers = exports.setGlobalFunctionObservers = void 0;
|
4
|
-
let globalFunctionObservers = [];
|
5
|
-
function setGlobalFunctionObservers(functionObservers) {
|
6
|
-
globalFunctionObservers = functionObservers;
|
7
|
-
}
|
8
|
-
exports.setGlobalFunctionObservers = setGlobalFunctionObservers;
|
9
|
-
function getGlobalFunctionObservers() {
|
10
|
-
return globalFunctionObservers;
|
11
|
-
}
|
12
|
-
exports.getGlobalFunctionObservers = getGlobalFunctionObservers;
|