modelfusion 0.112.0 → 0.114.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 +105 -0
- package/README.md +108 -212
- package/core/FunctionOptions.d.ts +14 -0
- package/core/api/AbstractApiConfiguration.cjs +16 -1
- package/core/api/AbstractApiConfiguration.d.ts +7 -3
- package/core/api/AbstractApiConfiguration.js +16 -1
- package/core/api/ApiConfiguration.d.ts +10 -1
- package/core/api/BaseUrlApiConfiguration.cjs +9 -5
- package/core/api/BaseUrlApiConfiguration.d.ts +7 -7
- package/core/api/BaseUrlApiConfiguration.js +9 -5
- package/core/api/CustomHeaderProvider.cjs +2 -0
- package/core/api/CustomHeaderProvider.d.ts +2 -0
- package/core/api/CustomHeaderProvider.js +1 -0
- package/core/api/index.cjs +1 -0
- package/core/api/index.d.ts +1 -0
- package/core/api/index.js +1 -0
- package/core/cache/Cache.cjs +2 -0
- package/core/cache/Cache.d.ts +12 -0
- package/core/cache/Cache.js +1 -0
- package/core/cache/MemoryCache.cjs +23 -0
- package/core/cache/MemoryCache.d.ts +15 -0
- package/core/cache/MemoryCache.js +19 -0
- package/core/cache/index.cjs +18 -0
- package/core/cache/index.d.ts +2 -0
- package/core/cache/index.js +2 -0
- package/core/index.cjs +1 -0
- package/core/index.d.ts +1 -0
- package/core/index.js +1 -0
- package/core/schema/TypeValidationError.cjs +36 -0
- package/core/schema/TypeValidationError.d.ts +15 -0
- package/core/schema/TypeValidationError.js +32 -0
- package/core/schema/index.cjs +2 -0
- package/core/schema/index.d.ts +2 -0
- package/core/schema/index.js +2 -0
- package/core/schema/parseJSON.cjs +6 -14
- package/core/schema/parseJSON.d.ts +3 -2
- package/core/schema/parseJSON.js +6 -14
- package/core/schema/validateTypes.cjs +65 -0
- package/core/schema/validateTypes.d.ts +34 -0
- package/core/schema/validateTypes.js +60 -0
- package/model-function/embed/EmbeddingModel.d.ts +2 -2
- package/model-function/executeStandardCall.cjs +3 -1
- package/model-function/executeStandardCall.d.ts +2 -2
- package/model-function/executeStandardCall.js +3 -1
- package/model-function/executeStreamCall.cjs +2 -1
- package/model-function/executeStreamCall.d.ts +2 -2
- package/model-function/executeStreamCall.js +2 -1
- package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
- package/model-function/generate-image/PromptTemplateImageGenerationModel.d.ts +2 -2
- package/model-function/generate-speech/SpeechGenerationModel.d.ts +3 -3
- package/model-function/generate-structure/StructureFromTextPromptTemplate.d.ts +13 -0
- package/model-function/generate-structure/generateStructure.cjs +4 -1
- package/model-function/generate-structure/generateStructure.js +4 -1
- package/model-function/generate-structure/jsonStructurePrompt.cjs +12 -0
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +3 -3
- package/model-function/generate-structure/jsonStructurePrompt.js +12 -0
- package/model-function/generate-structure/streamStructure.cjs +4 -1
- package/model-function/generate-structure/streamStructure.js +4 -1
- package/model-function/generate-text/PromptTemplateTextGenerationModel.cjs +3 -0
- package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +11 -2
- package/model-function/generate-text/PromptTemplateTextGenerationModel.js +3 -0
- package/model-function/generate-text/PromptTemplateTextStreamingModel.d.ts +2 -2
- package/model-function/generate-text/TextGenerationModel.d.ts +16 -3
- package/model-function/generate-text/generateText.cjs +43 -1
- package/model-function/generate-text/generateText.js +43 -1
- package/model-function/generate-transcription/TranscriptionModel.d.ts +2 -2
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +20 -8
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +27 -5
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +20 -8
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +8 -3
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +8 -3
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +8 -3
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextEmbeddingModel.js +8 -3
- package/model-provider/cohere/CohereTextGenerationModel.cjs +20 -8
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +45 -5
- package/model-provider/cohere/CohereTextGenerationModel.js +20 -8
- package/model-provider/cohere/CohereTokenizer.cjs +16 -6
- package/model-provider/cohere/CohereTokenizer.d.ts +3 -3
- package/model-provider/cohere/CohereTokenizer.js +16 -6
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.cjs +1 -1
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.js +1 -1
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +8 -3
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.d.ts +2 -2
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +8 -3
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +8 -3
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -3
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +8 -3
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +18 -4
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +21 -3
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +18 -4
- package/model-provider/llamacpp/LlamaCppCompletionModel.cjs +20 -8
- package/model-provider/llamacpp/LlamaCppCompletionModel.d.ts +125 -5
- package/model-provider/llamacpp/LlamaCppCompletionModel.js +20 -8
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +8 -3
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +3 -3
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +8 -3
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +8 -3
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +2 -2
- package/model-provider/llamacpp/LlamaCppTokenizer.js +8 -3
- package/model-provider/lmnt/LmntSpeechModel.cjs +8 -3
- package/model-provider/lmnt/LmntSpeechModel.d.ts +2 -2
- package/model-provider/lmnt/LmntSpeechModel.js +8 -3
- package/model-provider/mistral/MistralChatModel.cjs +20 -8
- package/model-provider/mistral/MistralChatModel.d.ts +55 -5
- package/model-provider/mistral/MistralChatModel.js +20 -8
- package/model-provider/mistral/MistralTextEmbeddingModel.cjs +8 -3
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +3 -3
- package/model-provider/mistral/MistralTextEmbeddingModel.js +8 -3
- package/model-provider/ollama/OllamaChatModel.cjs +35 -8
- package/model-provider/ollama/OllamaChatModel.d.ts +31 -5
- package/model-provider/ollama/OllamaChatModel.js +35 -8
- package/model-provider/ollama/OllamaCompletionModel.cjs +20 -7
- package/model-provider/ollama/OllamaCompletionModel.d.ts +43 -5
- package/model-provider/ollama/OllamaCompletionModel.js +20 -7
- package/model-provider/ollama/OllamaTextEmbeddingModel.cjs +8 -3
- package/model-provider/ollama/OllamaTextEmbeddingModel.d.ts +3 -3
- package/model-provider/ollama/OllamaTextEmbeddingModel.js +8 -3
- package/model-provider/openai/AbstractOpenAIChatModel.cjs +23 -13
- package/model-provider/openai/AbstractOpenAIChatModel.d.ts +94 -7
- package/model-provider/openai/AbstractOpenAIChatModel.js +23 -13
- package/model-provider/openai/AbstractOpenAICompletionModel.cjs +21 -9
- package/model-provider/openai/AbstractOpenAICompletionModel.d.ts +35 -5
- package/model-provider/openai/AbstractOpenAICompletionModel.js +21 -9
- package/model-provider/openai/AzureOpenAIApiConfiguration.cjs +5 -2
- package/model-provider/openai/AzureOpenAIApiConfiguration.d.ts +2 -1
- package/model-provider/openai/AzureOpenAIApiConfiguration.js +5 -2
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.cjs +12 -6
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.d.ts +89 -5
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.js +12 -6
- package/model-provider/openai/OpenAIChatModel.cjs +12 -4
- package/model-provider/openai/OpenAIChatModel.d.ts +3 -2
- package/model-provider/openai/OpenAIChatModel.js +12 -4
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +10 -6
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +4 -4
- package/model-provider/openai/OpenAIImageGenerationModel.js +10 -6
- package/model-provider/openai/OpenAISpeechModel.cjs +9 -4
- package/model-provider/openai/OpenAISpeechModel.d.ts +3 -3
- package/model-provider/openai/OpenAISpeechModel.js +9 -4
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +11 -6
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
- package/model-provider/openai/OpenAITextEmbeddingModel.js +11 -6
- package/model-provider/openai/OpenAITranscriptionModel.cjs +9 -6
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +4 -4
- package/model-provider/openai/OpenAITranscriptionModel.js +9 -6
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +12 -4
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +3 -2
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +12 -4
- package/model-provider/stability/StabilityImageGenerationModel.cjs +10 -5
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +3 -3
- package/model-provider/stability/StabilityImageGenerationModel.js +10 -5
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.cjs +9 -7
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.d.ts +3 -3
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.js +9 -7
- package/observability/helicone/HeliconeOpenAIApiConfiguration.cjs +2 -1
- package/observability/helicone/HeliconeOpenAIApiConfiguration.d.ts +3 -1
- package/observability/helicone/HeliconeOpenAIApiConfiguration.js +2 -1
- package/package.json +2 -2
@@ -1,4 +1,5 @@
|
|
1
1
|
import { AbstractApiConfiguration } from "./AbstractApiConfiguration.js";
|
2
|
+
import { CustomHeaderProvider } from "./CustomHeaderProvider.js";
|
2
3
|
import { RetryFunction } from "./RetryFunction.js";
|
3
4
|
import { ThrottleFunction } from "./ThrottleFunction.js";
|
4
5
|
export type UrlParts = {
|
@@ -10,6 +11,7 @@ export type UrlParts = {
|
|
10
11
|
export type BaseUrlPartsApiConfigurationOptions = {
|
11
12
|
baseUrl: string | UrlParts;
|
12
13
|
headers?: Record<string, string>;
|
14
|
+
customCallHeaders?: CustomHeaderProvider;
|
13
15
|
retry?: RetryFunction;
|
14
16
|
throttle?: ThrottleFunction;
|
15
17
|
};
|
@@ -20,18 +22,16 @@ export type BaseUrlPartsApiConfigurationOptions = {
|
|
20
22
|
*/
|
21
23
|
export declare class BaseUrlApiConfiguration extends AbstractApiConfiguration {
|
22
24
|
readonly baseUrl: UrlParts;
|
23
|
-
readonly
|
24
|
-
constructor({ baseUrl, headers, retry, throttle, }: BaseUrlPartsApiConfigurationOptions);
|
25
|
+
protected readonly fixedHeadersValue: Record<string, string>;
|
26
|
+
constructor({ baseUrl, headers, retry, throttle, customCallHeaders, }: BaseUrlPartsApiConfigurationOptions);
|
27
|
+
fixedHeaders(): Record<string, string>;
|
25
28
|
assembleUrl(path: string): string;
|
26
29
|
}
|
27
|
-
export type PartialBaseUrlPartsApiConfigurationOptions = {
|
30
|
+
export type PartialBaseUrlPartsApiConfigurationOptions = Omit<BaseUrlPartsApiConfigurationOptions, "baseUrl"> & {
|
28
31
|
baseUrl?: string | Partial<UrlParts>;
|
29
|
-
headers?: Record<string, string>;
|
30
|
-
retry?: RetryFunction;
|
31
|
-
throttle?: ThrottleFunction;
|
32
32
|
};
|
33
33
|
export declare class BaseUrlApiConfigurationWithDefaults extends BaseUrlApiConfiguration {
|
34
|
-
constructor({ baseUrlDefaults, baseUrl, headers, retry, throttle, }: {
|
34
|
+
constructor({ baseUrlDefaults, baseUrl, headers, retry, throttle, customCallHeaders, }: {
|
35
35
|
baseUrlDefaults: UrlParts;
|
36
36
|
} & PartialBaseUrlPartsApiConfigurationOptions);
|
37
37
|
}
|
@@ -5,22 +5,25 @@ import { AbstractApiConfiguration } from "./AbstractApiConfiguration.js";
|
|
5
5
|
* You can use it to configure custom APIs for models, e.g. your own internal OpenAI proxy with custom headers.
|
6
6
|
*/
|
7
7
|
export class BaseUrlApiConfiguration extends AbstractApiConfiguration {
|
8
|
-
constructor({ baseUrl, headers, retry, throttle, }) {
|
9
|
-
super({ retry, throttle });
|
8
|
+
constructor({ baseUrl, headers, retry, throttle, customCallHeaders, }) {
|
9
|
+
super({ retry, throttle, customCallHeaders });
|
10
10
|
Object.defineProperty(this, "baseUrl", {
|
11
11
|
enumerable: true,
|
12
12
|
configurable: true,
|
13
13
|
writable: true,
|
14
14
|
value: void 0
|
15
15
|
});
|
16
|
-
Object.defineProperty(this, "
|
16
|
+
Object.defineProperty(this, "fixedHeadersValue", {
|
17
17
|
enumerable: true,
|
18
18
|
configurable: true,
|
19
19
|
writable: true,
|
20
20
|
value: void 0
|
21
21
|
});
|
22
22
|
this.baseUrl = typeof baseUrl == "string" ? parseBaseUrl(baseUrl) : baseUrl;
|
23
|
-
this.
|
23
|
+
this.fixedHeadersValue = headers ?? {};
|
24
|
+
}
|
25
|
+
fixedHeaders() {
|
26
|
+
return this.fixedHeadersValue;
|
24
27
|
}
|
25
28
|
assembleUrl(path) {
|
26
29
|
let basePath = this.baseUrl.path;
|
@@ -36,12 +39,13 @@ export class BaseUrlApiConfiguration extends AbstractApiConfiguration {
|
|
36
39
|
}
|
37
40
|
}
|
38
41
|
export class BaseUrlApiConfigurationWithDefaults extends BaseUrlApiConfiguration {
|
39
|
-
constructor({ baseUrlDefaults, baseUrl, headers, retry, throttle, }) {
|
42
|
+
constructor({ baseUrlDefaults, baseUrl, headers, retry, throttle, customCallHeaders, }) {
|
40
43
|
super({
|
41
44
|
baseUrl: resolveBaseUrl(baseUrl, baseUrlDefaults),
|
42
45
|
headers,
|
43
46
|
retry,
|
44
47
|
throttle,
|
48
|
+
customCallHeaders,
|
45
49
|
});
|
46
50
|
}
|
47
51
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/core/api/index.cjs
CHANGED
@@ -32,6 +32,7 @@ __exportStar(require("./ApiCallError.cjs"), exports);
|
|
32
32
|
__exportStar(require("./ApiConfiguration.cjs"), exports);
|
33
33
|
exports.api = __importStar(require("./ApiFacade.cjs"));
|
34
34
|
__exportStar(require("./BaseUrlApiConfiguration.cjs"), exports);
|
35
|
+
__exportStar(require("./CustomHeaderProvider.cjs"), exports);
|
35
36
|
__exportStar(require("./RetryError.cjs"), exports);
|
36
37
|
__exportStar(require("./RetryFunction.cjs"), exports);
|
37
38
|
__exportStar(require("./ThrottleFunction.cjs"), exports);
|
package/core/api/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ export * from "./ApiCallError.js";
|
|
3
3
|
export * from "./ApiConfiguration.js";
|
4
4
|
export * as api from "./ApiFacade.js";
|
5
5
|
export * from "./BaseUrlApiConfiguration.js";
|
6
|
+
export * from "./CustomHeaderProvider.js";
|
6
7
|
export * from "./RetryError.js";
|
7
8
|
export * from "./RetryFunction.js";
|
8
9
|
export * from "./ThrottleFunction.js";
|
package/core/api/index.js
CHANGED
@@ -3,6 +3,7 @@ export * from "./ApiCallError.js";
|
|
3
3
|
export * from "./ApiConfiguration.js";
|
4
4
|
export * as api from "./ApiFacade.js";
|
5
5
|
export * from "./BaseUrlApiConfiguration.js";
|
6
|
+
export * from "./CustomHeaderProvider.js";
|
6
7
|
export * from "./RetryError.js";
|
7
8
|
export * from "./RetryFunction.js";
|
8
9
|
export * from "./ThrottleFunction.js";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export interface Cache {
|
2
|
+
lookupValue(key: {
|
3
|
+
functionType: string;
|
4
|
+
functionId?: string | undefined;
|
5
|
+
input: unknown;
|
6
|
+
}): Promise<object | null>;
|
7
|
+
storeValue(key: {
|
8
|
+
functionType: string;
|
9
|
+
functionId?: string | undefined;
|
10
|
+
input: unknown;
|
11
|
+
}, value: unknown): Promise<void>;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.MemoryCache = void 0;
|
4
|
+
class MemoryCache {
|
5
|
+
constructor() {
|
6
|
+
Object.defineProperty(this, "cache", {
|
7
|
+
enumerable: true,
|
8
|
+
configurable: true,
|
9
|
+
writable: true,
|
10
|
+
value: new Map()
|
11
|
+
});
|
12
|
+
}
|
13
|
+
hashKey(key) {
|
14
|
+
return JSON.stringify(key);
|
15
|
+
}
|
16
|
+
async lookupValue(key) {
|
17
|
+
return this.cache.get(this.hashKey(key)) ?? null;
|
18
|
+
}
|
19
|
+
async storeValue(key, value) {
|
20
|
+
this.cache.set(this.hashKey(key), value);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.MemoryCache = MemoryCache;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Cache } from "./Cache.js";
|
2
|
+
export declare class MemoryCache implements Cache {
|
3
|
+
private readonly cache;
|
4
|
+
private hashKey;
|
5
|
+
lookupValue(key: {
|
6
|
+
functionType: string;
|
7
|
+
functionId?: string | undefined;
|
8
|
+
input: unknown;
|
9
|
+
}): Promise<object | null>;
|
10
|
+
storeValue(key: {
|
11
|
+
functionType: string;
|
12
|
+
functionId?: string | undefined;
|
13
|
+
input: unknown;
|
14
|
+
}, value: unknown): Promise<void>;
|
15
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export class MemoryCache {
|
2
|
+
constructor() {
|
3
|
+
Object.defineProperty(this, "cache", {
|
4
|
+
enumerable: true,
|
5
|
+
configurable: true,
|
6
|
+
writable: true,
|
7
|
+
value: new Map()
|
8
|
+
});
|
9
|
+
}
|
10
|
+
hashKey(key) {
|
11
|
+
return JSON.stringify(key);
|
12
|
+
}
|
13
|
+
async lookupValue(key) {
|
14
|
+
return this.cache.get(this.hashKey(key)) ?? null;
|
15
|
+
}
|
16
|
+
async storeValue(key, value) {
|
17
|
+
this.cache.set(this.hashKey(key), value);
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,18 @@
|
|
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("./Cache.cjs"), exports);
|
18
|
+
__exportStar(require("./MemoryCache.cjs"), exports);
|
package/core/index.cjs
CHANGED
@@ -38,6 +38,7 @@ exports.modelfusion = __importStar(require("./ModelFusionConfiguration.cjs"));
|
|
38
38
|
__exportStar(require("./Run.cjs"), exports);
|
39
39
|
__exportStar(require("./Vector.cjs"), exports);
|
40
40
|
__exportStar(require("./api/index.cjs"), exports);
|
41
|
+
__exportStar(require("./cache/index.cjs"), exports);
|
41
42
|
__exportStar(require("./executeFunction.cjs"), exports);
|
42
43
|
__exportStar(require("./getRun.cjs"), exports);
|
43
44
|
__exportStar(require("./schema/index.cjs"), exports);
|
package/core/index.d.ts
CHANGED
@@ -9,6 +9,7 @@ export * as modelfusion from "./ModelFusionConfiguration.js";
|
|
9
9
|
export * from "./Run.js";
|
10
10
|
export * from "./Vector.js";
|
11
11
|
export * from "./api/index.js";
|
12
|
+
export * from "./cache/index.js";
|
12
13
|
export * from "./executeFunction.js";
|
13
14
|
export * from "./getRun.js";
|
14
15
|
export * from "./schema/index.js";
|
package/core/index.js
CHANGED
@@ -9,6 +9,7 @@ export * as modelfusion from "./ModelFusionConfiguration.js";
|
|
9
9
|
export * from "./Run.js";
|
10
10
|
export * from "./Vector.js";
|
11
11
|
export * from "./api/index.js";
|
12
|
+
export * from "./cache/index.js";
|
12
13
|
export * from "./executeFunction.js";
|
13
14
|
export * from "./getRun.js";
|
14
15
|
export * from "./schema/index.js";
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TypeValidationError = void 0;
|
4
|
+
const getErrorMessage_js_1 = require("../../util/getErrorMessage.cjs");
|
5
|
+
class TypeValidationError extends Error {
|
6
|
+
constructor({ structure, cause }) {
|
7
|
+
super(`Type validation failed: ` +
|
8
|
+
`Structure: ${JSON.stringify(structure)}.\n` +
|
9
|
+
`Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
|
10
|
+
Object.defineProperty(this, "structure", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: void 0
|
15
|
+
});
|
16
|
+
Object.defineProperty(this, "cause", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: void 0
|
21
|
+
});
|
22
|
+
this.name = "TypeValidationError";
|
23
|
+
this.cause = cause;
|
24
|
+
this.structure = structure;
|
25
|
+
}
|
26
|
+
toJSON() {
|
27
|
+
return {
|
28
|
+
name: this.name,
|
29
|
+
message: this.message,
|
30
|
+
cause: this.cause,
|
31
|
+
stack: this.stack,
|
32
|
+
object: this.structure,
|
33
|
+
};
|
34
|
+
}
|
35
|
+
}
|
36
|
+
exports.TypeValidationError = TypeValidationError;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export declare class TypeValidationError extends Error {
|
2
|
+
readonly structure: unknown;
|
3
|
+
readonly cause: unknown;
|
4
|
+
constructor({ structure, cause }: {
|
5
|
+
structure: unknown;
|
6
|
+
cause: unknown;
|
7
|
+
});
|
8
|
+
toJSON(): {
|
9
|
+
name: string;
|
10
|
+
message: string;
|
11
|
+
cause: unknown;
|
12
|
+
stack: string | undefined;
|
13
|
+
object: unknown;
|
14
|
+
};
|
15
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { getErrorMessage } from "../../util/getErrorMessage.js";
|
2
|
+
export class TypeValidationError extends Error {
|
3
|
+
constructor({ structure, cause }) {
|
4
|
+
super(`Type validation failed: ` +
|
5
|
+
`Structure: ${JSON.stringify(structure)}.\n` +
|
6
|
+
`Error message: ${getErrorMessage(cause)}`);
|
7
|
+
Object.defineProperty(this, "structure", {
|
8
|
+
enumerable: true,
|
9
|
+
configurable: true,
|
10
|
+
writable: true,
|
11
|
+
value: void 0
|
12
|
+
});
|
13
|
+
Object.defineProperty(this, "cause", {
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true,
|
17
|
+
value: void 0
|
18
|
+
});
|
19
|
+
this.name = "TypeValidationError";
|
20
|
+
this.cause = cause;
|
21
|
+
this.structure = structure;
|
22
|
+
}
|
23
|
+
toJSON() {
|
24
|
+
return {
|
25
|
+
name: this.name,
|
26
|
+
message: this.message,
|
27
|
+
cause: this.cause,
|
28
|
+
stack: this.stack,
|
29
|
+
object: this.structure,
|
30
|
+
};
|
31
|
+
}
|
32
|
+
}
|
package/core/schema/index.cjs
CHANGED
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./JSONParseError.cjs"), exports);
|
18
18
|
__exportStar(require("./JsonSchemaProducer.cjs"), exports);
|
19
19
|
__exportStar(require("./Schema.cjs"), exports);
|
20
|
+
__exportStar(require("./TypeValidationError.cjs"), exports);
|
20
21
|
__exportStar(require("./UncheckedSchema.cjs"), exports);
|
21
22
|
__exportStar(require("./ZodSchema.cjs"), exports);
|
22
23
|
__exportStar(require("./parseJSON.cjs"), exports);
|
24
|
+
__exportStar(require("./validateTypes.cjs"), exports);
|
package/core/schema/index.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export * from "./JSONParseError.js";
|
2
2
|
export * from "./JsonSchemaProducer.js";
|
3
3
|
export * from "./Schema.js";
|
4
|
+
export * from "./TypeValidationError.js";
|
4
5
|
export * from "./UncheckedSchema.js";
|
5
6
|
export * from "./ZodSchema.js";
|
6
7
|
export * from "./parseJSON.js";
|
8
|
+
export * from "./validateTypes.js";
|
package/core/schema/index.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
export * from "./JSONParseError.js";
|
2
2
|
export * from "./JsonSchemaProducer.js";
|
3
3
|
export * from "./Schema.js";
|
4
|
+
export * from "./TypeValidationError.js";
|
4
5
|
export * from "./UncheckedSchema.js";
|
5
6
|
export * from "./ZodSchema.js";
|
6
7
|
export * from "./parseJSON.js";
|
8
|
+
export * from "./validateTypes.js";
|
@@ -6,20 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.safeParseJSON = exports.parseJSON = void 0;
|
7
7
|
const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
|
8
8
|
const JSONParseError_js_1 = require("./JSONParseError.cjs");
|
9
|
+
const validateTypes_js_1 = require("./validateTypes.cjs");
|
10
|
+
const TypeValidationError_js_1 = require("./TypeValidationError.cjs");
|
9
11
|
function parseJSON({ text, schema, }) {
|
10
12
|
try {
|
11
13
|
const json = secure_json_parse_1.default.parse(text);
|
12
14
|
if (schema == null) {
|
13
15
|
return json;
|
14
16
|
}
|
15
|
-
|
16
|
-
if (!validationResult.success) {
|
17
|
-
throw new JSONParseError_js_1.JSONParseError({ text, cause: validationResult.error });
|
18
|
-
}
|
19
|
-
return validationResult.data;
|
17
|
+
return (0, validateTypes_js_1.validateTypes)({ structure: json, schema });
|
20
18
|
}
|
21
19
|
catch (error) {
|
22
|
-
if (error instanceof JSONParseError_js_1.JSONParseError
|
20
|
+
if (error instanceof JSONParseError_js_1.JSONParseError ||
|
21
|
+
error instanceof TypeValidationError_js_1.TypeValidationError) {
|
23
22
|
throw error;
|
24
23
|
}
|
25
24
|
throw new JSONParseError_js_1.JSONParseError({ text, cause: error });
|
@@ -35,14 +34,7 @@ function safeParseJSON({ text, schema, }) {
|
|
35
34
|
data: json,
|
36
35
|
};
|
37
36
|
}
|
38
|
-
|
39
|
-
if (validationResult.success) {
|
40
|
-
return validationResult;
|
41
|
-
}
|
42
|
-
return {
|
43
|
-
success: false,
|
44
|
-
error: new JSONParseError_js_1.JSONParseError({ text, cause: validationResult.error }),
|
45
|
-
};
|
37
|
+
return (0, validateTypes_js_1.safeValidateTypes)({ structure: json, schema });
|
46
38
|
}
|
47
39
|
catch (error) {
|
48
40
|
return {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { JSONParseError } from "./JSONParseError.js";
|
2
2
|
import { Schema } from "./Schema.js";
|
3
|
+
import { TypeValidationError } from "./TypeValidationError.js";
|
3
4
|
/**
|
4
5
|
* Parses a JSON string into an unknown object.
|
5
6
|
*
|
@@ -34,7 +35,7 @@ export declare function safeParseJSON({ text, }: {
|
|
34
35
|
data: unknown;
|
35
36
|
} | {
|
36
37
|
success: false;
|
37
|
-
error: JSONParseError;
|
38
|
+
error: JSONParseError | TypeValidationError;
|
38
39
|
};
|
39
40
|
/**
|
40
41
|
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the structure.
|
@@ -52,5 +53,5 @@ export declare function safeParseJSON<T>({ text, schema, }: {
|
|
52
53
|
data: T;
|
53
54
|
} | {
|
54
55
|
success: false;
|
55
|
-
error: JSONParseError;
|
56
|
+
error: JSONParseError | TypeValidationError;
|
56
57
|
};
|
package/core/schema/parseJSON.js
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
import SecureJSON from "secure-json-parse";
|
2
2
|
import { JSONParseError } from "./JSONParseError.js";
|
3
|
+
import { safeValidateTypes, validateTypes } from "./validateTypes.js";
|
4
|
+
import { TypeValidationError } from "./TypeValidationError.js";
|
3
5
|
export function parseJSON({ text, schema, }) {
|
4
6
|
try {
|
5
7
|
const json = SecureJSON.parse(text);
|
6
8
|
if (schema == null) {
|
7
9
|
return json;
|
8
10
|
}
|
9
|
-
|
10
|
-
if (!validationResult.success) {
|
11
|
-
throw new JSONParseError({ text, cause: validationResult.error });
|
12
|
-
}
|
13
|
-
return validationResult.data;
|
11
|
+
return validateTypes({ structure: json, schema });
|
14
12
|
}
|
15
13
|
catch (error) {
|
16
|
-
if (error instanceof JSONParseError
|
14
|
+
if (error instanceof JSONParseError ||
|
15
|
+
error instanceof TypeValidationError) {
|
17
16
|
throw error;
|
18
17
|
}
|
19
18
|
throw new JSONParseError({ text, cause: error });
|
@@ -28,14 +27,7 @@ export function safeParseJSON({ text, schema, }) {
|
|
28
27
|
data: json,
|
29
28
|
};
|
30
29
|
}
|
31
|
-
|
32
|
-
if (validationResult.success) {
|
33
|
-
return validationResult;
|
34
|
-
}
|
35
|
-
return {
|
36
|
-
success: false,
|
37
|
-
error: new JSONParseError({ text, cause: validationResult.error }),
|
38
|
-
};
|
30
|
+
return safeValidateTypes({ structure: json, schema });
|
39
31
|
}
|
40
32
|
catch (error) {
|
41
33
|
return {
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.safeValidateTypes = exports.validateTypes = void 0;
|
4
|
+
const TypeValidationError_js_1 = require("./TypeValidationError.cjs");
|
5
|
+
/**
|
6
|
+
* Validates the types of an unknown object using a schema and
|
7
|
+
* return a strongly-typed object.
|
8
|
+
*
|
9
|
+
* @template T - The type of the object to validate.
|
10
|
+
* @param {string} structure - The JSON structure to validate.
|
11
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
12
|
+
* @returns {T} - The typed object.
|
13
|
+
*/
|
14
|
+
function validateTypes({ structure, schema, }) {
|
15
|
+
try {
|
16
|
+
const validationResult = schema.validate(structure);
|
17
|
+
if (!validationResult.success) {
|
18
|
+
throw new TypeValidationError_js_1.TypeValidationError({
|
19
|
+
structure,
|
20
|
+
cause: validationResult.error,
|
21
|
+
});
|
22
|
+
}
|
23
|
+
return validationResult.data;
|
24
|
+
}
|
25
|
+
catch (error) {
|
26
|
+
if (error instanceof TypeValidationError_js_1.TypeValidationError) {
|
27
|
+
throw error;
|
28
|
+
}
|
29
|
+
throw new TypeValidationError_js_1.TypeValidationError({ structure: structure, cause: error });
|
30
|
+
}
|
31
|
+
}
|
32
|
+
exports.validateTypes = validateTypes;
|
33
|
+
/**
|
34
|
+
* Safely validates the types of an unknown object using a schema and
|
35
|
+
* return a strongly-typed object.
|
36
|
+
*
|
37
|
+
* @template T - The type of the object to validate.
|
38
|
+
* @param {string} structure - The JSON object to validate.
|
39
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
40
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
41
|
+
*/
|
42
|
+
function safeValidateTypes({ structure, schema, }) {
|
43
|
+
try {
|
44
|
+
const validationResult = schema.validate(structure);
|
45
|
+
if (validationResult.success) {
|
46
|
+
return validationResult;
|
47
|
+
}
|
48
|
+
return {
|
49
|
+
success: false,
|
50
|
+
error: new TypeValidationError_js_1.TypeValidationError({
|
51
|
+
structure: structure,
|
52
|
+
cause: validationResult.error,
|
53
|
+
}),
|
54
|
+
};
|
55
|
+
}
|
56
|
+
catch (error) {
|
57
|
+
return {
|
58
|
+
success: false,
|
59
|
+
error: error instanceof TypeValidationError_js_1.TypeValidationError
|
60
|
+
? error
|
61
|
+
: new TypeValidationError_js_1.TypeValidationError({ structure: structure, cause: error }),
|
62
|
+
};
|
63
|
+
}
|
64
|
+
}
|
65
|
+
exports.safeValidateTypes = safeValidateTypes;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { Schema } from "./Schema.js";
|
2
|
+
import { TypeValidationError } from "./TypeValidationError.js";
|
3
|
+
/**
|
4
|
+
* Validates the types of an unknown object using a schema and
|
5
|
+
* return a strongly-typed object.
|
6
|
+
*
|
7
|
+
* @template T - The type of the object to validate.
|
8
|
+
* @param {string} structure - The JSON structure to validate.
|
9
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
10
|
+
* @returns {T} - The typed object.
|
11
|
+
*/
|
12
|
+
export declare function validateTypes<T>({ structure, schema, }: {
|
13
|
+
structure: unknown;
|
14
|
+
schema: Schema<T>;
|
15
|
+
}): T;
|
16
|
+
/**
|
17
|
+
* Safely validates the types of an unknown object using a schema and
|
18
|
+
* return a strongly-typed object.
|
19
|
+
*
|
20
|
+
* @template T - The type of the object to validate.
|
21
|
+
* @param {string} structure - The JSON object to validate.
|
22
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
23
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
24
|
+
*/
|
25
|
+
export declare function safeValidateTypes<T>({ structure, schema, }: {
|
26
|
+
structure: unknown;
|
27
|
+
schema: Schema<T>;
|
28
|
+
}): {
|
29
|
+
success: true;
|
30
|
+
data: T;
|
31
|
+
} | {
|
32
|
+
success: false;
|
33
|
+
error: TypeValidationError;
|
34
|
+
};
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { TypeValidationError } from "./TypeValidationError.js";
|
2
|
+
/**
|
3
|
+
* Validates the types of an unknown object using a schema and
|
4
|
+
* return a strongly-typed object.
|
5
|
+
*
|
6
|
+
* @template T - The type of the object to validate.
|
7
|
+
* @param {string} structure - The JSON structure to validate.
|
8
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
9
|
+
* @returns {T} - The typed object.
|
10
|
+
*/
|
11
|
+
export function validateTypes({ structure, schema, }) {
|
12
|
+
try {
|
13
|
+
const validationResult = schema.validate(structure);
|
14
|
+
if (!validationResult.success) {
|
15
|
+
throw new TypeValidationError({
|
16
|
+
structure,
|
17
|
+
cause: validationResult.error,
|
18
|
+
});
|
19
|
+
}
|
20
|
+
return validationResult.data;
|
21
|
+
}
|
22
|
+
catch (error) {
|
23
|
+
if (error instanceof TypeValidationError) {
|
24
|
+
throw error;
|
25
|
+
}
|
26
|
+
throw new TypeValidationError({ structure: structure, cause: error });
|
27
|
+
}
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Safely validates the types of an unknown object using a schema and
|
31
|
+
* return a strongly-typed object.
|
32
|
+
*
|
33
|
+
* @template T - The type of the object to validate.
|
34
|
+
* @param {string} structure - The JSON object to validate.
|
35
|
+
* @param {Schema<T>} schema - The schema to use for validating the JSON.
|
36
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
37
|
+
*/
|
38
|
+
export function safeValidateTypes({ structure, schema, }) {
|
39
|
+
try {
|
40
|
+
const validationResult = schema.validate(structure);
|
41
|
+
if (validationResult.success) {
|
42
|
+
return validationResult;
|
43
|
+
}
|
44
|
+
return {
|
45
|
+
success: false,
|
46
|
+
error: new TypeValidationError({
|
47
|
+
structure: structure,
|
48
|
+
cause: validationResult.error,
|
49
|
+
}),
|
50
|
+
};
|
51
|
+
}
|
52
|
+
catch (error) {
|
53
|
+
return {
|
54
|
+
success: false,
|
55
|
+
error: error instanceof TypeValidationError
|
56
|
+
? error
|
57
|
+
: new TypeValidationError({ structure: structure, cause: error }),
|
58
|
+
};
|
59
|
+
}
|
60
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { Vector } from "../../core/Vector.js";
|
3
3
|
import { Model, ModelSettings } from "../Model.js";
|
4
4
|
export interface EmbeddingModelSettings extends ModelSettings {
|
@@ -16,7 +16,7 @@ export interface EmbeddingModel<VALUE, SETTINGS extends EmbeddingModelSettings =
|
|
16
16
|
* True if the model can handle multiple embedding calls in parallel.
|
17
17
|
*/
|
18
18
|
readonly isParallelizable: boolean;
|
19
|
-
doEmbedValues(values: VALUE[], options
|
19
|
+
doEmbedValues(values: VALUE[], options: FunctionCallOptions): PromiseLike<{
|
20
20
|
response: unknown;
|
21
21
|
embeddings: Vector[];
|
22
22
|
}>;
|