modelfusion 0.105.0 → 0.107.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/CHANGELOG.md +26 -0
- package/README.md +16 -59
- package/core/DefaultRun.cjs +0 -4
- package/core/DefaultRun.d.ts +0 -2
- package/core/DefaultRun.js +0 -4
- package/core/ExtensionFunctionEvent.d.ts +11 -0
- package/core/FunctionEvent.d.ts +2 -2
- package/extension/index.cjs +22 -3
- package/extension/index.d.ts +5 -1
- package/extension/index.js +4 -1
- package/index.cjs +0 -3
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/model-function/generate-structure/jsonStructurePrompt.cjs +42 -6
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +12 -1
- package/model-function/generate-structure/jsonStructurePrompt.js +42 -5
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +2 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +1 -1
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.test.cjs +11 -0
- package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.test.js +11 -0
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +10 -8
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +10 -8
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.test.cjs +11 -0
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.test.js +11 -0
- package/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.cjs +150 -0
- package/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.d.ts +62 -0
- package/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.js +143 -0
- package/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.test.cjs +60 -0
- package/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.test.js +58 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.test.cjs +11 -0
- package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.test.js +11 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.test.cjs +11 -0
- package/model-function/generate-text/prompt-template/TextPromptTemplate.test.js +11 -0
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.test.cjs +11 -0
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.test.js +11 -0
- package/model-function/generate-text/prompt-template/index.cjs +2 -1
- package/model-function/generate-text/prompt-template/index.d.ts +1 -0
- package/model-function/generate-text/prompt-template/index.js +1 -0
- package/model-function/index.cjs +0 -1
- package/model-function/index.d.ts +0 -1
- package/model-function/index.js +0 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +6 -6
- package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.d.ts +3 -3
- package/model-provider/llamacpp/{LlamaCppTextGenerationModel.cjs → LlamaCppCompletionModel.cjs} +8 -8
- package/model-provider/llamacpp/{LlamaCppTextGenerationModel.d.ts → LlamaCppCompletionModel.d.ts} +49 -49
- package/model-provider/llamacpp/{LlamaCppTextGenerationModel.js → LlamaCppCompletionModel.js} +6 -6
- package/model-provider/llamacpp/{LlamaCppTextGenerationModel.test.cjs → LlamaCppCompletionModel.test.cjs} +3 -3
- package/model-provider/llamacpp/{LlamaCppTextGenerationModel.test.js → LlamaCppCompletionModel.test.js} +3 -3
- package/model-provider/llamacpp/LlamaCppFacade.cjs +2 -2
- package/model-provider/llamacpp/LlamaCppFacade.d.ts +2 -2
- package/model-provider/llamacpp/LlamaCppFacade.js +2 -2
- package/model-provider/llamacpp/index.cjs +1 -1
- package/model-provider/llamacpp/index.d.ts +1 -1
- package/model-provider/llamacpp/index.js +1 -1
- package/model-provider/mistral/MistralChatModel.cjs +4 -4
- package/model-provider/mistral/MistralChatModel.d.ts +6 -6
- package/model-provider/mistral/MistralChatModel.js +1 -1
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/mistral/index.cjs +3 -3
- package/model-provider/mistral/index.d.ts +2 -2
- package/model-provider/mistral/index.js +2 -2
- package/model-provider/ollama/OllamaChatModel.d.ts +9 -8
- package/model-provider/ollama/OllamaChatModel.js +1 -1
- package/model-provider/ollama/OllamaCompletionModel.d.ts +2 -1
- package/model-provider/ollama/OllamaCompletionModel.js +1 -1
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +1 -7
- package/model-provider/ollama/OllamaCompletionModel.test.js +1 -7
- package/model-provider/openai/AbstractOpenAIChatModel.d.ts +8 -8
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAICompletionModel.d.ts +6 -6
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +11 -11
- package/model-provider/openai/index.cjs +0 -1
- package/model-provider/openai/index.d.ts +0 -1
- package/model-provider/openai/index.js +0 -1
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
- package/package.json +9 -20
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
- package/tool/generate-tool-call/index.cjs +1 -0
- package/tool/generate-tool-call/index.d.ts +1 -0
- package/tool/generate-tool-call/index.js +1 -0
- package/tool/generate-tool-call/jsonToolCallPrompt.cjs +30 -0
- package/tool/generate-tool-call/jsonToolCallPrompt.d.ts +5 -0
- package/tool/generate-tool-call/jsonToolCallPrompt.js +27 -0
- package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +1 -11
- package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.d.ts +12 -0
- package/tool/generate-tool-calls-or-text/index.cjs +1 -0
- package/tool/generate-tool-calls-or-text/index.d.ts +1 -0
- package/tool/generate-tool-calls-or-text/index.js +1 -0
- package/util/index.cjs +0 -1
- package/util/index.d.ts +0 -1
- package/util/index.js +0 -1
- package/browser/MediaSourceAppender.cjs +0 -54
- package/browser/MediaSourceAppender.d.ts +0 -11
- package/browser/MediaSourceAppender.js +0 -50
- package/browser/convertAudioChunksToBase64.cjs +0 -8
- package/browser/convertAudioChunksToBase64.d.ts +0 -4
- package/browser/convertAudioChunksToBase64.js +0 -4
- package/browser/convertBlobToBase64.cjs +0 -23
- package/browser/convertBlobToBase64.d.ts +0 -1
- package/browser/convertBlobToBase64.js +0 -19
- package/browser/index.cjs +0 -22
- package/browser/index.d.ts +0 -6
- package/browser/index.js +0 -6
- package/browser/invokeFlow.cjs +0 -23
- package/browser/invokeFlow.d.ts +0 -8
- package/browser/invokeFlow.js +0 -19
- package/browser/readEventSource.cjs +0 -29
- package/browser/readEventSource.d.ts +0 -9
- package/browser/readEventSource.js +0 -25
- package/browser/readEventSourceStream.cjs +0 -35
- package/browser/readEventSourceStream.d.ts +0 -7
- package/browser/readEventSourceStream.js +0 -31
- package/composed-function/index.cjs +0 -19
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/composed-function/summarize/SummarizationFunction.d.ts +0 -4
- package/composed-function/summarize/summarizeRecursively.cjs +0 -19
- package/composed-function/summarize/summarizeRecursively.d.ts +0 -11
- package/composed-function/summarize/summarizeRecursively.js +0 -15
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +0 -25
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +0 -24
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +0 -21
- package/cost/Cost.cjs +0 -38
- package/cost/Cost.d.ts +0 -16
- package/cost/Cost.js +0 -34
- package/cost/CostCalculator.d.ts +0 -8
- package/cost/calculateCost.cjs +0 -28
- package/cost/calculateCost.d.ts +0 -7
- package/cost/calculateCost.js +0 -24
- package/cost/index.cjs +0 -19
- package/cost/index.d.ts +0 -3
- package/cost/index.js +0 -3
- package/guard/GuardEvent.cjs +0 -2
- package/guard/GuardEvent.d.ts +0 -7
- package/guard/fixStructure.cjs +0 -75
- package/guard/fixStructure.d.ts +0 -64
- package/guard/fixStructure.js +0 -71
- package/guard/guard.cjs +0 -79
- package/guard/guard.d.ts +0 -29
- package/guard/guard.js +0 -75
- package/guard/index.cjs +0 -19
- package/guard/index.d.ts +0 -3
- package/guard/index.js +0 -3
- package/model-function/SuccessfulModelCall.cjs +0 -10
- package/model-function/SuccessfulModelCall.d.ts +0 -12
- package/model-function/SuccessfulModelCall.js +0 -6
- package/model-provider/openai/OpenAICostCalculator.cjs +0 -89
- package/model-provider/openai/OpenAICostCalculator.d.ts +0 -6
- package/model-provider/openai/OpenAICostCalculator.js +0 -85
- package/server/fastify/AssetStorage.cjs +0 -2
- package/server/fastify/AssetStorage.d.ts +0 -17
- package/server/fastify/AssetStorage.js +0 -1
- package/server/fastify/DefaultFlow.cjs +0 -22
- package/server/fastify/DefaultFlow.d.ts +0 -16
- package/server/fastify/DefaultFlow.js +0 -18
- package/server/fastify/FileSystemAssetStorage.cjs +0 -60
- package/server/fastify/FileSystemAssetStorage.d.ts +0 -19
- package/server/fastify/FileSystemAssetStorage.js +0 -56
- package/server/fastify/FileSystemLogger.cjs +0 -49
- package/server/fastify/FileSystemLogger.d.ts +0 -18
- package/server/fastify/FileSystemLogger.js +0 -45
- package/server/fastify/Flow.cjs +0 -2
- package/server/fastify/Flow.d.ts +0 -9
- package/server/fastify/Flow.js +0 -1
- package/server/fastify/FlowRun.cjs +0 -71
- package/server/fastify/FlowRun.d.ts +0 -28
- package/server/fastify/FlowRun.js +0 -67
- package/server/fastify/FlowSchema.cjs +0 -2
- package/server/fastify/FlowSchema.d.ts +0 -5
- package/server/fastify/FlowSchema.js +0 -1
- package/server/fastify/Logger.cjs +0 -2
- package/server/fastify/Logger.d.ts +0 -13
- package/server/fastify/Logger.js +0 -1
- package/server/fastify/PathProvider.cjs +0 -34
- package/server/fastify/PathProvider.d.ts +0 -12
- package/server/fastify/PathProvider.js +0 -30
- package/server/fastify/index.cjs +0 -24
- package/server/fastify/index.d.ts +0 -8
- package/server/fastify/index.js +0 -8
- package/server/fastify/modelFusionFlowPlugin.cjs +0 -103
- package/server/fastify/modelFusionFlowPlugin.d.ts +0 -12
- package/server/fastify/modelFusionFlowPlugin.js +0 -99
- package/util/getAudioFileExtension.cjs +0 -29
- package/util/getAudioFileExtension.d.ts +0 -1
- package/util/getAudioFileExtension.js +0 -25
- /package/{composed-function/summarize/SummarizationFunction.cjs → core/ExtensionFunctionEvent.cjs} +0 -0
- /package/{composed-function/summarize/SummarizationFunction.js → core/ExtensionFunctionEvent.js} +0 -0
- /package/{cost/CostCalculator.js → model-function/generate-text/prompt-template/MistralInstructPromptTemplate.test.d.ts} +0 -0
- /package/{guard/GuardEvent.js → model-provider/llamacpp/LlamaCppCompletionModel.test.d.ts} +0 -0
- /package/model-provider/mistral/{MistralPromptTemplate.cjs → MistralChatPromptTemplate.cjs} +0 -0
- /package/model-provider/mistral/{MistralPromptTemplate.d.ts → MistralChatPromptTemplate.d.ts} +0 -0
- /package/model-provider/mistral/{MistralPromptTemplate.js → MistralChatPromptTemplate.js} +0 -0
- /package/{cost/CostCalculator.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
- /package/{model-provider/llamacpp/LlamaCppTextGenerationModel.test.d.ts → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js} +0 -0
package/guard/guard.cjs
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.guard = void 0;
|
4
|
-
const executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
|
5
|
-
async function guard(execute, input, guards, options) {
|
6
|
-
const guardList = Array.isArray(guards) ? guards : [guards];
|
7
|
-
const maxAttempts = options?.maxAttempts ?? 2;
|
8
|
-
return (0, executeFunctionCall_js_1.executeFunctionCall)({
|
9
|
-
options,
|
10
|
-
input,
|
11
|
-
functionType: "guard",
|
12
|
-
execute: async (options) => {
|
13
|
-
let attempts = 0;
|
14
|
-
while (attempts < maxAttempts) {
|
15
|
-
let result;
|
16
|
-
try {
|
17
|
-
result = {
|
18
|
-
type: "value",
|
19
|
-
input,
|
20
|
-
output: await execute(input, options),
|
21
|
-
};
|
22
|
-
}
|
23
|
-
catch (error) {
|
24
|
-
result = {
|
25
|
-
type: "error",
|
26
|
-
input,
|
27
|
-
error,
|
28
|
-
};
|
29
|
-
}
|
30
|
-
let isValid = true;
|
31
|
-
for (const guard of guardList) {
|
32
|
-
const guardResult = await guard(result);
|
33
|
-
if (guardResult === undefined) {
|
34
|
-
continue;
|
35
|
-
}
|
36
|
-
switch (guardResult.action) {
|
37
|
-
case "passThrough": {
|
38
|
-
break;
|
39
|
-
}
|
40
|
-
case "retry": {
|
41
|
-
input = guardResult.input;
|
42
|
-
isValid = false;
|
43
|
-
break;
|
44
|
-
}
|
45
|
-
case "return": {
|
46
|
-
result = {
|
47
|
-
type: "value",
|
48
|
-
input,
|
49
|
-
output: guardResult.output,
|
50
|
-
};
|
51
|
-
break;
|
52
|
-
}
|
53
|
-
case "throwError": {
|
54
|
-
result = {
|
55
|
-
type: "error",
|
56
|
-
input,
|
57
|
-
error: guardResult.error,
|
58
|
-
};
|
59
|
-
break;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
if (isValid) {
|
64
|
-
if (result.type === "value") {
|
65
|
-
return result.output;
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
throw result.error;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
attempts++;
|
72
|
-
}
|
73
|
-
// TODO dedicated error type
|
74
|
-
throw new Error(`Maximum attempts of ${maxAttempts} reached ` +
|
75
|
-
`without producing a valid output or handling an error.`);
|
76
|
-
},
|
77
|
-
});
|
78
|
-
}
|
79
|
-
exports.guard = guard;
|
package/guard/guard.d.ts
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
import { FunctionOptions } from "../core/FunctionOptions.js";
|
2
|
-
type OutputResult<INPUT, OUTPUT> = {
|
3
|
-
type: "value";
|
4
|
-
input: INPUT;
|
5
|
-
output: OUTPUT;
|
6
|
-
error?: undefined;
|
7
|
-
} | {
|
8
|
-
type: "error";
|
9
|
-
input: INPUT;
|
10
|
-
output?: undefined;
|
11
|
-
error: unknown;
|
12
|
-
};
|
13
|
-
export type OutputValidator<INPUT, OUTPUT> = ({ type, input, output, error, }: OutputResult<INPUT, OUTPUT>) => PromiseLike<boolean>;
|
14
|
-
export type Guard<INPUT, OUTPUT> = ({ type, input, output, error, }: OutputResult<INPUT, OUTPUT>) => PromiseLike<{
|
15
|
-
action: "retry";
|
16
|
-
input: INPUT;
|
17
|
-
} | {
|
18
|
-
action: "return";
|
19
|
-
output: OUTPUT;
|
20
|
-
} | {
|
21
|
-
action: "throwError";
|
22
|
-
error: unknown;
|
23
|
-
} | {
|
24
|
-
action: "passThrough";
|
25
|
-
} | undefined>;
|
26
|
-
export declare function guard<INPUT, OUTPUT>(execute: (input: INPUT, options?: FunctionOptions) => PromiseLike<OUTPUT>, input: INPUT, guards: Guard<INPUT, OUTPUT> | Array<Guard<INPUT, OUTPUT>>, options?: FunctionOptions & {
|
27
|
-
maxAttempts: number;
|
28
|
-
}): Promise<OUTPUT | undefined>;
|
29
|
-
export {};
|
package/guard/guard.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
import { executeFunctionCall } from "../core/executeFunctionCall.js";
|
2
|
-
export async function guard(execute, input, guards, options) {
|
3
|
-
const guardList = Array.isArray(guards) ? guards : [guards];
|
4
|
-
const maxAttempts = options?.maxAttempts ?? 2;
|
5
|
-
return executeFunctionCall({
|
6
|
-
options,
|
7
|
-
input,
|
8
|
-
functionType: "guard",
|
9
|
-
execute: async (options) => {
|
10
|
-
let attempts = 0;
|
11
|
-
while (attempts < maxAttempts) {
|
12
|
-
let result;
|
13
|
-
try {
|
14
|
-
result = {
|
15
|
-
type: "value",
|
16
|
-
input,
|
17
|
-
output: await execute(input, options),
|
18
|
-
};
|
19
|
-
}
|
20
|
-
catch (error) {
|
21
|
-
result = {
|
22
|
-
type: "error",
|
23
|
-
input,
|
24
|
-
error,
|
25
|
-
};
|
26
|
-
}
|
27
|
-
let isValid = true;
|
28
|
-
for (const guard of guardList) {
|
29
|
-
const guardResult = await guard(result);
|
30
|
-
if (guardResult === undefined) {
|
31
|
-
continue;
|
32
|
-
}
|
33
|
-
switch (guardResult.action) {
|
34
|
-
case "passThrough": {
|
35
|
-
break;
|
36
|
-
}
|
37
|
-
case "retry": {
|
38
|
-
input = guardResult.input;
|
39
|
-
isValid = false;
|
40
|
-
break;
|
41
|
-
}
|
42
|
-
case "return": {
|
43
|
-
result = {
|
44
|
-
type: "value",
|
45
|
-
input,
|
46
|
-
output: guardResult.output,
|
47
|
-
};
|
48
|
-
break;
|
49
|
-
}
|
50
|
-
case "throwError": {
|
51
|
-
result = {
|
52
|
-
type: "error",
|
53
|
-
input,
|
54
|
-
error: guardResult.error,
|
55
|
-
};
|
56
|
-
break;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
if (isValid) {
|
61
|
-
if (result.type === "value") {
|
62
|
-
return result.output;
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
throw result.error;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
attempts++;
|
69
|
-
}
|
70
|
-
// TODO dedicated error type
|
71
|
-
throw new Error(`Maximum attempts of ${maxAttempts} reached ` +
|
72
|
-
`without producing a valid output or handling an error.`);
|
73
|
-
},
|
74
|
-
});
|
75
|
-
}
|
package/guard/index.cjs
DELETED
@@ -1,19 +0,0 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./GuardEvent.cjs"), exports);
|
18
|
-
__exportStar(require("./fixStructure.cjs"), exports);
|
19
|
-
__exportStar(require("./guard.cjs"), exports);
|
package/guard/index.d.ts
DELETED
package/guard/index.js
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractSuccessfulModelCalls = void 0;
|
4
|
-
function extractSuccessfulModelCalls(runFunctionEvents) {
|
5
|
-
return runFunctionEvents.filter((event) => "model" in event &&
|
6
|
-
"result" in event &&
|
7
|
-
"status" in event.result &&
|
8
|
-
event.result.status === "success");
|
9
|
-
}
|
10
|
-
exports.extractSuccessfulModelCalls = extractSuccessfulModelCalls;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { FunctionEvent } from "../core/FunctionEvent.js";
|
2
|
-
import { ModelCallFinishedEvent } from "./ModelCallEvent.js";
|
3
|
-
export type SuccessfulModelCall = ModelCallFinishedEvent & {
|
4
|
-
result: {
|
5
|
-
status: "success";
|
6
|
-
};
|
7
|
-
};
|
8
|
-
export declare function extractSuccessfulModelCalls(runFunctionEvents: FunctionEvent[]): (ModelCallFinishedEvent & {
|
9
|
-
result: {
|
10
|
-
status: "success";
|
11
|
-
};
|
12
|
-
})[];
|
@@ -1,89 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.OpenAICostCalculator = void 0;
|
4
|
-
const OpenAICompletionModel_js_1 = require("./OpenAICompletionModel.cjs");
|
5
|
-
const OpenAIImageGenerationModel_js_1 = require("./OpenAIImageGenerationModel.cjs");
|
6
|
-
const OpenAISpeechModel_js_1 = require("./OpenAISpeechModel.cjs");
|
7
|
-
const OpenAITextEmbeddingModel_js_1 = require("./OpenAITextEmbeddingModel.cjs");
|
8
|
-
const OpenAITranscriptionModel_js_1 = require("./OpenAITranscriptionModel.cjs");
|
9
|
-
const OpenAIChatModel_js_1 = require("./OpenAIChatModel.cjs");
|
10
|
-
class OpenAICostCalculator {
|
11
|
-
constructor() {
|
12
|
-
Object.defineProperty(this, "provider", {
|
13
|
-
enumerable: true,
|
14
|
-
configurable: true,
|
15
|
-
writable: true,
|
16
|
-
value: "openai"
|
17
|
-
});
|
18
|
-
}
|
19
|
-
async calculateCostInMillicents(call) {
|
20
|
-
const type = call.functionType;
|
21
|
-
const model = call.model.modelName;
|
22
|
-
switch (type) {
|
23
|
-
case "generate-image": {
|
24
|
-
if (model == null) {
|
25
|
-
return null;
|
26
|
-
}
|
27
|
-
return (0, OpenAIImageGenerationModel_js_1.calculateOpenAIImageGenerationCostInMillicents)({
|
28
|
-
model: model,
|
29
|
-
settings: call.settings,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
case "embed": {
|
33
|
-
if (model == null) {
|
34
|
-
return null;
|
35
|
-
}
|
36
|
-
if ((0, OpenAITextEmbeddingModel_js_1.isOpenAIEmbeddingModel)(model)) {
|
37
|
-
const responses = Array.isArray(call.result.response)
|
38
|
-
? call.result.response
|
39
|
-
: [call.result.response];
|
40
|
-
return (0, OpenAITextEmbeddingModel_js_1.calculateOpenAIEmbeddingCostInMillicents)({
|
41
|
-
model,
|
42
|
-
responses,
|
43
|
-
});
|
44
|
-
}
|
45
|
-
break;
|
46
|
-
}
|
47
|
-
case "generate-structure":
|
48
|
-
case "generate-text": {
|
49
|
-
if (model == null) {
|
50
|
-
return null;
|
51
|
-
}
|
52
|
-
if ((0, OpenAIChatModel_js_1.isOpenAIChatModel)(model)) {
|
53
|
-
return (0, OpenAIChatModel_js_1.calculateOpenAIChatCostInMillicents)({
|
54
|
-
model,
|
55
|
-
response: call.result.response,
|
56
|
-
});
|
57
|
-
}
|
58
|
-
if ((0, OpenAICompletionModel_js_1.isOpenAICompletionModel)(model)) {
|
59
|
-
return (0, OpenAICompletionModel_js_1.calculateOpenAICompletionCostInMillicents)({
|
60
|
-
model,
|
61
|
-
response: call.result.response,
|
62
|
-
});
|
63
|
-
}
|
64
|
-
break;
|
65
|
-
}
|
66
|
-
case "generate-transcription": {
|
67
|
-
if (model == null) {
|
68
|
-
return null;
|
69
|
-
}
|
70
|
-
return (0, OpenAITranscriptionModel_js_1.calculateOpenAITranscriptionCostInMillicents)({
|
71
|
-
model: model,
|
72
|
-
response: call.result
|
73
|
-
.response,
|
74
|
-
});
|
75
|
-
}
|
76
|
-
case "generate-speech": {
|
77
|
-
if (model == null) {
|
78
|
-
return null;
|
79
|
-
}
|
80
|
-
return (0, OpenAISpeechModel_js_1.calculateOpenAISpeechCostInMillicents)({
|
81
|
-
model: model,
|
82
|
-
input: call.input,
|
83
|
-
});
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return null;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
exports.OpenAICostCalculator = OpenAICostCalculator;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { CostCalculator } from "../../cost/CostCalculator.js";
|
2
|
-
import { SuccessfulModelCall } from "../../model-function/SuccessfulModelCall.js";
|
3
|
-
export declare class OpenAICostCalculator implements CostCalculator {
|
4
|
-
readonly provider = "openai";
|
5
|
-
calculateCostInMillicents(call: SuccessfulModelCall): Promise<number | null>;
|
6
|
-
}
|
@@ -1,85 +0,0 @@
|
|
1
|
-
import { calculateOpenAICompletionCostInMillicents, isOpenAICompletionModel, } from "./OpenAICompletionModel.js";
|
2
|
-
import { calculateOpenAIImageGenerationCostInMillicents, } from "./OpenAIImageGenerationModel.js";
|
3
|
-
import { calculateOpenAISpeechCostInMillicents, } from "./OpenAISpeechModel.js";
|
4
|
-
import { calculateOpenAIEmbeddingCostInMillicents, isOpenAIEmbeddingModel, } from "./OpenAITextEmbeddingModel.js";
|
5
|
-
import { calculateOpenAITranscriptionCostInMillicents, } from "./OpenAITranscriptionModel.js";
|
6
|
-
import { calculateOpenAIChatCostInMillicents, isOpenAIChatModel, } from "./OpenAIChatModel.js";
|
7
|
-
export class OpenAICostCalculator {
|
8
|
-
constructor() {
|
9
|
-
Object.defineProperty(this, "provider", {
|
10
|
-
enumerable: true,
|
11
|
-
configurable: true,
|
12
|
-
writable: true,
|
13
|
-
value: "openai"
|
14
|
-
});
|
15
|
-
}
|
16
|
-
async calculateCostInMillicents(call) {
|
17
|
-
const type = call.functionType;
|
18
|
-
const model = call.model.modelName;
|
19
|
-
switch (type) {
|
20
|
-
case "generate-image": {
|
21
|
-
if (model == null) {
|
22
|
-
return null;
|
23
|
-
}
|
24
|
-
return calculateOpenAIImageGenerationCostInMillicents({
|
25
|
-
model: model,
|
26
|
-
settings: call.settings,
|
27
|
-
});
|
28
|
-
}
|
29
|
-
case "embed": {
|
30
|
-
if (model == null) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
if (isOpenAIEmbeddingModel(model)) {
|
34
|
-
const responses = Array.isArray(call.result.response)
|
35
|
-
? call.result.response
|
36
|
-
: [call.result.response];
|
37
|
-
return calculateOpenAIEmbeddingCostInMillicents({
|
38
|
-
model,
|
39
|
-
responses,
|
40
|
-
});
|
41
|
-
}
|
42
|
-
break;
|
43
|
-
}
|
44
|
-
case "generate-structure":
|
45
|
-
case "generate-text": {
|
46
|
-
if (model == null) {
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
if (isOpenAIChatModel(model)) {
|
50
|
-
return calculateOpenAIChatCostInMillicents({
|
51
|
-
model,
|
52
|
-
response: call.result.response,
|
53
|
-
});
|
54
|
-
}
|
55
|
-
if (isOpenAICompletionModel(model)) {
|
56
|
-
return calculateOpenAICompletionCostInMillicents({
|
57
|
-
model,
|
58
|
-
response: call.result.response,
|
59
|
-
});
|
60
|
-
}
|
61
|
-
break;
|
62
|
-
}
|
63
|
-
case "generate-transcription": {
|
64
|
-
if (model == null) {
|
65
|
-
return null;
|
66
|
-
}
|
67
|
-
return calculateOpenAITranscriptionCostInMillicents({
|
68
|
-
model: model,
|
69
|
-
response: call.result
|
70
|
-
.response,
|
71
|
-
});
|
72
|
-
}
|
73
|
-
case "generate-speech": {
|
74
|
-
if (model == null) {
|
75
|
-
return null;
|
76
|
-
}
|
77
|
-
return calculateOpenAISpeechCostInMillicents({
|
78
|
-
model: model,
|
79
|
-
input: call.input,
|
80
|
-
});
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return null;
|
84
|
-
}
|
85
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
import { FlowRun } from "./FlowRun.js";
|
3
|
-
export type Asset = {
|
4
|
-
data: Buffer;
|
5
|
-
contentType: string;
|
6
|
-
name: string;
|
7
|
-
};
|
8
|
-
export interface AssetStorage {
|
9
|
-
storeAsset(options: {
|
10
|
-
run: FlowRun<unknown>;
|
11
|
-
asset: Asset;
|
12
|
-
}): Promise<void>;
|
13
|
-
readAsset(options: {
|
14
|
-
run: FlowRun<unknown>;
|
15
|
-
assetName: string;
|
16
|
-
}): Promise<Asset | null>;
|
17
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DefaultFlow = void 0;
|
4
|
-
class DefaultFlow {
|
5
|
-
constructor({ schema, process, }) {
|
6
|
-
Object.defineProperty(this, "schema", {
|
7
|
-
enumerable: true,
|
8
|
-
configurable: true,
|
9
|
-
writable: true,
|
10
|
-
value: void 0
|
11
|
-
});
|
12
|
-
Object.defineProperty(this, "process", {
|
13
|
-
enumerable: true,
|
14
|
-
configurable: true,
|
15
|
-
writable: true,
|
16
|
-
value: void 0
|
17
|
-
});
|
18
|
-
this.schema = schema;
|
19
|
-
this.process = process;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
exports.DefaultFlow = DefaultFlow;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { FlowRun } from "./FlowRun.js";
|
2
|
-
import { FlowSchema } from "./FlowSchema.js";
|
3
|
-
export declare class DefaultFlow<INPUT, EVENT> {
|
4
|
-
readonly schema: FlowSchema<INPUT, EVENT>;
|
5
|
-
constructor({ schema, process, }: {
|
6
|
-
schema: FlowSchema<INPUT, EVENT>;
|
7
|
-
process: (options: {
|
8
|
-
input: INPUT;
|
9
|
-
run: FlowRun<EVENT>;
|
10
|
-
}) => Promise<void>;
|
11
|
-
});
|
12
|
-
process: (options: {
|
13
|
-
input: INPUT;
|
14
|
-
run: FlowRun<EVENT>;
|
15
|
-
}) => Promise<void>;
|
16
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export class DefaultFlow {
|
2
|
-
constructor({ schema, process, }) {
|
3
|
-
Object.defineProperty(this, "schema", {
|
4
|
-
enumerable: true,
|
5
|
-
configurable: true,
|
6
|
-
writable: true,
|
7
|
-
value: void 0
|
8
|
-
});
|
9
|
-
Object.defineProperty(this, "process", {
|
10
|
-
enumerable: true,
|
11
|
-
configurable: true,
|
12
|
-
writable: true,
|
13
|
-
value: void 0
|
14
|
-
});
|
15
|
-
this.schema = schema;
|
16
|
-
this.process = process;
|
17
|
-
}
|
18
|
-
}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FileSystemAssetStorage = void 0;
|
4
|
-
const node_fs_1 = require("node:fs");
|
5
|
-
const node_path_1 = require("node:path");
|
6
|
-
class FileSystemAssetStorage {
|
7
|
-
constructor({ path, logger, }) {
|
8
|
-
Object.defineProperty(this, "path", {
|
9
|
-
enumerable: true,
|
10
|
-
configurable: true,
|
11
|
-
writable: true,
|
12
|
-
value: void 0
|
13
|
-
});
|
14
|
-
Object.defineProperty(this, "logger", {
|
15
|
-
enumerable: true,
|
16
|
-
configurable: true,
|
17
|
-
writable: true,
|
18
|
-
value: void 0
|
19
|
-
});
|
20
|
-
this.path = path;
|
21
|
-
this.logger = logger;
|
22
|
-
}
|
23
|
-
async storeAsset({ run, asset, }) {
|
24
|
-
try {
|
25
|
-
const assetPath = this.path(run);
|
26
|
-
await node_fs_1.promises.mkdir(assetPath, { recursive: true });
|
27
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(assetPath, asset.name), asset.data);
|
28
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(assetPath, `${asset.name}.meta.json`), JSON.stringify({
|
29
|
-
name: asset.name,
|
30
|
-
contentType: asset.contentType,
|
31
|
-
}));
|
32
|
-
}
|
33
|
-
catch (error) {
|
34
|
-
this.logger.logError({
|
35
|
-
run,
|
36
|
-
message: `Failed to store asset ${asset.name}`,
|
37
|
-
error,
|
38
|
-
});
|
39
|
-
throw error;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
async readAsset(options) {
|
43
|
-
try {
|
44
|
-
const assetPath = this.path(options.run);
|
45
|
-
const data = await node_fs_1.promises.readFile((0, node_path_1.join)(assetPath, options.assetName));
|
46
|
-
const meta = await node_fs_1.promises.readFile((0, node_path_1.join)(assetPath, `${options.assetName}.meta.json`));
|
47
|
-
const { name, contentType } = JSON.parse(meta.toString());
|
48
|
-
return { data, name, contentType };
|
49
|
-
}
|
50
|
-
catch (error) {
|
51
|
-
this.logger.logError({
|
52
|
-
run: options.run,
|
53
|
-
message: `Failed to read asset ${options.assetName}`,
|
54
|
-
error,
|
55
|
-
});
|
56
|
-
throw error;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
exports.FileSystemAssetStorage = FileSystemAssetStorage;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { Asset, AssetStorage } from "./AssetStorage.js";
|
2
|
-
import { FlowRun } from "./FlowRun.js";
|
3
|
-
import { Logger } from "./Logger.js";
|
4
|
-
export declare class FileSystemAssetStorage implements AssetStorage {
|
5
|
-
private readonly path;
|
6
|
-
private readonly logger;
|
7
|
-
constructor({ path, logger, }: {
|
8
|
-
path: (run: FlowRun<unknown>) => string;
|
9
|
-
logger: Logger;
|
10
|
-
});
|
11
|
-
storeAsset({ run, asset, }: {
|
12
|
-
run: FlowRun<unknown>;
|
13
|
-
asset: Asset;
|
14
|
-
}): Promise<void>;
|
15
|
-
readAsset(options: {
|
16
|
-
run: FlowRun<unknown>;
|
17
|
-
assetName: string;
|
18
|
-
}): Promise<Asset | null>;
|
19
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import { promises as fs } from "node:fs";
|
2
|
-
import { join } from "node:path";
|
3
|
-
export class FileSystemAssetStorage {
|
4
|
-
constructor({ path, logger, }) {
|
5
|
-
Object.defineProperty(this, "path", {
|
6
|
-
enumerable: true,
|
7
|
-
configurable: true,
|
8
|
-
writable: true,
|
9
|
-
value: void 0
|
10
|
-
});
|
11
|
-
Object.defineProperty(this, "logger", {
|
12
|
-
enumerable: true,
|
13
|
-
configurable: true,
|
14
|
-
writable: true,
|
15
|
-
value: void 0
|
16
|
-
});
|
17
|
-
this.path = path;
|
18
|
-
this.logger = logger;
|
19
|
-
}
|
20
|
-
async storeAsset({ run, asset, }) {
|
21
|
-
try {
|
22
|
-
const assetPath = this.path(run);
|
23
|
-
await fs.mkdir(assetPath, { recursive: true });
|
24
|
-
await fs.writeFile(join(assetPath, asset.name), asset.data);
|
25
|
-
await fs.writeFile(join(assetPath, `${asset.name}.meta.json`), JSON.stringify({
|
26
|
-
name: asset.name,
|
27
|
-
contentType: asset.contentType,
|
28
|
-
}));
|
29
|
-
}
|
30
|
-
catch (error) {
|
31
|
-
this.logger.logError({
|
32
|
-
run,
|
33
|
-
message: `Failed to store asset ${asset.name}`,
|
34
|
-
error,
|
35
|
-
});
|
36
|
-
throw error;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
async readAsset(options) {
|
40
|
-
try {
|
41
|
-
const assetPath = this.path(options.run);
|
42
|
-
const data = await fs.readFile(join(assetPath, options.assetName));
|
43
|
-
const meta = await fs.readFile(join(assetPath, `${options.assetName}.meta.json`));
|
44
|
-
const { name, contentType } = JSON.parse(meta.toString());
|
45
|
-
return { data, name, contentType };
|
46
|
-
}
|
47
|
-
catch (error) {
|
48
|
-
this.logger.logError({
|
49
|
-
run: options.run,
|
50
|
-
message: `Failed to read asset ${options.assetName}`,
|
51
|
-
error,
|
52
|
-
});
|
53
|
-
throw error;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|