modelfusion 0.6.0 → 0.8.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 +27 -16
- package/composed-function/index.cjs +0 -3
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +1 -1
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/model-function/Model.d.ts +2 -2
- package/model-function/ModelCallEvent.d.ts +4 -6
- package/model-function/SuccessfulModelCall.cjs +6 -3
- package/model-function/SuccessfulModelCall.d.ts +3 -3
- package/model-function/SuccessfulModelCall.js +6 -3
- package/model-function/embed-text/embedText.cjs +16 -30
- package/model-function/embed-text/embedText.d.ts +14 -4
- package/model-function/embed-text/embedText.js +16 -30
- package/model-function/executeCall.cjs +6 -6
- package/model-function/executeCall.js +6 -6
- package/model-function/generate-image/generateImage.cjs +7 -20
- package/model-function/generate-image/generateImage.d.ts +7 -2
- package/model-function/generate-image/generateImage.js +7 -20
- package/model-function/generate-json/JsonGenerationEvent.d.ts +2 -2
- package/model-function/generate-json/generateJson.cjs +7 -5
- package/model-function/generate-json/generateJson.d.ts +6 -1
- package/model-function/generate-json/generateJson.js +7 -5
- package/model-function/generate-json/generateJsonOrText.cjs +11 -9
- package/model-function/generate-json/generateJsonOrText.d.ts +10 -1
- package/model-function/generate-json/generateJsonOrText.js +11 -9
- package/model-function/generate-text/generateText.cjs +7 -17
- package/model-function/generate-text/generateText.d.ts +7 -2
- package/model-function/generate-text/generateText.js +7 -17
- package/model-function/generate-text/streamText.cjs +13 -11
- package/model-function/generate-text/streamText.d.ts +9 -1
- package/model-function/generate-text/streamText.js +13 -11
- package/model-function/index.cjs +1 -1
- package/model-function/index.d.ts +1 -1
- package/model-function/index.js +1 -1
- package/model-function/transcribe-audio/transcribe.cjs +7 -19
- package/model-function/transcribe-audio/transcribe.d.ts +7 -2
- package/model-function/transcribe-audio/transcribe.js +7 -19
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +1 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +1 -1
- package/model-provider/cohere/CohereTextEmbeddingModel.js +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.cjs +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.js +1 -1
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +1 -1
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +1 -1
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +1 -1
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +1 -1
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAIImageGenerationModel.js +1 -1
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +1 -1
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +1 -1
- package/model-provider/openai/OpenAITextEmbeddingModel.js +1 -1
- package/model-provider/openai/OpenAITextGenerationModel.cjs +1 -1
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAITextGenerationModel.js +1 -1
- package/model-provider/openai/OpenAITranscriptionModel.cjs +1 -1
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -1
- package/model-provider/openai/OpenAITranscriptionModel.js +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
- package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +1 -1
- package/model-provider/stability/StabilityImageGenerationModel.cjs +1 -1
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +1 -1
- package/model-provider/stability/StabilityImageGenerationModel.js +1 -1
- package/package.json +1 -1
- package/run/ConsoleLogger.cjs +2 -2
- package/run/ConsoleLogger.d.ts +5 -5
- package/run/ConsoleLogger.js +2 -2
- package/run/DefaultRun.cjs +7 -7
- package/run/DefaultRun.d.ts +6 -6
- package/run/DefaultRun.js +7 -7
- package/run/Run.d.ts +2 -2
- package/run/RunFunction.d.ts +0 -4
- package/run/RunFunctionEvent.d.ts +12 -0
- package/{model-function/ModelCallEventSource.cjs → run/RunFunctionEventSource.cjs} +7 -7
- package/run/RunFunctionEventSource.d.ts +13 -0
- package/{model-function/ModelCallEventSource.js → run/RunFunctionEventSource.js} +5 -5
- package/run/RunFunctionObserver.cjs +2 -0
- package/run/RunFunctionObserver.d.ts +5 -0
- package/run/RunFunctionObserver.js +1 -0
- package/run/index.cjs +3 -0
- package/run/index.d.ts +3 -0
- package/run/index.js +3 -0
- package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -1
- package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -1
- package/text-chunk/upsertTextChunks.cjs +1 -1
- package/text-chunk/upsertTextChunks.js +1 -1
- package/tool/ExecuteToolEvent.cjs +2 -0
- package/tool/ExecuteToolEvent.d.ts +22 -0
- package/tool/ExecuteToolEvent.js +1 -0
- package/{composed-function/use-tool → tool}/Tool.cjs +7 -0
- package/{composed-function/use-tool → tool}/Tool.d.ts +5 -2
- package/{composed-function/use-tool → tool}/Tool.js +7 -0
- package/tool/ToolExecutionError.cjs +31 -0
- package/tool/ToolExecutionError.d.ts +11 -0
- package/tool/ToolExecutionError.js +27 -0
- package/tool/executeTool.cjs +79 -0
- package/tool/executeTool.d.ts +20 -0
- package/tool/executeTool.js +75 -0
- package/tool/index.cjs +22 -0
- package/tool/index.d.ts +6 -0
- package/tool/index.js +6 -0
- package/tool/useTool.cjs +33 -0
- package/tool/useTool.d.ts +15 -0
- package/tool/useTool.js +29 -0
- package/tool/useToolOrGenerateText.cjs +38 -0
- package/{composed-function/use-tool/useTool.d.ts → tool/useToolOrGenerateText.d.ts} +2 -15
- package/tool/useToolOrGenerateText.js +34 -0
- package/composed-function/use-tool/useTool.cjs +0 -59
- package/composed-function/use-tool/useTool.js +0 -54
- package/model-function/ModelCallEventSource.d.ts +0 -13
- package/model-function/ModelCallObserver.d.ts +0 -5
- /package/{model-function/ModelCallObserver.cjs → run/RunFunctionEvent.cjs} +0 -0
- /package/{model-function/ModelCallObserver.js → run/RunFunctionEvent.js} +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.cjs +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.d.ts +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.js +0 -0
@@ -30,7 +30,7 @@ exports.COHERE_TEXT_EMBEDDING_MODELS = {
|
|
30
30
|
* @see https://docs.cohere.com/reference/embed
|
31
31
|
*
|
32
32
|
* @example
|
33
|
-
* const
|
33
|
+
* const embeddings = await embedTexts(
|
34
34
|
* new CohereTextEmbeddingModel({ model: "embed-english-light-v2.0" }),
|
35
35
|
* [
|
36
36
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -38,7 +38,7 @@ export interface CohereTextEmbeddingModelSettings extends TextEmbeddingModelSett
|
|
38
38
|
* @see https://docs.cohere.com/reference/embed
|
39
39
|
*
|
40
40
|
* @example
|
41
|
-
* const
|
41
|
+
* const embeddings = await embedTexts(
|
42
42
|
* new CohereTextEmbeddingModel({ model: "embed-english-light-v2.0" }),
|
43
43
|
* [
|
44
44
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -24,7 +24,7 @@ export const COHERE_TEXT_EMBEDDING_MODELS = {
|
|
24
24
|
* @see https://docs.cohere.com/reference/embed
|
25
25
|
*
|
26
26
|
* @example
|
27
|
-
* const
|
27
|
+
* const embeddings = await embedTexts(
|
28
28
|
* new CohereTextEmbeddingModel({ model: "embed-english-light-v2.0" }),
|
29
29
|
* [
|
30
30
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -59,7 +59,7 @@ export interface CohereTextGenerationModelSettings extends TextGenerationModelSe
|
|
59
59
|
* maxTokens: 500,
|
60
60
|
* });
|
61
61
|
*
|
62
|
-
* const
|
62
|
+
* const text = await generateText(
|
63
63
|
* model,
|
64
64
|
* "Write a short story about a robot learning to love:\n\n"
|
65
65
|
* );
|
@@ -21,7 +21,7 @@ const HuggingFaceError_js_1 = require("./HuggingFaceError.cjs");
|
|
21
21
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
22
22
|
* });
|
23
23
|
*
|
24
|
-
* const
|
24
|
+
* const embeddings = await embedTexts(
|
25
25
|
* model,
|
26
26
|
* [
|
27
27
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -29,7 +29,7 @@ export interface HuggingFaceTextEmbeddingModelSettings extends TextEmbeddingMode
|
|
29
29
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
30
30
|
* });
|
31
31
|
*
|
32
|
-
* const
|
32
|
+
* const embeddings = await embedTexts(
|
33
33
|
* model,
|
34
34
|
* [
|
35
35
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -15,7 +15,7 @@ import { failedHuggingFaceCallResponseHandler } from "./HuggingFaceError.js";
|
|
15
15
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
16
16
|
* });
|
17
17
|
*
|
18
|
-
* const
|
18
|
+
* const embeddings = await embedTexts(
|
19
19
|
* model,
|
20
20
|
* [
|
21
21
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -23,7 +23,7 @@ const PromptMappingTextGenerationModel_js_1 = require("../../prompt/PromptMappin
|
|
23
23
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
24
24
|
* });
|
25
25
|
*
|
26
|
-
* const
|
26
|
+
* const text = await generateText(
|
27
27
|
* model,
|
28
28
|
* "Write a short story about a robot learning to love:\n\n"
|
29
29
|
* );
|
@@ -38,7 +38,7 @@ export interface HuggingFaceTextGenerationModelSettings extends TextGenerationMo
|
|
38
38
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
39
39
|
* });
|
40
40
|
*
|
41
|
-
* const
|
41
|
+
* const text = await generateText(
|
42
42
|
* model,
|
43
43
|
* "Write a short story about a robot learning to love:\n\n"
|
44
44
|
* );
|
@@ -17,7 +17,7 @@ import { PromptMappingTextGenerationModel } from "../../prompt/PromptMappingText
|
|
17
17
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
18
18
|
* });
|
19
19
|
*
|
20
|
-
* const
|
20
|
+
* const text = await generateText(
|
21
21
|
* model,
|
22
22
|
* "Write a short story about a robot learning to love:\n\n"
|
23
23
|
* );
|
@@ -22,7 +22,7 @@ exports.calculateOpenAIImageGenerationCostInMillicents = calculateOpenAIImageGen
|
|
22
22
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
23
23
|
*
|
24
24
|
* @example
|
25
|
-
* const
|
25
|
+
* const image = await generateImage(
|
26
26
|
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
27
27
|
* "the wicked witch of the west in the style of early 19th century painting"
|
28
28
|
* );
|
@@ -20,7 +20,7 @@ export interface OpenAIImageGenerationSettings extends ImageGenerationModelSetti
|
|
20
20
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
21
21
|
*
|
22
22
|
* @example
|
23
|
-
* const
|
23
|
+
* const image = await generateImage(
|
24
24
|
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
25
25
|
* "the wicked witch of the west in the style of early 19th century painting"
|
26
26
|
* );
|
@@ -18,7 +18,7 @@ export const calculateOpenAIImageGenerationCostInMillicents = ({ settings, }) =>
|
|
18
18
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
19
19
|
*
|
20
20
|
* @example
|
21
|
-
* const
|
21
|
+
* const image = await generateImage(
|
22
22
|
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
23
23
|
* "the wicked witch of the west in the style of early 19th century painting"
|
24
24
|
* );
|
@@ -36,7 +36,7 @@ exports.calculateOpenAIEmbeddingCostInMillicents = calculateOpenAIEmbeddingCostI
|
|
36
36
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
37
37
|
*
|
38
38
|
* @example
|
39
|
-
* const
|
39
|
+
* const embeddings = await embedTexts(
|
40
40
|
* new OpenAITextEmbeddingModel({ model: "text-embedding-ada-002" }),
|
41
41
|
* [
|
42
42
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -32,7 +32,7 @@ export interface OpenAITextEmbeddingModelSettings extends TextEmbeddingModelSett
|
|
32
32
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
33
33
|
*
|
34
34
|
* @example
|
35
|
-
* const
|
35
|
+
* const embeddings = await embedTexts(
|
36
36
|
* new OpenAITextEmbeddingModel({ model: "text-embedding-ada-002" }),
|
37
37
|
* [
|
38
38
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -28,7 +28,7 @@ export const calculateOpenAIEmbeddingCostInMillicents = ({ model, responses, })
|
|
28
28
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
29
29
|
*
|
30
30
|
* @example
|
31
|
-
* const
|
31
|
+
* const embeddings = await embedTexts(
|
32
32
|
* new OpenAITextEmbeddingModel({ model: "text-embedding-ada-002" }),
|
33
33
|
* [
|
34
34
|
* "At first, Nox didn't know what to do with the pup.",
|
@@ -79,7 +79,7 @@ exports.calculateOpenAITextGenerationCostInMillicents = calculateOpenAITextGener
|
|
79
79
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
80
80
|
* });
|
81
81
|
*
|
82
|
-
* const
|
82
|
+
* const text = await generateText(
|
83
83
|
* model,
|
84
84
|
* "Write a short story about a robot learning to love:\n\n"
|
85
85
|
* );
|
@@ -96,7 +96,7 @@ export interface OpenAITextGenerationModelSettings extends TextGenerationModelSe
|
|
96
96
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
97
97
|
* });
|
98
98
|
*
|
99
|
-
* const
|
99
|
+
* const text = await generateText(
|
100
100
|
* model,
|
101
101
|
* "Write a short story about a robot learning to love:\n\n"
|
102
102
|
* );
|
@@ -71,7 +71,7 @@ export const calculateOpenAITextGenerationCostInMillicents = ({ model, response,
|
|
71
71
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
72
72
|
* });
|
73
73
|
*
|
74
|
-
* const
|
74
|
+
* const text = await generateText(
|
75
75
|
* model,
|
76
76
|
* "Write a short story about a robot learning to love:\n\n"
|
77
77
|
* );
|
@@ -34,7 +34,7 @@ exports.calculateOpenAITranscriptionCostInMillicents = calculateOpenAITranscript
|
|
34
34
|
* @example
|
35
35
|
* const data = await fs.promises.readFile("data/test.mp3");
|
36
36
|
*
|
37
|
-
* const
|
37
|
+
* const transcription = await transcribe(
|
38
38
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
39
39
|
* {
|
40
40
|
* type: "mp3",
|
@@ -39,7 +39,7 @@ export type OpenAITranscriptionInput = {
|
|
39
39
|
* @example
|
40
40
|
* const data = await fs.promises.readFile("data/test.mp3");
|
41
41
|
*
|
42
|
-
* const
|
42
|
+
* const transcription = await transcribe(
|
43
43
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
44
44
|
* {
|
45
45
|
* type: "mp3",
|
@@ -27,7 +27,7 @@ export const calculateOpenAITranscriptionCostInMillicents = ({ model, response,
|
|
27
27
|
* @example
|
28
28
|
* const data = await fs.promises.readFile("data/test.mp3");
|
29
29
|
*
|
30
|
-
* const
|
30
|
+
* const transcription = await transcribe(
|
31
31
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
32
32
|
* {
|
33
33
|
* type: "mp3",
|
@@ -95,7 +95,7 @@ exports.calculateOpenAIChatCostInMillicents = calculateOpenAIChatCostInMillicent
|
|
95
95
|
* maxTokens: 500,
|
96
96
|
* });
|
97
97
|
*
|
98
|
-
* const
|
98
|
+
* const text = await generateText([
|
99
99
|
* model,
|
100
100
|
* OpenAIChatMessage.system(
|
101
101
|
* "Write a short story about a robot learning to love:"
|
@@ -109,7 +109,7 @@ export interface OpenAIChatSettings extends TextGenerationModelSettings, OpenAIM
|
|
109
109
|
* maxTokens: 500,
|
110
110
|
* });
|
111
111
|
*
|
112
|
-
* const
|
112
|
+
* const text = await generateText([
|
113
113
|
* model,
|
114
114
|
* OpenAIChatMessage.system(
|
115
115
|
* "Write a short story about a robot learning to love:"
|
@@ -87,7 +87,7 @@ export const calculateOpenAIChatCostInMillicents = ({ model, response, }) => res
|
|
87
87
|
* maxTokens: 500,
|
88
88
|
* });
|
89
89
|
*
|
90
|
-
* const
|
90
|
+
* const text = await generateText([
|
91
91
|
* model,
|
92
92
|
* OpenAIChatMessage.system(
|
93
93
|
* "Write a short story about a robot learning to love:"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
import { Tool } from "../../../composed-function/use-tool/Tool.js";
|
3
2
|
import { GenerateJsonPrompt } from "../../../model-function/generate-json/GenerateJsonModel.js";
|
4
3
|
import { GenerateJsonOrTextPrompt } from "../../../model-function/generate-json/GenerateJsonOrTextModel.js";
|
5
4
|
import { SchemaDefinition } from "../../../model-function/generate-json/SchemaDefinition.js";
|
5
|
+
import { Tool } from "../../../tool/Tool.js";
|
6
6
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
7
7
|
import { OpenAIChatResponse } from "./OpenAIChatModel.js";
|
8
8
|
export type OpenAIFunctionDescription<T> = {
|
@@ -12,7 +12,7 @@ const StabilityError_js_1 = require("./StabilityError.cjs");
|
|
12
12
|
* @see https://api.stability.ai/docs#tag/v1generation/operation/textToImage
|
13
13
|
*
|
14
14
|
* @example
|
15
|
-
* const
|
15
|
+
* const image = await generateImage(
|
16
16
|
* new StabilityImageGenerationModel({
|
17
17
|
* model: "stable-diffusion-512-v2-1",
|
18
18
|
* cfgScale: 7,
|
@@ -10,7 +10,7 @@ import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
|
10
10
|
* @see https://api.stability.ai/docs#tag/v1generation/operation/textToImage
|
11
11
|
*
|
12
12
|
* @example
|
13
|
-
* const
|
13
|
+
* const image = await generateImage(
|
14
14
|
* new StabilityImageGenerationModel({
|
15
15
|
* model: "stable-diffusion-512-v2-1",
|
16
16
|
* cfgScale: 7,
|
@@ -9,7 +9,7 @@ import { failedStabilityCallResponseHandler } from "./StabilityError.js";
|
|
9
9
|
* @see https://api.stability.ai/docs#tag/v1generation/operation/textToImage
|
10
10
|
*
|
11
11
|
* @example
|
12
|
-
* const
|
12
|
+
* const image = await generateImage(
|
13
13
|
* new StabilityImageGenerationModel({
|
14
14
|
* model: "stable-diffusion-512-v2-1",
|
15
15
|
* cfgScale: 7,
|
package/package.json
CHANGED
package/run/ConsoleLogger.cjs
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ConsoleLogger = void 0;
|
4
4
|
class ConsoleLogger {
|
5
|
-
|
5
|
+
onRunFunctionStarted(event) {
|
6
6
|
console.log(JSON.stringify(event, null, 2));
|
7
7
|
}
|
8
|
-
|
8
|
+
onRunFunctionFinished(event) {
|
9
9
|
console.log(JSON.stringify(event, null, 2));
|
10
10
|
}
|
11
11
|
}
|
package/run/ConsoleLogger.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
export declare class ConsoleLogger implements
|
4
|
-
|
5
|
-
|
1
|
+
import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
|
2
|
+
import { RunFunctionObserver } from "./RunFunctionObserver.js";
|
3
|
+
export declare class ConsoleLogger implements RunFunctionObserver {
|
4
|
+
onRunFunctionStarted(event: RunFunctionStartedEvent): void;
|
5
|
+
onRunFunctionFinished(event: RunFunctionFinishedEvent): void;
|
6
6
|
}
|
package/run/ConsoleLogger.js
CHANGED
package/run/DefaultRun.cjs
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DefaultRun = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
|
-
const SuccessfulModelCall_js_1 = require("../model-function/SuccessfulModelCall.cjs");
|
6
5
|
const calculateCost_js_1 = require("../cost/calculateCost.cjs");
|
6
|
+
const SuccessfulModelCall_js_1 = require("../model-function/SuccessfulModelCall.cjs");
|
7
7
|
class DefaultRun {
|
8
8
|
constructor({ runId = (0, nanoid_1.nanoid)(), sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
|
9
9
|
Object.defineProperty(this, "runId", {
|
@@ -36,7 +36,7 @@ class DefaultRun {
|
|
36
36
|
writable: true,
|
37
37
|
value: void 0
|
38
38
|
});
|
39
|
-
Object.defineProperty(this, "
|
39
|
+
Object.defineProperty(this, "events", {
|
40
40
|
enumerable: true,
|
41
41
|
configurable: true,
|
42
42
|
writable: true,
|
@@ -55,18 +55,18 @@ class DefaultRun {
|
|
55
55
|
this.costCalculators = costCalculators;
|
56
56
|
this.observers = [
|
57
57
|
{
|
58
|
-
|
59
|
-
this.
|
58
|
+
onRunFunctionStarted: (event) => {
|
59
|
+
this.events.push(event);
|
60
60
|
},
|
61
|
-
|
62
|
-
this.
|
61
|
+
onRunFunctionFinished: (event) => {
|
62
|
+
this.events.push(event);
|
63
63
|
},
|
64
64
|
},
|
65
65
|
...(observers ?? []),
|
66
66
|
];
|
67
67
|
}
|
68
68
|
get successfulModelCalls() {
|
69
|
-
return (0, SuccessfulModelCall_js_1.extractSuccessfulModelCalls)(this.
|
69
|
+
return (0, SuccessfulModelCall_js_1.extractSuccessfulModelCalls)(this.events);
|
70
70
|
}
|
71
71
|
calculateCost() {
|
72
72
|
return (0, calculateCost_js_1.calculateCost)({
|
package/run/DefaultRun.d.ts
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
+
import { CostCalculator } from "../cost/CostCalculator.js";
|
1
2
|
import { SuccessfulModelCall } from "../model-function/SuccessfulModelCall.js";
|
2
|
-
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
3
|
-
import { ModelCallObserver } from "../model-function/ModelCallObserver.js";
|
4
3
|
import { Run } from "./Run.js";
|
5
|
-
import {
|
4
|
+
import { RunFunctionEvent } from "./RunFunctionEvent.js";
|
5
|
+
import { RunFunctionObserver } from "./RunFunctionObserver.js";
|
6
6
|
export declare class DefaultRun implements Run {
|
7
7
|
readonly runId: string;
|
8
8
|
readonly sessionId?: string;
|
9
9
|
readonly userId?: string;
|
10
10
|
readonly abortSignal?: AbortSignal;
|
11
11
|
readonly costCalculators: CostCalculator[];
|
12
|
-
readonly
|
13
|
-
readonly observers?:
|
12
|
+
readonly events: RunFunctionEvent[];
|
13
|
+
readonly observers?: RunFunctionObserver[];
|
14
14
|
constructor({ runId, sessionId, userId, abortSignal, observers, costCalculators, }?: {
|
15
15
|
runId?: string;
|
16
16
|
sessionId?: string;
|
17
17
|
userId?: string;
|
18
18
|
abortSignal?: AbortSignal;
|
19
|
-
observers?:
|
19
|
+
observers?: RunFunctionObserver[];
|
20
20
|
costCalculators?: CostCalculator[];
|
21
21
|
});
|
22
22
|
get successfulModelCalls(): Array<SuccessfulModelCall>;
|
package/run/DefaultRun.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
-
import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
|
3
2
|
import { calculateCost } from "../cost/calculateCost.js";
|
3
|
+
import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
|
4
4
|
export class DefaultRun {
|
5
5
|
constructor({ runId = createId(), sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
|
6
6
|
Object.defineProperty(this, "runId", {
|
@@ -33,7 +33,7 @@ export class DefaultRun {
|
|
33
33
|
writable: true,
|
34
34
|
value: void 0
|
35
35
|
});
|
36
|
-
Object.defineProperty(this, "
|
36
|
+
Object.defineProperty(this, "events", {
|
37
37
|
enumerable: true,
|
38
38
|
configurable: true,
|
39
39
|
writable: true,
|
@@ -52,18 +52,18 @@ export class DefaultRun {
|
|
52
52
|
this.costCalculators = costCalculators;
|
53
53
|
this.observers = [
|
54
54
|
{
|
55
|
-
|
56
|
-
this.
|
55
|
+
onRunFunctionStarted: (event) => {
|
56
|
+
this.events.push(event);
|
57
57
|
},
|
58
|
-
|
59
|
-
this.
|
58
|
+
onRunFunctionFinished: (event) => {
|
59
|
+
this.events.push(event);
|
60
60
|
},
|
61
61
|
},
|
62
62
|
...(observers ?? []),
|
63
63
|
];
|
64
64
|
}
|
65
65
|
get successfulModelCalls() {
|
66
|
-
return extractSuccessfulModelCalls(this.
|
66
|
+
return extractSuccessfulModelCalls(this.events);
|
67
67
|
}
|
68
68
|
calculateCost() {
|
69
69
|
return calculateCost({
|
package/run/Run.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorHandler } from "../util/ErrorHandler.js";
|
2
|
-
import {
|
2
|
+
import { RunFunctionObserver } from "./RunFunctionObserver.js";
|
3
3
|
export interface Run {
|
4
4
|
/**
|
5
5
|
* Unique identifier for a specific run. Primarily utilized for efficient referencing
|
@@ -22,6 +22,6 @@ export interface Run {
|
|
22
22
|
* to the run.
|
23
23
|
*/
|
24
24
|
abortSignal?: AbortSignal;
|
25
|
-
observers?:
|
25
|
+
observers?: RunFunctionObserver[];
|
26
26
|
errorHandler?: ErrorHandler;
|
27
27
|
}
|
package/run/RunFunction.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { SafeResult } from "../util/SafeResult.js";
|
2
1
|
import { Run } from "./Run.js";
|
3
2
|
/**
|
4
3
|
* Standardized function signature for functions that are part of a run.
|
@@ -8,6 +7,3 @@ import { Run } from "./Run.js";
|
|
8
7
|
export type RunFunction<INPUT, OUTPUT> = (input: INPUT, options?: {
|
9
8
|
run?: Run;
|
10
9
|
}) => PromiseLike<OUTPUT>;
|
11
|
-
export type SafeRunFunction<INPUT, OUTPUT> = (input: INPUT, options?: {
|
12
|
-
run?: Run;
|
13
|
-
}) => PromiseLike<SafeResult<OUTPUT>>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "tool/ExecuteToolEvent.js";
|
2
|
+
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
3
|
+
import { IdMetadata } from "./IdMetadata.js";
|
4
|
+
export type RunFunctionEvent = RunFunctionStartedEvent | RunFunctionFinishedEvent;
|
5
|
+
export type RunFunctionStartedEventMetadata = IdMetadata & {
|
6
|
+
startEpochSeconds: number;
|
7
|
+
};
|
8
|
+
export type RunFunctionStartedEvent = ModelCallStartedEvent | ExecuteToolStartedEvent;
|
9
|
+
export type RunFunctionFinishedEventMetadata = RunFunctionStartedEventMetadata & {
|
10
|
+
durationInMs: number;
|
11
|
+
};
|
12
|
+
export type RunFunctionFinishedEvent = ModelCallFinishedEvent | ExecuteToolFinishedEvent;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
class
|
3
|
+
exports.RunFunctionEventSource = void 0;
|
4
|
+
class RunFunctionEventSource {
|
5
5
|
constructor({ observers, errorHandler, }) {
|
6
6
|
Object.defineProperty(this, "observers", {
|
7
7
|
enumerable: true,
|
@@ -18,20 +18,20 @@ class ModelCallEventSource {
|
|
18
18
|
this.observers = observers;
|
19
19
|
this.errorHandler = errorHandler ?? ((error) => console.error(error));
|
20
20
|
}
|
21
|
-
|
21
|
+
notifyRunFunctionStarted(event) {
|
22
22
|
for (const observer of this.observers) {
|
23
23
|
try {
|
24
|
-
observer.
|
24
|
+
observer.onRunFunctionStarted?.(event);
|
25
25
|
}
|
26
26
|
catch (error) {
|
27
27
|
this.errorHandler(error);
|
28
28
|
}
|
29
29
|
}
|
30
30
|
}
|
31
|
-
|
31
|
+
notifyRunFunctionFinished(event) {
|
32
32
|
for (const observer of this.observers) {
|
33
33
|
try {
|
34
|
-
observer.
|
34
|
+
observer.onRunFunctionFinished?.(event);
|
35
35
|
}
|
36
36
|
catch (error) {
|
37
37
|
this.errorHandler(error);
|
@@ -39,4 +39,4 @@ class ModelCallEventSource {
|
|
39
39
|
}
|
40
40
|
}
|
41
41
|
}
|
42
|
-
exports.
|
42
|
+
exports.RunFunctionEventSource = RunFunctionEventSource;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ErrorHandler } from "../util/ErrorHandler.js";
|
2
|
+
import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
|
3
|
+
import { RunFunctionObserver } from "./RunFunctionObserver.js";
|
4
|
+
export declare class RunFunctionEventSource {
|
5
|
+
readonly observers: RunFunctionObserver[];
|
6
|
+
readonly errorHandler: ErrorHandler;
|
7
|
+
constructor({ observers, errorHandler, }: {
|
8
|
+
observers: RunFunctionObserver[];
|
9
|
+
errorHandler?: ErrorHandler;
|
10
|
+
});
|
11
|
+
notifyRunFunctionStarted(event: RunFunctionStartedEvent): void;
|
12
|
+
notifyRunFunctionFinished(event: RunFunctionFinishedEvent): void;
|
13
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export class
|
1
|
+
export class RunFunctionEventSource {
|
2
2
|
constructor({ observers, errorHandler, }) {
|
3
3
|
Object.defineProperty(this, "observers", {
|
4
4
|
enumerable: true,
|
@@ -15,20 +15,20 @@ export class ModelCallEventSource {
|
|
15
15
|
this.observers = observers;
|
16
16
|
this.errorHandler = errorHandler ?? ((error) => console.error(error));
|
17
17
|
}
|
18
|
-
|
18
|
+
notifyRunFunctionStarted(event) {
|
19
19
|
for (const observer of this.observers) {
|
20
20
|
try {
|
21
|
-
observer.
|
21
|
+
observer.onRunFunctionStarted?.(event);
|
22
22
|
}
|
23
23
|
catch (error) {
|
24
24
|
this.errorHandler(error);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
28
|
-
|
28
|
+
notifyRunFunctionFinished(event) {
|
29
29
|
for (const observer of this.observers) {
|
30
30
|
try {
|
31
|
-
observer.
|
31
|
+
observer.onRunFunctionFinished?.(event);
|
32
32
|
}
|
33
33
|
catch (error) {
|
34
34
|
this.errorHandler(error);
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/run/index.cjs
CHANGED
@@ -19,4 +19,7 @@ __exportStar(require("./DefaultRun.cjs"), exports);
|
|
19
19
|
__exportStar(require("./IdMetadata.cjs"), exports);
|
20
20
|
__exportStar(require("./Run.cjs"), exports);
|
21
21
|
__exportStar(require("./RunFunction.cjs"), exports);
|
22
|
+
__exportStar(require("./RunFunctionEvent.cjs"), exports);
|
23
|
+
__exportStar(require("./RunFunctionObserver.cjs"), exports);
|
24
|
+
__exportStar(require("./RunFunctionEventSource.cjs"), exports);
|
22
25
|
__exportStar(require("./Vector.cjs"), exports);
|