modelfusion 0.113.0 → 0.114.1
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 +65 -0
- package/README.md +89 -89
- 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/generateStructure.cjs +4 -1
- package/model-function/generate-structure/generateStructure.js +4 -1
- 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 +12 -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 +20 -8
- package/model-provider/ollama/OllamaChatModel.d.ts +27 -5
- package/model-provider/ollama/OllamaChatModel.js +20 -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 +25 -15
- package/model-provider/openai/AbstractOpenAIChatModel.d.ts +108 -21
- package/model-provider/openai/AbstractOpenAIChatModel.js +25 -15
- 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 +91 -7
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.js +12 -6
- 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/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 +1 -1
@@ -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
|
}>;
|
@@ -43,11 +43,13 @@ async function executeStandardCall({ model, options, input, functionType, genera
|
|
43
43
|
...startMetadata,
|
44
44
|
});
|
45
45
|
const result = await (0, runSafe_js_1.runSafe)(() => generateResponse({
|
46
|
+
functionType: startMetadata.functionType,
|
46
47
|
functionId: options?.functionId,
|
48
|
+
callId: startMetadata.callId,
|
47
49
|
logging: options?.logging,
|
48
50
|
observers: options?.observers,
|
51
|
+
cache: options?.cache,
|
49
52
|
run,
|
50
|
-
parentCallId: startMetadata.callId,
|
51
53
|
}));
|
52
54
|
const finishMetadata = {
|
53
55
|
eventType: "finished",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { FunctionOptions } from "../core/FunctionOptions.js";
|
1
|
+
import { FunctionCallOptions, FunctionOptions } from "../core/FunctionOptions.js";
|
2
2
|
import { Model, ModelSettings } from "./Model.js";
|
3
3
|
import { ModelCallStartedEvent } from "./ModelCallEvent.js";
|
4
4
|
import { ModelCallMetadata } from "./ModelCallMetadata.js";
|
@@ -7,7 +7,7 @@ export declare function executeStandardCall<VALUE, MODEL extends Model<ModelSett
|
|
7
7
|
options?: FunctionOptions;
|
8
8
|
input: unknown;
|
9
9
|
functionType: ModelCallStartedEvent["functionType"];
|
10
|
-
generateResponse: (options
|
10
|
+
generateResponse: (options: FunctionCallOptions) => PromiseLike<{
|
11
11
|
response: unknown;
|
12
12
|
extractedValue: VALUE;
|
13
13
|
usage?: unknown;
|
@@ -40,11 +40,13 @@ export async function executeStandardCall({ model, options, input, functionType,
|
|
40
40
|
...startMetadata,
|
41
41
|
});
|
42
42
|
const result = await runSafe(() => generateResponse({
|
43
|
+
functionType: startMetadata.functionType,
|
43
44
|
functionId: options?.functionId,
|
45
|
+
callId: startMetadata.callId,
|
44
46
|
logging: options?.logging,
|
45
47
|
observers: options?.observers,
|
48
|
+
cache: options?.cache,
|
46
49
|
run,
|
47
|
-
parentCallId: startMetadata.callId,
|
48
50
|
}));
|
49
51
|
const finishMetadata = {
|
50
52
|
eventType: "finished",
|
@@ -45,11 +45,12 @@ async function executeStreamCall({ model, options, input, functionType, startStr
|
|
45
45
|
});
|
46
46
|
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
47
47
|
const deltaIterable = await startStream({
|
48
|
+
functionType: startMetadata.functionType,
|
48
49
|
functionId: options?.functionId,
|
50
|
+
callId: startMetadata.callId,
|
49
51
|
logging: options?.logging,
|
50
52
|
observers: options?.observers,
|
51
53
|
run,
|
52
|
-
parentCallId: startMetadata.callId,
|
53
54
|
});
|
54
55
|
// Return a queue that can be iterated over several times:
|
55
56
|
const responseQueue = new AsyncQueue_js_1.AsyncQueue();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { FunctionOptions } from "../core/FunctionOptions.js";
|
1
|
+
import { FunctionCallOptions, FunctionOptions } from "../core/FunctionOptions.js";
|
2
2
|
import { Delta } from "./Delta.js";
|
3
3
|
import { Model, ModelSettings } from "./Model.js";
|
4
4
|
import { ModelCallStartedEvent } from "./ModelCallEvent.js";
|
@@ -8,7 +8,7 @@ export declare function executeStreamCall<DELTA_VALUE, VALUE, MODEL extends Mode
|
|
8
8
|
options?: FunctionOptions;
|
9
9
|
input: unknown;
|
10
10
|
functionType: ModelCallStartedEvent["functionType"];
|
11
|
-
startStream: (options
|
11
|
+
startStream: (options: FunctionCallOptions) => PromiseLike<AsyncIterable<Delta<DELTA_VALUE>>>;
|
12
12
|
processDelta: (delta: Delta<DELTA_VALUE> & {
|
13
13
|
type: "delta";
|
14
14
|
}) => VALUE | undefined;
|
@@ -42,11 +42,12 @@ export async function executeStreamCall({ model, options, input, functionType, s
|
|
42
42
|
});
|
43
43
|
const result = await runSafe(async () => {
|
44
44
|
const deltaIterable = await startStream({
|
45
|
+
functionType: startMetadata.functionType,
|
45
46
|
functionId: options?.functionId,
|
47
|
+
callId: startMetadata.callId,
|
46
48
|
logging: options?.logging,
|
47
49
|
observers: options?.observers,
|
48
50
|
run,
|
49
|
-
parentCallId: startMetadata.callId,
|
50
51
|
});
|
51
52
|
// Return a queue that can be iterated over several times:
|
52
53
|
const responseQueue = new AsyncQueue();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { Model, ModelSettings } from "../Model.js";
|
3
3
|
import { PromptTemplate } from "../PromptTemplate.js";
|
4
4
|
export interface ImageGenerationModelSettings extends ModelSettings {
|
@@ -14,7 +14,7 @@ export interface ImageGenerationModelSettings extends ModelSettings {
|
|
14
14
|
numberOfGenerations?: number;
|
15
15
|
}
|
16
16
|
export interface ImageGenerationModel<PROMPT, SETTINGS extends ImageGenerationModelSettings = ImageGenerationModelSettings> extends Model<SETTINGS> {
|
17
|
-
doGenerateImages(prompt: PROMPT, options
|
17
|
+
doGenerateImages(prompt: PROMPT, options: FunctionCallOptions): PromiseLike<{
|
18
18
|
response: unknown;
|
19
19
|
base64Images: string[];
|
20
20
|
}>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { PromptTemplate } from "../PromptTemplate.js";
|
3
3
|
import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGenerationModel.js";
|
4
4
|
export declare class PromptTemplateImageGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS extends ImageGenerationModelSettings, MODEL extends ImageGenerationModel<MODEL_PROMPT, SETTINGS>> implements ImageGenerationModel<PROMPT, SETTINGS> {
|
@@ -10,7 +10,7 @@ export declare class PromptTemplateImageGenerationModel<PROMPT, MODEL_PROMPT, SE
|
|
10
10
|
});
|
11
11
|
get modelInformation(): import("../ModelInformation.js").ModelInformation;
|
12
12
|
get settings(): SETTINGS;
|
13
|
-
doGenerateImages(prompt: PROMPT, options
|
13
|
+
doGenerateImages(prompt: PROMPT, options: FunctionCallOptions): PromiseLike<{
|
14
14
|
response: unknown;
|
15
15
|
base64Images: string[];
|
16
16
|
}>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import {
|
2
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
3
3
|
import { Delta } from "../Delta.js";
|
4
4
|
import { Model, ModelSettings } from "../Model.js";
|
5
5
|
export interface SpeechGenerationModelSettings extends ModelSettings {
|
@@ -8,8 +8,8 @@ export interface SpeechGenerationModel<SETTINGS extends SpeechGenerationModelSet
|
|
8
8
|
/**
|
9
9
|
* Generates an mp3 audio buffer that contains the speech for the given text.
|
10
10
|
*/
|
11
|
-
doGenerateSpeechStandard(text: string, options
|
11
|
+
doGenerateSpeechStandard(text: string, options: FunctionCallOptions): PromiseLike<Buffer>;
|
12
12
|
}
|
13
13
|
export interface StreamingSpeechGenerationModel<SETTINGS extends SpeechGenerationModelSettings = SpeechGenerationModelSettings> extends SpeechGenerationModel<SETTINGS> {
|
14
|
-
doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>, options
|
14
|
+
doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>, options: FunctionCallOptions): PromiseLike<AsyncIterable<Delta<Buffer>>>;
|
15
15
|
}
|
@@ -10,7 +10,10 @@ async function generateStructure(model, schema, prompt, options) {
|
|
10
10
|
: prompt;
|
11
11
|
const fullResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
12
12
|
functionType: "generate-structure",
|
13
|
-
input:
|
13
|
+
input: {
|
14
|
+
schema,
|
15
|
+
prompt: expandedPrompt,
|
16
|
+
},
|
14
17
|
model,
|
15
18
|
options,
|
16
19
|
generateResponse: async (options) => {
|
@@ -7,7 +7,10 @@ export async function generateStructure(model, schema, prompt, options) {
|
|
7
7
|
: prompt;
|
8
8
|
const fullResponse = await executeStandardCall({
|
9
9
|
functionType: "generate-structure",
|
10
|
-
input:
|
10
|
+
input: {
|
11
|
+
schema,
|
12
|
+
prompt: expandedPrompt,
|
13
|
+
},
|
11
14
|
model,
|
12
15
|
options,
|
13
16
|
generateResponse: async (options) => {
|
@@ -12,7 +12,10 @@ async function streamStructure(model, schema, prompt, options) {
|
|
12
12
|
let lastStructure;
|
13
13
|
const fullResponse = await (0, executeStreamCall_js_1.executeStreamCall)({
|
14
14
|
functionType: "stream-structure",
|
15
|
-
input:
|
15
|
+
input: {
|
16
|
+
schema,
|
17
|
+
prompt: expandedPrompt,
|
18
|
+
},
|
16
19
|
model,
|
17
20
|
options,
|
18
21
|
startStream: async (options) => model.doStreamStructure(schema, expandedPrompt, options),
|
@@ -9,7 +9,10 @@ export async function streamStructure(model, schema, prompt, options) {
|
|
9
9
|
let lastStructure;
|
10
10
|
const fullResponse = await executeStreamCall({
|
11
11
|
functionType: "stream-structure",
|
12
|
-
input:
|
12
|
+
input: {
|
13
|
+
schema,
|
14
|
+
prompt: expandedPrompt,
|
15
|
+
},
|
13
16
|
model,
|
14
17
|
options,
|
15
18
|
startStream: async (options) => model.doStreamStructure(schema, expandedPrompt, options),
|