modelfusion 0.105.0 → 0.106.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 +11 -0
- package/README.md +8 -10
- 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/Llama2PromptTemplate.cjs +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +1 -1
- 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/LlamaCppTextGenerationModel.d.ts +23 -23
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- 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/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-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/GuardEvent.js +0 -1
- 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.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
- /package/{cost/CostCalculator.js → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js} +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.106.0 - 2023-12-28
|
4
|
+
|
5
|
+
Experimental features that are unlikely to become stable before v1.0 have been moved to a separate `modelfusion-experimental` package.
|
6
|
+
|
7
|
+
### Removed
|
8
|
+
|
9
|
+
- Cost calculation
|
10
|
+
- `guard` function
|
11
|
+
- Browser and server features (incl. flow)
|
12
|
+
- `summarizeRecursively` function
|
13
|
+
|
3
14
|
## v0.105.0 - 2023-12-26
|
4
15
|
|
5
16
|
### Added
|
package/README.md
CHANGED
@@ -12,16 +12,13 @@
|
|
12
12
|
|
13
13
|
## Introduction
|
14
14
|
|
15
|
-
**ModelFusion** is
|
15
|
+
**ModelFusion** is an abstraction layer for integrating AI models into JavaScript and TypeScript applications, unifying the API for common operations such as text streaming, structure generation, and tool usage. It provides features to support production environments, including observability hooks, logging, and automatic retries. You can use ModelFusion to build AI applications, chatbots, and agents.
|
16
16
|
|
17
17
|
- **Vendor-neutral**: ModelFusion is a non-commercial open source project that is community-driven. You can use it with any supported provider.
|
18
18
|
- **Multi-modal**: ModelFusion supports a wide range of models including text generation, image generation, vision, text-to-speech, speech-to-text, and embedding models.
|
19
|
-
- **Streaming**: ModelFusion supports streaming for many generation models, e.g. text streaming, structure streaming, and full duplex speech streaming.
|
20
|
-
- **Utility functions**: ModelFusion provides functionality for tools and tool usage, vector indices, and guards functions.
|
21
19
|
- **Type inference and validation**: ModelFusion infers TypeScript types wherever possible and to validates model responses.
|
22
20
|
- **Observability and logging**: ModelFusion provides an observer framework and out-of-the-box logging support.
|
23
21
|
- **Resilience and Robustness**: ModelFusion ensures seamless operation through automatic retries, throttling, and error handling mechanisms.
|
24
|
-
- **Server**: ModelFusion provides a Fastify plugin that exposes a ModelFusion flow as a REST endpoint that uses server-sent events.
|
25
22
|
|
26
23
|
> [!NOTE]
|
27
24
|
> ModelFusion is in its initial development phase. The main API is now mostly stable, but until version 1.0 there may be breaking changes. Feedback and suggestions are welcome.
|
@@ -649,7 +646,7 @@ import { modelfusion } from "modelfusion";
|
|
649
646
|
modelfusion.setLogFormat("detailed-object"); // log full events
|
650
647
|
```
|
651
648
|
|
652
|
-
### [Server](https://modelfusion.dev/guide/server/)
|
649
|
+
### [Server](https://modelfusion.dev/guide/experimental/server/)
|
653
650
|
|
654
651
|
> [!WARNING]
|
655
652
|
> ModelFusion Server is in its initial development phase and not feature-complete. The API is experimental and breaking changes are likely. Feedback and suggestions are welcome.
|
@@ -668,7 +665,7 @@ import {
|
|
668
665
|
FileSystemAssetStorage,
|
669
666
|
FileSystemLogger,
|
670
667
|
modelFusionFastifyPlugin,
|
671
|
-
} from "modelfusion/fastify-server"; // '/fastify-server' import path
|
668
|
+
} from "modelfusion-experimental/fastify-server"; // '/fastify-server' import path
|
672
669
|
|
673
670
|
// configurable logging for all runs using ModelFusion observability:
|
674
671
|
const logger = new FileSystemLogger({
|
@@ -693,7 +690,7 @@ fastify.register(modelFusionFastifyPlugin, {
|
|
693
690
|
Using `invokeFlow`, you can easily connect your client to a ModelFusion flow endpoint:
|
694
691
|
|
695
692
|
```ts
|
696
|
-
import { invokeFlow } from "modelfusion/browser"; // '/browser' import path
|
693
|
+
import { invokeFlow } from "modelfusion-experimental/browser"; // '/browser' import path
|
697
694
|
|
698
695
|
invokeFlow({
|
699
696
|
url: `${BASE_URL}/myFlow`,
|
@@ -727,14 +724,12 @@ invokeFlow({
|
|
727
724
|
- [Generate structure or text](https://modelfusion.dev/guide/function/generate-structure-or-text)
|
728
725
|
- [Tokenize Text](https://modelfusion.dev/guide/function/tokenize-text)
|
729
726
|
- [Embed Value](https://modelfusion.dev/guide/function/embed)
|
730
|
-
- [Guards](https://modelfusion.dev/guide/guard)
|
731
727
|
- [Tools](https://modelfusion.dev/guide/tools)
|
732
728
|
- [Vector Indices](https://modelfusion.dev/guide/vector-index)
|
733
729
|
- [Upsert](https://modelfusion.dev/guide/vector-index/upsert)
|
734
730
|
- [Retrieve](https://modelfusion.dev/guide/vector-index/retrieve)
|
735
731
|
- [Text Chunks](https://modelfusion.dev/guide/text-chunk/)
|
736
732
|
- [Split Text](https://modelfusion.dev/guide/text-chunk/split)
|
737
|
-
- [Server](https://modelfusion.dev/guide/server/)
|
738
733
|
- [Utilities](https://modelfusion.dev/guide/util/)
|
739
734
|
- [API Configuration](https://modelfusion.dev/guide/util/api-configuration)
|
740
735
|
- [Retry strategies](https://modelfusion.dev/guide/util/api-configuration/retry)
|
@@ -743,7 +738,10 @@ invokeFlow({
|
|
743
738
|
- [Observers](https://modelfusion.dev/guide/util/observer)
|
744
739
|
- [Runs](https://modelfusion.dev/guide/util/run)
|
745
740
|
- [Abort signals](https://modelfusion.dev/guide/util/abort)
|
746
|
-
|
741
|
+
- [Experimental](https://modelfusion.dev/guide/experimental/)
|
742
|
+
- [Guards](https://modelfusion.dev/guide/experimental/guard)
|
743
|
+
- [Server](https://modelfusion.dev/guide/experimental/server/)
|
744
|
+
- [Cost calculation](https://modelfusion.dev/guide/experimental/cost-calculation)
|
747
745
|
- [Troubleshooting](https://modelfusion.dev/guide/troubleshooting)
|
748
746
|
- [Bundling](https://modelfusion.dev/guide/troubleshooting/bundling)
|
749
747
|
|
package/core/DefaultRun.cjs
CHANGED
@@ -2,7 +2,6 @@
|
|
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 FunctionEventSource_js_1 = require("./FunctionEventSource.cjs");
|
7
6
|
class DefaultRun {
|
8
7
|
constructor({ runId = `run-${(0, nanoid_1.nanoid)()}`, sessionId, userId, abortSignal, observers, errorHandler, } = {}) {
|
@@ -69,8 +68,5 @@ class DefaultRun {
|
|
69
68
|
errorHandler: this.errorHandler.bind(this),
|
70
69
|
});
|
71
70
|
}
|
72
|
-
get successfulModelCalls() {
|
73
|
-
return (0, SuccessfulModelCall_js_1.extractSuccessfulModelCalls)(this.events);
|
74
|
-
}
|
75
71
|
}
|
76
72
|
exports.DefaultRun = DefaultRun;
|
package/core/DefaultRun.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { SuccessfulModelCall } from "../model-function/SuccessfulModelCall.js";
|
2
1
|
import { ErrorHandler } from "../util/ErrorHandler.js";
|
3
2
|
import { FunctionEvent } from "./FunctionEvent.js";
|
4
3
|
import { FunctionObserver } from "./FunctionObserver.js";
|
@@ -22,5 +21,4 @@ export declare class DefaultRun implements Run {
|
|
22
21
|
readonly functionObserver: {
|
23
22
|
onFunctionEvent: (event: FunctionEvent) => void;
|
24
23
|
};
|
25
|
-
get successfulModelCalls(): Array<SuccessfulModelCall>;
|
26
24
|
}
|
package/core/DefaultRun.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
-
import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
|
3
2
|
import { FunctionEventSource } from "./FunctionEventSource.js";
|
4
3
|
export class DefaultRun {
|
5
4
|
constructor({ runId = `run-${createId()}`, sessionId, userId, abortSignal, observers, errorHandler, } = {}) {
|
@@ -66,7 +65,4 @@ export class DefaultRun {
|
|
66
65
|
errorHandler: this.errorHandler.bind(this),
|
67
66
|
});
|
68
67
|
}
|
69
|
-
get successfulModelCalls() {
|
70
|
-
return extractSuccessfulModelCalls(this.events);
|
71
|
-
}
|
72
68
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "./FunctionEvent.js";
|
2
|
+
export interface ExtensionFunctionStartedEvent extends BaseFunctionStartedEvent {
|
3
|
+
functionType: "extension";
|
4
|
+
extension: string;
|
5
|
+
data: unknown;
|
6
|
+
}
|
7
|
+
export interface ExtensionFunctionFinishedEvent extends BaseFunctionFinishedEvent {
|
8
|
+
functionType: "extension";
|
9
|
+
extension: string;
|
10
|
+
data: unknown;
|
11
|
+
}
|
package/core/FunctionEvent.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ExtensionFunctionStartedEvent, ExtensionFunctionFinishedEvent } from "./ExtensionFunctionEvent.js";
|
2
2
|
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
3
3
|
import { RetrieveFinishedEvent, RetrieveStartedEvent } from "../retriever/RetrieveEvent.js";
|
4
4
|
import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/execute-tool/ExecuteToolEvent.js";
|
@@ -82,4 +82,4 @@ export interface BaseFunctionFinishedEvent extends BaseFunctionEvent {
|
|
82
82
|
*/
|
83
83
|
result: BaseFunctionFinishedEventResult;
|
84
84
|
}
|
85
|
-
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent |
|
85
|
+
export type FunctionEvent = ExecuteFunctionStartedEvent | ExecuteFunctionFinishedEvent | ExecuteToolStartedEvent | ExecuteToolFinishedEvent | ExtensionFunctionStartedEvent | ExtensionFunctionFinishedEvent | ModelCallStartedEvent | ModelCallFinishedEvent | RetrieveStartedEvent | RetrieveFinishedEvent | UpsertIntoVectorIndexStartedEvent | UpsertIntoVectorIndexFinishedEvent | UseToolStartedEvent | UseToolFinishedEvent | UseToolsOrGenerateTextStartedEvent | UseToolsOrGenerateTextFinishedEvent;
|
package/extension/index.cjs
CHANGED
@@ -1,15 +1,34 @@
|
|
1
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
|
+
};
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AbstractModel = exports.
|
17
|
+
exports.parseEventSourceStream = exports.AbstractModel = exports.executeFunctionCall = exports.postToApi = exports.postJsonToApi = exports.createTextResponseHandler = exports.createJsonResponseHandler = exports.createAudioMpegResponseHandler = exports.loadApiKey = exports.callWithRetryAndThrottle = void 0;
|
18
|
+
__exportStar(require("../core/ExtensionFunctionEvent.cjs"), exports);
|
4
19
|
var callWithRetryAndThrottle_js_1 = require("../core/api/callWithRetryAndThrottle.cjs");
|
5
20
|
Object.defineProperty(exports, "callWithRetryAndThrottle", { enumerable: true, get: function () { return callWithRetryAndThrottle_js_1.callWithRetryAndThrottle; } });
|
6
21
|
var loadApiKey_js_1 = require("../core/api/loadApiKey.cjs");
|
7
22
|
Object.defineProperty(exports, "loadApiKey", { enumerable: true, get: function () { return loadApiKey_js_1.loadApiKey; } });
|
8
23
|
var postToApi_js_1 = require("../core/api/postToApi.cjs");
|
9
|
-
Object.defineProperty(exports, "postJsonToApi", { enumerable: true, get: function () { return postToApi_js_1.postJsonToApi; } });
|
10
|
-
Object.defineProperty(exports, "postToApi", { enumerable: true, get: function () { return postToApi_js_1.postToApi; } });
|
11
24
|
Object.defineProperty(exports, "createAudioMpegResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createAudioMpegResponseHandler; } });
|
12
25
|
Object.defineProperty(exports, "createJsonResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createJsonResponseHandler; } });
|
13
26
|
Object.defineProperty(exports, "createTextResponseHandler", { enumerable: true, get: function () { return postToApi_js_1.createTextResponseHandler; } });
|
27
|
+
Object.defineProperty(exports, "postJsonToApi", { enumerable: true, get: function () { return postToApi_js_1.postJsonToApi; } });
|
28
|
+
Object.defineProperty(exports, "postToApi", { enumerable: true, get: function () { return postToApi_js_1.postToApi; } });
|
29
|
+
var executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
|
30
|
+
Object.defineProperty(exports, "executeFunctionCall", { enumerable: true, get: function () { return executeFunctionCall_js_1.executeFunctionCall; } });
|
14
31
|
var AbstractModel_js_1 = require("../model-function/AbstractModel.cjs");
|
15
32
|
Object.defineProperty(exports, "AbstractModel", { enumerable: true, get: function () { return AbstractModel_js_1.AbstractModel; } });
|
33
|
+
var parseEventSourceStream_js_1 = require("../util/streaming/parseEventSourceStream.cjs");
|
34
|
+
Object.defineProperty(exports, "parseEventSourceStream", { enumerable: true, get: function () { return parseEventSourceStream_js_1.parseEventSourceStream; } });
|
package/extension/index.d.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
export * from "../core/ExtensionFunctionEvent.js";
|
1
2
|
export { callWithRetryAndThrottle } from "../core/api/callWithRetryAndThrottle.js";
|
2
3
|
export { loadApiKey } from "../core/api/loadApiKey.js";
|
3
|
-
export {
|
4
|
+
export { ResponseHandler, createAudioMpegResponseHandler, createJsonResponseHandler, createTextResponseHandler, postJsonToApi, postToApi, } from "../core/api/postToApi.js";
|
5
|
+
export { executeFunctionCall } from "../core/executeFunctionCall.js";
|
4
6
|
export { AbstractModel } from "../model-function/AbstractModel.js";
|
7
|
+
export { ErrorHandler } from "../util/ErrorHandler.js";
|
8
|
+
export { parseEventSourceStream } from "../util/streaming/parseEventSourceStream.js";
|
package/extension/index.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
export * from "../core/ExtensionFunctionEvent.js";
|
1
2
|
export { callWithRetryAndThrottle } from "../core/api/callWithRetryAndThrottle.js";
|
2
3
|
export { loadApiKey } from "../core/api/loadApiKey.js";
|
3
|
-
export {
|
4
|
+
export { createAudioMpegResponseHandler, createJsonResponseHandler, createTextResponseHandler, postJsonToApi, postToApi, } from "../core/api/postToApi.js";
|
5
|
+
export { executeFunctionCall } from "../core/executeFunctionCall.js";
|
4
6
|
export { AbstractModel } from "../model-function/AbstractModel.js";
|
7
|
+
export { parseEventSourceStream } from "../util/streaming/parseEventSourceStream.js";
|
package/index.cjs
CHANGED
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./composed-function/index.cjs"), exports);
|
18
17
|
__exportStar(require("./core/index.cjs"), exports);
|
19
|
-
__exportStar(require("./cost/index.cjs"), exports);
|
20
|
-
__exportStar(require("./guard/index.cjs"), exports);
|
21
18
|
__exportStar(require("./model-function/index.cjs"), exports);
|
22
19
|
__exportStar(require("./model-provider/index.cjs"), exports);
|
23
20
|
__exportStar(require("./observability/index.cjs"), exports);
|
package/index.d.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
export * from "./composed-function/index.js";
|
2
1
|
export * from "./core/index.js";
|
3
|
-
export * from "./cost/index.js";
|
4
|
-
export * from "./guard/index.js";
|
5
2
|
export * from "./model-function/index.js";
|
6
3
|
export * from "./model-provider/index.js";
|
7
4
|
export * from "./observability/index.js";
|
package/index.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
export * from "./composed-function/index.js";
|
2
1
|
export * from "./core/index.js";
|
3
|
-
export * from "./cost/index.js";
|
4
|
-
export * from "./guard/index.js";
|
5
2
|
export * from "./model-function/index.js";
|
6
3
|
export * from "./model-provider/index.js";
|
7
4
|
export * from "./observability/index.js";
|
@@ -2,10 +2,46 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.jsonStructurePrompt = void 0;
|
4
4
|
const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
const DEFAULT_SCHEMA_PREFIX = "JSON schema:";
|
6
|
+
const DEFAULT_SCHEMA_SUFFIX = "\nYou MUST answer with a JSON object matches the above schema.";
|
7
|
+
exports.jsonStructurePrompt = {
|
8
|
+
custom(createPrompt) {
|
9
|
+
return { createPrompt, extractStructure };
|
10
|
+
},
|
11
|
+
text({ schemaPrefix, schemaSuffix, } = {}) {
|
12
|
+
return {
|
13
|
+
createPrompt: (prompt, schema) => ({
|
14
|
+
system: createSystemPrompt({ schema, schemaPrefix, schemaSuffix }),
|
15
|
+
instruction: prompt,
|
16
|
+
}),
|
17
|
+
extractStructure,
|
18
|
+
};
|
19
|
+
},
|
20
|
+
instruction({ schemaPrefix, schemaSuffix, } = {}) {
|
21
|
+
return {
|
22
|
+
createPrompt: (prompt, schema) => ({
|
23
|
+
system: createSystemPrompt({
|
24
|
+
originalSystemPrompt: prompt.system,
|
25
|
+
schema,
|
26
|
+
schemaPrefix,
|
27
|
+
schemaSuffix,
|
28
|
+
}),
|
29
|
+
instruction: prompt.instruction,
|
30
|
+
}),
|
31
|
+
extractStructure,
|
32
|
+
};
|
33
|
+
},
|
34
|
+
};
|
35
|
+
function createSystemPrompt({ originalSystemPrompt, schema, schemaPrefix = DEFAULT_SCHEMA_PREFIX, schemaSuffix = DEFAULT_SCHEMA_SUFFIX, }) {
|
36
|
+
return [
|
37
|
+
originalSystemPrompt,
|
38
|
+
schemaPrefix,
|
39
|
+
JSON.stringify(schema.getJsonSchema()),
|
40
|
+
schemaSuffix,
|
41
|
+
]
|
42
|
+
.filter(Boolean)
|
43
|
+
.join("\n");
|
44
|
+
}
|
45
|
+
function extractStructure(response) {
|
46
|
+
return (0, parseJSON_js_1.parseJSON)({ text: response });
|
10
47
|
}
|
11
|
-
exports.jsonStructurePrompt = jsonStructurePrompt;
|
@@ -1,4 +1,15 @@
|
|
1
1
|
import { JsonSchemaProducer } from "../../core/schema/JsonSchemaProducer.js";
|
2
2
|
import { Schema } from "../../core/schema/Schema.js";
|
3
|
+
import { InstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
|
3
4
|
import { StructureFromTextPromptTemplate } from "./StructureFromTextPromptTemplate.js";
|
4
|
-
export declare
|
5
|
+
export declare const jsonStructurePrompt: {
|
6
|
+
custom<SOURCE_PROMPT, TARGET_PROMPT>(createPrompt: (prompt: SOURCE_PROMPT, schema: Schema<unknown> & JsonSchemaProducer) => TARGET_PROMPT): StructureFromTextPromptTemplate<SOURCE_PROMPT, TARGET_PROMPT>;
|
7
|
+
text({ schemaPrefix, schemaSuffix, }?: {
|
8
|
+
schemaPrefix?: string | undefined;
|
9
|
+
schemaSuffix?: string | undefined;
|
10
|
+
}): StructureFromTextPromptTemplate<string, InstructionPrompt>;
|
11
|
+
instruction({ schemaPrefix, schemaSuffix, }?: {
|
12
|
+
schemaPrefix?: string | undefined;
|
13
|
+
schemaSuffix?: string | undefined;
|
14
|
+
}): StructureFromTextPromptTemplate<InstructionPrompt, InstructionPrompt>;
|
15
|
+
};
|
@@ -1,7 +1,44 @@
|
|
1
1
|
import { parseJSON } from "../../core/schema/parseJSON.js";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
const DEFAULT_SCHEMA_PREFIX = "JSON schema:";
|
3
|
+
const DEFAULT_SCHEMA_SUFFIX = "\nYou MUST answer with a JSON object matches the above schema.";
|
4
|
+
export const jsonStructurePrompt = {
|
5
|
+
custom(createPrompt) {
|
6
|
+
return { createPrompt, extractStructure };
|
7
|
+
},
|
8
|
+
text({ schemaPrefix, schemaSuffix, } = {}) {
|
9
|
+
return {
|
10
|
+
createPrompt: (prompt, schema) => ({
|
11
|
+
system: createSystemPrompt({ schema, schemaPrefix, schemaSuffix }),
|
12
|
+
instruction: prompt,
|
13
|
+
}),
|
14
|
+
extractStructure,
|
15
|
+
};
|
16
|
+
},
|
17
|
+
instruction({ schemaPrefix, schemaSuffix, } = {}) {
|
18
|
+
return {
|
19
|
+
createPrompt: (prompt, schema) => ({
|
20
|
+
system: createSystemPrompt({
|
21
|
+
originalSystemPrompt: prompt.system,
|
22
|
+
schema,
|
23
|
+
schemaPrefix,
|
24
|
+
schemaSuffix,
|
25
|
+
}),
|
26
|
+
instruction: prompt.instruction,
|
27
|
+
}),
|
28
|
+
extractStructure,
|
29
|
+
};
|
30
|
+
},
|
31
|
+
};
|
32
|
+
function createSystemPrompt({ originalSystemPrompt, schema, schemaPrefix = DEFAULT_SCHEMA_PREFIX, schemaSuffix = DEFAULT_SCHEMA_SUFFIX, }) {
|
33
|
+
return [
|
34
|
+
originalSystemPrompt,
|
35
|
+
schemaPrefix,
|
36
|
+
JSON.stringify(schema.getJsonSchema()),
|
37
|
+
schemaSuffix,
|
38
|
+
]
|
39
|
+
.filter(Boolean)
|
40
|
+
.join("\n");
|
41
|
+
}
|
42
|
+
function extractStructure(response) {
|
43
|
+
return parseJSON({ text: response });
|
7
44
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { TextGenerationToolCallModel, ToolCallPromptTemplate } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
3
|
-
import { TextGenerationToolCallsOrGenerateTextModel
|
3
|
+
import { TextGenerationToolCallsOrGenerateTextModel } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
4
|
+
import { ToolCallsOrGenerateTextPromptTemplate } from "../../tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js";
|
4
5
|
import { StructureFromTextGenerationModel } from "../generate-structure/StructureFromTextGenerationModel.js";
|
5
6
|
import { StructureFromTextPromptTemplate } from "../generate-structure/StructureFromTextPromptTemplate.js";
|
6
7
|
import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { TextGenerationToolCallModel, } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
2
|
-
import { TextGenerationToolCallsOrGenerateTextModel
|
2
|
+
import { TextGenerationToolCallsOrGenerateTextModel } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
3
3
|
import { StructureFromTextGenerationModel } from "../generate-structure/StructureFromTextGenerationModel.js";
|
4
4
|
export class PromptTemplateTextGenerationModel {
|
5
5
|
constructor({ model, promptTemplate, }) {
|
package/model-function/index.cjs
CHANGED
@@ -20,7 +20,6 @@ __exportStar(require("./ModelCallEvent.cjs"), exports);
|
|
20
20
|
__exportStar(require("./ModelCallMetadata.cjs"), exports);
|
21
21
|
__exportStar(require("./ModelInformation.cjs"), exports);
|
22
22
|
__exportStar(require("./PromptTemplate.cjs"), exports);
|
23
|
-
__exportStar(require("./SuccessfulModelCall.cjs"), exports);
|
24
23
|
__exportStar(require("./embed/EmbeddingEvent.cjs"), exports);
|
25
24
|
__exportStar(require("./embed/EmbeddingModel.cjs"), exports);
|
26
25
|
__exportStar(require("./embed/embed.cjs"), exports);
|
@@ -4,7 +4,6 @@ export * from "./ModelCallEvent.js";
|
|
4
4
|
export * from "./ModelCallMetadata.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./PromptTemplate.js";
|
7
|
-
export * from "./SuccessfulModelCall.js";
|
8
7
|
export * from "./embed/EmbeddingEvent.js";
|
9
8
|
export * from "./embed/EmbeddingModel.js";
|
10
9
|
export * from "./embed/embed.js";
|
package/model-function/index.js
CHANGED
@@ -4,7 +4,6 @@ export * from "./ModelCallEvent.js";
|
|
4
4
|
export * from "./ModelCallMetadata.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./PromptTemplate.js";
|
7
|
-
export * from "./SuccessfulModelCall.js";
|
8
7
|
export * from "./embed/EmbeddingEvent.js";
|
9
8
|
export * from "./embed/EmbeddingModel.js";
|
10
9
|
export * from "./embed/embed.js";
|
@@ -74,8 +74,8 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
|
|
74
74
|
get settingsForEvent(): Partial<CohereTextEmbeddingModelSettings>;
|
75
75
|
doEmbedValues(texts: string[], options?: FunctionOptions): Promise<{
|
76
76
|
response: {
|
77
|
-
texts: string[];
|
78
77
|
embeddings: number[][];
|
78
|
+
texts: string[];
|
79
79
|
id: string;
|
80
80
|
meta: {
|
81
81
|
api_version: {
|
@@ -109,8 +109,8 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
109
109
|
};
|
110
110
|
}>;
|
111
111
|
}, "strip", z.ZodTypeAny, {
|
112
|
-
texts: string[];
|
113
112
|
embeddings: number[][];
|
113
|
+
texts: string[];
|
114
114
|
id: string;
|
115
115
|
meta: {
|
116
116
|
api_version: {
|
@@ -118,8 +118,8 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
118
118
|
};
|
119
119
|
};
|
120
120
|
}, {
|
121
|
-
texts: string[];
|
122
121
|
embeddings: number[][];
|
122
|
+
texts: string[];
|
123
123
|
id: string;
|
124
124
|
meta: {
|
125
125
|
api_version: {
|
@@ -66,8 +66,8 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
66
66
|
get settingsForEvent(): Partial<CohereTextGenerationModelSettings>;
|
67
67
|
doGenerateTexts(prompt: string, options?: FunctionOptions): Promise<{
|
68
68
|
response: {
|
69
|
-
prompt: string;
|
70
69
|
id: string;
|
70
|
+
prompt: string;
|
71
71
|
generations: {
|
72
72
|
text: string;
|
73
73
|
id: string;
|
@@ -90,8 +90,8 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
90
90
|
is_finished: false;
|
91
91
|
} | {
|
92
92
|
response: {
|
93
|
-
prompt: string;
|
94
93
|
id: string;
|
94
|
+
prompt: string;
|
95
95
|
generations: {
|
96
96
|
text: string;
|
97
97
|
id: string;
|
@@ -155,8 +155,8 @@ declare const cohereTextGenerationResponseSchema: z.ZodObject<{
|
|
155
155
|
};
|
156
156
|
}>>;
|
157
157
|
}, "strip", z.ZodTypeAny, {
|
158
|
-
prompt: string;
|
159
158
|
id: string;
|
159
|
+
prompt: string;
|
160
160
|
generations: {
|
161
161
|
text: string;
|
162
162
|
id: string;
|
@@ -168,8 +168,8 @@ declare const cohereTextGenerationResponseSchema: z.ZodObject<{
|
|
168
168
|
};
|
169
169
|
} | undefined;
|
170
170
|
}, {
|
171
|
-
prompt: string;
|
172
171
|
id: string;
|
172
|
+
prompt: string;
|
173
173
|
generations: {
|
174
174
|
text: string;
|
175
175
|
id: string;
|
@@ -193,8 +193,8 @@ export declare const CohereTextGenerationResponseFormat: {
|
|
193
193
|
json: {
|
194
194
|
stream: boolean;
|
195
195
|
handler: ResponseHandler<{
|
196
|
-
prompt: string;
|
197
196
|
id: string;
|
197
|
+
prompt: string;
|
198
198
|
generations: {
|
199
199
|
text: string;
|
200
200
|
id: string;
|
@@ -220,8 +220,8 @@ export declare const CohereTextGenerationResponseFormat: {
|
|
220
220
|
is_finished: false;
|
221
221
|
} | {
|
222
222
|
response: {
|
223
|
-
prompt: string;
|
224
223
|
id: string;
|
224
|
+
prompt: string;
|
225
225
|
generations: {
|
226
226
|
text: string;
|
227
227
|
id: string;
|