modelfusion 0.121.2 → 0.123.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 +78 -1
- package/README.md +127 -85
- package/index.cjs +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/model-function/ModelCallEvent.d.ts +6 -2
- package/model-function/classify/Classifier.cjs +2 -0
- package/model-function/classify/Classifier.d.ts +10 -0
- package/model-function/classify/Classifier.js +1 -0
- package/model-function/classify/ClassifyEvent.cjs +2 -0
- package/model-function/classify/ClassifyEvent.d.ts +20 -0
- package/model-function/classify/ClassifyEvent.js +1 -0
- package/model-function/classify/EmbeddingSimilarityClassifier.cjs +97 -0
- package/model-function/classify/EmbeddingSimilarityClassifier.d.ts +40 -0
- package/model-function/classify/EmbeddingSimilarityClassifier.js +93 -0
- package/model-function/classify/classify.cjs +27 -0
- package/model-function/classify/classify.d.ts +17 -0
- package/model-function/classify/classify.js +23 -0
- package/{classifier → model-function/classify}/index.cjs +4 -1
- package/model-function/classify/index.d.ts +4 -0
- package/model-function/classify/index.js +4 -0
- package/model-function/embed/embed.cjs +14 -14
- package/model-function/embed/embed.d.ts +24 -18
- package/model-function/embed/embed.js +14 -14
- package/model-function/generate-image/generateImage.cjs +6 -6
- package/model-function/generate-image/generateImage.d.ts +12 -9
- package/model-function/generate-image/generateImage.js +6 -6
- package/model-function/generate-speech/generateSpeech.cjs +7 -7
- package/model-function/generate-speech/generateSpeech.d.ts +12 -9
- package/model-function/generate-speech/generateSpeech.js +7 -7
- package/model-function/generate-speech/streamSpeech.cjs +6 -6
- package/model-function/generate-speech/streamSpeech.d.ts +12 -8
- package/model-function/generate-speech/streamSpeech.js +6 -6
- package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +5 -3
- package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +1 -1
- package/model-function/generate-structure/StructureFromTextGenerationModel.js +5 -3
- package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +5 -1
- package/model-function/generate-structure/StructureFromTextStreamingModel.js +5 -1
- package/model-function/generate-structure/StructureGenerationModel.d.ts +1 -1
- package/model-function/generate-structure/generateStructure.cjs +8 -8
- package/model-function/generate-structure/generateStructure.d.ts +17 -10
- package/model-function/generate-structure/generateStructure.js +8 -8
- package/model-function/generate-structure/streamStructure.cjs +6 -6
- package/model-function/generate-structure/streamStructure.d.ts +16 -10
- package/model-function/generate-structure/streamStructure.js +6 -6
- package/model-function/generate-text/generateText.cjs +6 -6
- package/model-function/generate-text/generateText.d.ts +12 -9
- package/model-function/generate-text/generateText.js +6 -6
- package/model-function/generate-text/streamText.cjs +6 -6
- package/model-function/generate-text/streamText.d.ts +12 -8
- package/model-function/generate-text/streamText.js +6 -6
- package/model-function/generate-transcription/generateTranscription.cjs +3 -3
- package/model-function/generate-transcription/generateTranscription.d.ts +12 -9
- package/model-function/generate-transcription/generateTranscription.js +3 -3
- package/model-function/index.cjs +1 -0
- package/model-function/index.d.ts +1 -0
- package/model-function/index.js +1 -0
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +12 -12
- package/model-provider/cohere/CohereTextGenerationModel.test.cjs +7 -4
- package/model-provider/cohere/CohereTextGenerationModel.test.js +7 -4
- package/model-provider/llamacpp/LlamaCppCompletionModel.d.ts +10 -10
- package/model-provider/llamacpp/LlamaCppCompletionModel.test.cjs +4 -1
- package/model-provider/llamacpp/LlamaCppCompletionModel.test.js +4 -1
- package/model-provider/mistral/MistralChatModel.test.cjs +15 -8
- package/model-provider/mistral/MistralChatModel.test.js +15 -8
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.d.ts +9 -9
- package/model-provider/ollama/OllamaChatModel.test.cjs +6 -1
- package/model-provider/ollama/OllamaChatModel.test.js +6 -1
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +31 -16
- package/model-provider/ollama/OllamaCompletionModel.test.js +31 -16
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.cjs +4 -4
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.js +4 -4
- package/model-provider/openai/OpenAIChatModel.test.cjs +21 -14
- package/model-provider/openai/OpenAIChatModel.test.js +21 -14
- package/model-provider/openai/OpenAICompletionModel.test.cjs +15 -9
- package/model-provider/openai/OpenAICompletionModel.test.js +15 -9
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- package/package.json +1 -1
- package/tool/execute-tool/executeTool.cjs +5 -5
- package/tool/execute-tool/executeTool.d.ts +8 -4
- package/tool/execute-tool/executeTool.js +5 -5
- package/tool/execute-tool/safeExecuteToolCall.cjs +1 -1
- package/tool/execute-tool/safeExecuteToolCall.js +1 -1
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +4 -2
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +4 -2
- package/tool/generate-tool-call/generateToolCall.cjs +7 -7
- package/tool/generate-tool-call/generateToolCall.d.ts +11 -5
- package/tool/generate-tool-call/generateToolCall.js +7 -7
- package/tool/generate-tool-calls/TextGenerationToolCallsModel.cjs +4 -2
- package/tool/generate-tool-calls/TextGenerationToolCallsModel.js +4 -2
- package/tool/generate-tool-calls/generateToolCalls.cjs +3 -3
- package/tool/generate-tool-calls/generateToolCalls.d.ts +11 -5
- package/tool/generate-tool-calls/generateToolCalls.js +3 -3
- package/tool/use-tool/useTool.cjs +2 -2
- package/tool/use-tool/useTool.d.ts +5 -1
- package/tool/use-tool/useTool.js +2 -2
- package/tool/use-tools/useTools.cjs +8 -2
- package/tool/use-tools/useTools.d.ts +5 -1
- package/tool/use-tools/useTools.js +8 -2
- package/vector-index/VectorIndexRetriever.cjs +5 -1
- package/vector-index/VectorIndexRetriever.js +5 -1
- package/vector-index/upsertIntoVectorIndex.cjs +5 -1
- package/vector-index/upsertIntoVectorIndex.js +5 -1
- package/classifier/SemanticClassifier.cjs +0 -75
- package/classifier/SemanticClassifier.d.ts +0 -25
- package/classifier/SemanticClassifier.js +0 -71
- package/classifier/index.d.ts +0 -1
- package/classifier/index.js +0 -1
@@ -0,0 +1,97 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.EmbeddingSimilarityClassifier = void 0;
|
4
|
+
const cosineSimilarity_js_1 = require("../../util/cosineSimilarity.cjs");
|
5
|
+
const embed_js_1 = require("../embed/embed.cjs");
|
6
|
+
/**
|
7
|
+
* Classifies values based on their distance to the values from a set of clusters.
|
8
|
+
* When the distance is below a certain threshold, the value is classified as belonging to the cluster,
|
9
|
+
* and the cluster name is returned. Otherwise, the value is classified as null.
|
10
|
+
*/
|
11
|
+
class EmbeddingSimilarityClassifier {
|
12
|
+
constructor(settings) {
|
13
|
+
Object.defineProperty(this, "settings", {
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true,
|
17
|
+
value: void 0
|
18
|
+
});
|
19
|
+
Object.defineProperty(this, "modelInformation", {
|
20
|
+
enumerable: true,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: {
|
24
|
+
provider: "modelfusion",
|
25
|
+
modelName: "EmbeddingSimilarityClassifier",
|
26
|
+
}
|
27
|
+
});
|
28
|
+
Object.defineProperty(this, "embeddings", {
|
29
|
+
enumerable: true,
|
30
|
+
configurable: true,
|
31
|
+
writable: true,
|
32
|
+
value: void 0
|
33
|
+
});
|
34
|
+
this.settings = settings;
|
35
|
+
}
|
36
|
+
async getEmbeddings(options) {
|
37
|
+
if (this.embeddings != null) {
|
38
|
+
return this.embeddings;
|
39
|
+
}
|
40
|
+
const embeddings = [];
|
41
|
+
for (const cluster of this.settings.clusters) {
|
42
|
+
const clusterEmbeddings = await (0, embed_js_1.embedMany)({
|
43
|
+
model: this.settings.embeddingModel,
|
44
|
+
values: cluster.values,
|
45
|
+
...options,
|
46
|
+
});
|
47
|
+
for (let i = 0; i < clusterEmbeddings.length; i++) {
|
48
|
+
embeddings.push({
|
49
|
+
embedding: clusterEmbeddings[i],
|
50
|
+
clusterValue: cluster.values[i],
|
51
|
+
clusterName: cluster.name,
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
55
|
+
this.embeddings = embeddings; // lazy caching
|
56
|
+
return embeddings;
|
57
|
+
}
|
58
|
+
async doClassify(value, options) {
|
59
|
+
const valueEmbedding = await (0, embed_js_1.embed)({
|
60
|
+
model: this.settings.embeddingModel,
|
61
|
+
value,
|
62
|
+
...options,
|
63
|
+
});
|
64
|
+
const clusterEmbeddings = await this.getEmbeddings(options);
|
65
|
+
const allMatches = [];
|
66
|
+
for (const embedding of clusterEmbeddings) {
|
67
|
+
const similarity = (0, cosineSimilarity_js_1.cosineSimilarity)(valueEmbedding, embedding.embedding);
|
68
|
+
if (similarity >= this.settings.similarityThreshold) {
|
69
|
+
allMatches.push({
|
70
|
+
similarity,
|
71
|
+
clusterValue: embedding.clusterValue,
|
72
|
+
clusterName: embedding.clusterName,
|
73
|
+
});
|
74
|
+
}
|
75
|
+
}
|
76
|
+
// sort (highest similarity first)
|
77
|
+
allMatches.sort((a, b) => b.similarity - a.similarity);
|
78
|
+
return {
|
79
|
+
class: allMatches.length > 0
|
80
|
+
? allMatches[0].clusterName
|
81
|
+
: null,
|
82
|
+
rawResponse: undefined,
|
83
|
+
};
|
84
|
+
}
|
85
|
+
get settingsForEvent() {
|
86
|
+
const eventSettingProperties = [
|
87
|
+
"clusters",
|
88
|
+
"embeddingModel",
|
89
|
+
"similarityThreshold",
|
90
|
+
];
|
91
|
+
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
92
|
+
}
|
93
|
+
withSettings(additionalSettings) {
|
94
|
+
return new EmbeddingSimilarityClassifier(Object.assign({}, this.settings, additionalSettings));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
exports.EmbeddingSimilarityClassifier = EmbeddingSimilarityClassifier;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
2
|
+
import { Vector } from "../../core/Vector.js";
|
3
|
+
import { EmbeddingModel } from "../embed/EmbeddingModel.js";
|
4
|
+
import { Classifier, ClassifierSettings } from "./Classifier.js";
|
5
|
+
export interface ValueCluster<VALUE, NAME extends string> {
|
6
|
+
name: NAME;
|
7
|
+
values: VALUE[];
|
8
|
+
}
|
9
|
+
export interface EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS extends Array<ValueCluster<VALUE, string>>> extends ClassifierSettings {
|
10
|
+
clusters: CLUSTERS;
|
11
|
+
embeddingModel: EmbeddingModel<VALUE>;
|
12
|
+
similarityThreshold: number;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Classifies values based on their distance to the values from a set of clusters.
|
16
|
+
* When the distance is below a certain threshold, the value is classified as belonging to the cluster,
|
17
|
+
* and the cluster name is returned. Otherwise, the value is classified as null.
|
18
|
+
*/
|
19
|
+
export declare class EmbeddingSimilarityClassifier<VALUE, CLUSTERS extends Array<ValueCluster<VALUE, string>>> implements Classifier<VALUE, ClusterNames<CLUSTERS> | null, EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS>> {
|
20
|
+
readonly settings: EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS>;
|
21
|
+
readonly modelInformation: {
|
22
|
+
provider: string;
|
23
|
+
modelName: string;
|
24
|
+
};
|
25
|
+
private embeddings;
|
26
|
+
constructor(settings: EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS>);
|
27
|
+
getEmbeddings(options: FunctionCallOptions): Promise<{
|
28
|
+
embedding: Vector;
|
29
|
+
clusterValue: VALUE;
|
30
|
+
clusterName: string;
|
31
|
+
}[]>;
|
32
|
+
doClassify(value: VALUE, options: FunctionCallOptions): Promise<{
|
33
|
+
class: ClusterNames<CLUSTERS> | null;
|
34
|
+
rawResponse: undefined;
|
35
|
+
}>;
|
36
|
+
get settingsForEvent(): Partial<EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS>>;
|
37
|
+
withSettings(additionalSettings: Partial<EmbeddingSimilarityClassifierSettings<VALUE, CLUSTERS>>): this;
|
38
|
+
}
|
39
|
+
type ClusterNames<CLUSTERS> = CLUSTERS extends Array<ValueCluster<unknown, infer NAME>> ? NAME : never;
|
40
|
+
export {};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { cosineSimilarity } from "../../util/cosineSimilarity.js";
|
2
|
+
import { embed, embedMany } from "../embed/embed.js";
|
3
|
+
/**
|
4
|
+
* Classifies values based on their distance to the values from a set of clusters.
|
5
|
+
* When the distance is below a certain threshold, the value is classified as belonging to the cluster,
|
6
|
+
* and the cluster name is returned. Otherwise, the value is classified as null.
|
7
|
+
*/
|
8
|
+
export class EmbeddingSimilarityClassifier {
|
9
|
+
constructor(settings) {
|
10
|
+
Object.defineProperty(this, "settings", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: void 0
|
15
|
+
});
|
16
|
+
Object.defineProperty(this, "modelInformation", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: {
|
21
|
+
provider: "modelfusion",
|
22
|
+
modelName: "EmbeddingSimilarityClassifier",
|
23
|
+
}
|
24
|
+
});
|
25
|
+
Object.defineProperty(this, "embeddings", {
|
26
|
+
enumerable: true,
|
27
|
+
configurable: true,
|
28
|
+
writable: true,
|
29
|
+
value: void 0
|
30
|
+
});
|
31
|
+
this.settings = settings;
|
32
|
+
}
|
33
|
+
async getEmbeddings(options) {
|
34
|
+
if (this.embeddings != null) {
|
35
|
+
return this.embeddings;
|
36
|
+
}
|
37
|
+
const embeddings = [];
|
38
|
+
for (const cluster of this.settings.clusters) {
|
39
|
+
const clusterEmbeddings = await embedMany({
|
40
|
+
model: this.settings.embeddingModel,
|
41
|
+
values: cluster.values,
|
42
|
+
...options,
|
43
|
+
});
|
44
|
+
for (let i = 0; i < clusterEmbeddings.length; i++) {
|
45
|
+
embeddings.push({
|
46
|
+
embedding: clusterEmbeddings[i],
|
47
|
+
clusterValue: cluster.values[i],
|
48
|
+
clusterName: cluster.name,
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
52
|
+
this.embeddings = embeddings; // lazy caching
|
53
|
+
return embeddings;
|
54
|
+
}
|
55
|
+
async doClassify(value, options) {
|
56
|
+
const valueEmbedding = await embed({
|
57
|
+
model: this.settings.embeddingModel,
|
58
|
+
value,
|
59
|
+
...options,
|
60
|
+
});
|
61
|
+
const clusterEmbeddings = await this.getEmbeddings(options);
|
62
|
+
const allMatches = [];
|
63
|
+
for (const embedding of clusterEmbeddings) {
|
64
|
+
const similarity = cosineSimilarity(valueEmbedding, embedding.embedding);
|
65
|
+
if (similarity >= this.settings.similarityThreshold) {
|
66
|
+
allMatches.push({
|
67
|
+
similarity,
|
68
|
+
clusterValue: embedding.clusterValue,
|
69
|
+
clusterName: embedding.clusterName,
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
// sort (highest similarity first)
|
74
|
+
allMatches.sort((a, b) => b.similarity - a.similarity);
|
75
|
+
return {
|
76
|
+
class: allMatches.length > 0
|
77
|
+
? allMatches[0].clusterName
|
78
|
+
: null,
|
79
|
+
rawResponse: undefined,
|
80
|
+
};
|
81
|
+
}
|
82
|
+
get settingsForEvent() {
|
83
|
+
const eventSettingProperties = [
|
84
|
+
"clusters",
|
85
|
+
"embeddingModel",
|
86
|
+
"similarityThreshold",
|
87
|
+
];
|
88
|
+
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
89
|
+
}
|
90
|
+
withSettings(additionalSettings) {
|
91
|
+
return new EmbeddingSimilarityClassifier(Object.assign({}, this.settings, additionalSettings));
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.classify = void 0;
|
4
|
+
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
|
+
async function classify({ model, value, fullResponse, ...options }) {
|
6
|
+
const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
7
|
+
functionType: "classify",
|
8
|
+
input: value,
|
9
|
+
model,
|
10
|
+
options,
|
11
|
+
generateResponse: async (options) => {
|
12
|
+
const result = await model.doClassify(value, options);
|
13
|
+
return {
|
14
|
+
rawResponse: result.rawResponse,
|
15
|
+
extractedValue: result.class,
|
16
|
+
};
|
17
|
+
},
|
18
|
+
});
|
19
|
+
return fullResponse
|
20
|
+
? {
|
21
|
+
class: callResponse.value,
|
22
|
+
rawResponse: callResponse.rawResponse,
|
23
|
+
metadata: callResponse.metadata,
|
24
|
+
}
|
25
|
+
: callResponse.value;
|
26
|
+
}
|
27
|
+
exports.classify = classify;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
|
+
import { ModelCallMetadata } from "../ModelCallMetadata.js";
|
3
|
+
import { Classifier, ClassifierSettings } from "./Classifier.js";
|
4
|
+
export declare function classify<VALUE, CLASS extends string | null>(args: {
|
5
|
+
model: Classifier<VALUE, CLASS, ClassifierSettings>;
|
6
|
+
value: VALUE;
|
7
|
+
fullResponse?: false;
|
8
|
+
} & FunctionOptions): Promise<CLASS>;
|
9
|
+
export declare function classify<VALUE, CLASS extends string | null>(args: {
|
10
|
+
model: Classifier<VALUE, CLASS, ClassifierSettings>;
|
11
|
+
value: VALUE;
|
12
|
+
fullResponse: true;
|
13
|
+
} & FunctionOptions): Promise<{
|
14
|
+
class: CLASS;
|
15
|
+
rawResponse: unknown;
|
16
|
+
metadata: ModelCallMetadata;
|
17
|
+
}>;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { executeStandardCall } from "../executeStandardCall.js";
|
2
|
+
export async function classify({ model, value, fullResponse, ...options }) {
|
3
|
+
const callResponse = await executeStandardCall({
|
4
|
+
functionType: "classify",
|
5
|
+
input: value,
|
6
|
+
model,
|
7
|
+
options,
|
8
|
+
generateResponse: async (options) => {
|
9
|
+
const result = await model.doClassify(value, options);
|
10
|
+
return {
|
11
|
+
rawResponse: result.rawResponse,
|
12
|
+
extractedValue: result.class,
|
13
|
+
};
|
14
|
+
},
|
15
|
+
});
|
16
|
+
return fullResponse
|
17
|
+
? {
|
18
|
+
class: callResponse.value,
|
19
|
+
rawResponse: callResponse.rawResponse,
|
20
|
+
metadata: callResponse.metadata,
|
21
|
+
}
|
22
|
+
: callResponse.value;
|
23
|
+
}
|
@@ -14,4 +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("./
|
17
|
+
__exportStar(require("./Classifier.cjs"), exports);
|
18
|
+
__exportStar(require("./ClassifyEvent.cjs"), exports);
|
19
|
+
__exportStar(require("./EmbeddingSimilarityClassifier.cjs"), exports);
|
20
|
+
__exportStar(require("./classify.cjs"), exports);
|
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.embed = exports.embedMany = void 0;
|
4
4
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
|
-
async function embedMany(model, values, options) {
|
6
|
-
const
|
5
|
+
async function embedMany({ model, values, fullResponse, ...options }) {
|
6
|
+
const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
7
7
|
functionType: "embed",
|
8
8
|
input: values,
|
9
9
|
model,
|
@@ -43,17 +43,17 @@ async function embedMany(model, values, options) {
|
|
43
43
|
};
|
44
44
|
},
|
45
45
|
});
|
46
|
-
return
|
46
|
+
return fullResponse
|
47
47
|
? {
|
48
|
-
embeddings:
|
49
|
-
rawResponse:
|
50
|
-
metadata:
|
48
|
+
embeddings: callResponse.value,
|
49
|
+
rawResponse: callResponse.rawResponse,
|
50
|
+
metadata: callResponse.metadata,
|
51
51
|
}
|
52
|
-
:
|
52
|
+
: callResponse.value;
|
53
53
|
}
|
54
54
|
exports.embedMany = embedMany;
|
55
|
-
async function embed(model, value, options) {
|
56
|
-
const
|
55
|
+
async function embed({ model, value, fullResponse, ...options }) {
|
56
|
+
const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
57
57
|
functionType: "embed",
|
58
58
|
input: value,
|
59
59
|
model,
|
@@ -66,12 +66,12 @@ async function embed(model, value, options) {
|
|
66
66
|
};
|
67
67
|
},
|
68
68
|
});
|
69
|
-
return
|
69
|
+
return fullResponse
|
70
70
|
? {
|
71
|
-
embedding:
|
72
|
-
rawResponse:
|
73
|
-
metadata:
|
71
|
+
embedding: callResponse.value,
|
72
|
+
rawResponse: callResponse.rawResponse,
|
73
|
+
metadata: callResponse.metadata,
|
74
74
|
}
|
75
|
-
:
|
75
|
+
: callResponse.value;
|
76
76
|
}
|
77
77
|
exports.embed = embed;
|
@@ -8,26 +8,29 @@ import { EmbeddingModel, EmbeddingModelSettings } from "./EmbeddingModel.js";
|
|
8
8
|
* @see https://modelfusion.dev/guide/function/embed
|
9
9
|
*
|
10
10
|
* @example
|
11
|
-
* const embeddings = await embedMany(
|
12
|
-
* openai.TextEmbedder(...),
|
13
|
-
* [
|
11
|
+
* const embeddings = await embedMany({
|
12
|
+
* embedder: openai.TextEmbedder(...),
|
13
|
+
* values: [
|
14
14
|
* "At first, Nox didn't know what to do with the pup.",
|
15
15
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
16
16
|
* ]
|
17
|
-
* );
|
17
|
+
* });
|
18
18
|
*
|
19
19
|
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating embeddings.
|
20
20
|
* @param {VALUE[]} values - The values to generate embeddings for.
|
21
|
-
* @param {FunctionOptions} [options] - Optional settings for the function.
|
22
21
|
*
|
23
22
|
* @returns {Promise<Vector[]>} - A promise that resolves to an array of vectors representing the embeddings.
|
24
23
|
*/
|
25
|
-
export declare function embedMany<VALUE>(
|
24
|
+
export declare function embedMany<VALUE>(args: {
|
25
|
+
model: EmbeddingModel<VALUE, EmbeddingModelSettings>;
|
26
|
+
values: VALUE[];
|
26
27
|
fullResponse?: false;
|
27
|
-
}): Promise<Vector[]>;
|
28
|
-
export declare function embedMany<VALUE>(
|
28
|
+
} & FunctionOptions): Promise<Vector[]>;
|
29
|
+
export declare function embedMany<VALUE>(args: {
|
30
|
+
model: EmbeddingModel<VALUE, EmbeddingModelSettings>;
|
31
|
+
values: VALUE[];
|
29
32
|
fullResponse: true;
|
30
|
-
}): Promise<{
|
33
|
+
} & FunctionOptions): Promise<{
|
31
34
|
embeddings: Vector[];
|
32
35
|
rawResponse: unknown;
|
33
36
|
metadata: ModelCallMetadata;
|
@@ -38,23 +41,26 @@ export declare function embedMany<VALUE>(model: EmbeddingModel<VALUE, EmbeddingM
|
|
38
41
|
* @see https://modelfusion.dev/guide/function/embed
|
39
42
|
*
|
40
43
|
* @example
|
41
|
-
* const embedding = await embed(
|
42
|
-
* openai.TextEmbedder(...),
|
43
|
-
* "At first, Nox didn't know what to do with the pup."
|
44
|
-
* );
|
44
|
+
* const embedding = await embed({
|
45
|
+
* model: openai.TextEmbedder(...),
|
46
|
+
* value: "At first, Nox didn't know what to do with the pup."
|
47
|
+
* });
|
45
48
|
*
|
46
49
|
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating the embedding.
|
47
50
|
* @param {VALUE} value - The value to generate an embedding for.
|
48
|
-
* @param {FunctionOptions} [options] - Optional settings for the function.
|
49
51
|
*
|
50
52
|
* @returns {Promise<Vector>} - A promise that resolves to a vector representing the embedding.
|
51
53
|
*/
|
52
|
-
export declare function embed<VALUE>(
|
54
|
+
export declare function embed<VALUE>(args: {
|
55
|
+
model: EmbeddingModel<VALUE, EmbeddingModelSettings>;
|
56
|
+
value: VALUE;
|
53
57
|
fullResponse?: false;
|
54
|
-
}): Promise<Vector>;
|
55
|
-
export declare function embed<VALUE>(
|
58
|
+
} & FunctionOptions): Promise<Vector>;
|
59
|
+
export declare function embed<VALUE>(args: {
|
60
|
+
model: EmbeddingModel<VALUE, EmbeddingModelSettings>;
|
61
|
+
value: VALUE;
|
56
62
|
fullResponse: true;
|
57
|
-
}): Promise<{
|
63
|
+
} & FunctionOptions): Promise<{
|
58
64
|
embedding: Vector;
|
59
65
|
rawResponse: unknown;
|
60
66
|
metadata: ModelCallMetadata;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { executeStandardCall } from "../executeStandardCall.js";
|
2
|
-
export async function embedMany(model, values, options) {
|
3
|
-
const
|
2
|
+
export async function embedMany({ model, values, fullResponse, ...options }) {
|
3
|
+
const callResponse = await executeStandardCall({
|
4
4
|
functionType: "embed",
|
5
5
|
input: values,
|
6
6
|
model,
|
@@ -40,16 +40,16 @@ export async function embedMany(model, values, options) {
|
|
40
40
|
};
|
41
41
|
},
|
42
42
|
});
|
43
|
-
return
|
43
|
+
return fullResponse
|
44
44
|
? {
|
45
|
-
embeddings:
|
46
|
-
rawResponse:
|
47
|
-
metadata:
|
45
|
+
embeddings: callResponse.value,
|
46
|
+
rawResponse: callResponse.rawResponse,
|
47
|
+
metadata: callResponse.metadata,
|
48
48
|
}
|
49
|
-
:
|
49
|
+
: callResponse.value;
|
50
50
|
}
|
51
|
-
export async function embed(model, value, options) {
|
52
|
-
const
|
51
|
+
export async function embed({ model, value, fullResponse, ...options }) {
|
52
|
+
const callResponse = await executeStandardCall({
|
53
53
|
functionType: "embed",
|
54
54
|
input: value,
|
55
55
|
model,
|
@@ -62,11 +62,11 @@ export async function embed(model, value, options) {
|
|
62
62
|
};
|
63
63
|
},
|
64
64
|
});
|
65
|
-
return
|
65
|
+
return fullResponse
|
66
66
|
? {
|
67
|
-
embedding:
|
68
|
-
rawResponse:
|
69
|
-
metadata:
|
67
|
+
embedding: callResponse.value,
|
68
|
+
rawResponse: callResponse.rawResponse,
|
69
|
+
metadata: callResponse.metadata,
|
70
70
|
}
|
71
|
-
:
|
71
|
+
: callResponse.value;
|
72
72
|
}
|
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.generateImage = void 0;
|
4
4
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
|
-
async function generateImage(model, prompt, options) {
|
6
|
-
const
|
5
|
+
async function generateImage({ model, prompt, fullResponse, ...options }) {
|
6
|
+
const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
7
7
|
functionType: "generate-image",
|
8
8
|
input: prompt,
|
9
9
|
model,
|
@@ -16,16 +16,16 @@ async function generateImage(model, prompt, options) {
|
|
16
16
|
};
|
17
17
|
},
|
18
18
|
});
|
19
|
-
const imagesBase64 =
|
19
|
+
const imagesBase64 = callResponse.value;
|
20
20
|
const images = imagesBase64.map((imageBase64) => Buffer.from(imageBase64, "base64"));
|
21
|
-
return
|
21
|
+
return fullResponse
|
22
22
|
? {
|
23
23
|
image: images[0],
|
24
24
|
imageBase64: imagesBase64[0],
|
25
25
|
images,
|
26
26
|
imagesBase64,
|
27
|
-
rawResponse:
|
28
|
-
metadata:
|
27
|
+
rawResponse: callResponse.rawResponse,
|
28
|
+
metadata: callResponse.metadata,
|
29
29
|
}
|
30
30
|
: images[0];
|
31
31
|
}
|
@@ -11,27 +11,30 @@ import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGener
|
|
11
11
|
* @see https://modelfusion.dev/guide/function/generate-image
|
12
12
|
*
|
13
13
|
* @example
|
14
|
-
* const image = await generateImage(
|
15
|
-
* stability.ImageGenerator(...),
|
16
|
-
* [
|
14
|
+
* const image = await generateImage({
|
15
|
+
* imageGenerator: stability.ImageGenerator(...),
|
16
|
+
* prompt: [
|
17
17
|
* { text: "the wicked witch of the west" },
|
18
18
|
* { text: "style of early 19th century painting", weight: 0.5 },
|
19
19
|
* ]
|
20
|
-
* );
|
20
|
+
* });
|
21
21
|
*
|
22
22
|
* @param {ImageGenerationModel<PROMPT, ImageGenerationModelSettings>} model - The image generation model to be used.
|
23
23
|
* @param {PROMPT} prompt - The prompt to be used for image generation.
|
24
|
-
* @param {FunctionOptions} [options] - Optional settings for the function.
|
25
24
|
*
|
26
25
|
* @returns {Promise} - Returns a promise that resolves to the generated image.
|
27
26
|
* The image is a Buffer containing the image data in PNG format.
|
28
27
|
*/
|
29
|
-
export declare function generateImage<PROMPT>(
|
28
|
+
export declare function generateImage<PROMPT>(args: {
|
29
|
+
model: ImageGenerationModel<PROMPT, ImageGenerationModelSettings>;
|
30
|
+
prompt: PROMPT;
|
30
31
|
fullResponse?: false;
|
31
|
-
}): Promise<Buffer>;
|
32
|
-
export declare function generateImage<PROMPT>(
|
32
|
+
} & FunctionOptions): Promise<Buffer>;
|
33
|
+
export declare function generateImage<PROMPT>(args: {
|
34
|
+
model: ImageGenerationModel<PROMPT, ImageGenerationModelSettings>;
|
35
|
+
prompt: PROMPT;
|
33
36
|
fullResponse: true;
|
34
|
-
}): Promise<{
|
37
|
+
} & FunctionOptions): Promise<{
|
35
38
|
image: Buffer;
|
36
39
|
imageBase64: string;
|
37
40
|
images: Buffer[];
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { executeStandardCall } from "../executeStandardCall.js";
|
2
|
-
export async function generateImage(model, prompt, options) {
|
3
|
-
const
|
2
|
+
export async function generateImage({ model, prompt, fullResponse, ...options }) {
|
3
|
+
const callResponse = await executeStandardCall({
|
4
4
|
functionType: "generate-image",
|
5
5
|
input: prompt,
|
6
6
|
model,
|
@@ -13,16 +13,16 @@ export async function generateImage(model, prompt, options) {
|
|
13
13
|
};
|
14
14
|
},
|
15
15
|
});
|
16
|
-
const imagesBase64 =
|
16
|
+
const imagesBase64 = callResponse.value;
|
17
17
|
const images = imagesBase64.map((imageBase64) => Buffer.from(imageBase64, "base64"));
|
18
|
-
return
|
18
|
+
return fullResponse
|
19
19
|
? {
|
20
20
|
image: images[0],
|
21
21
|
imageBase64: imagesBase64[0],
|
22
22
|
images,
|
23
23
|
imagesBase64,
|
24
|
-
rawResponse:
|
25
|
-
metadata:
|
24
|
+
rawResponse: callResponse.rawResponse,
|
25
|
+
metadata: callResponse.metadata,
|
26
26
|
}
|
27
27
|
: images[0];
|
28
28
|
}
|
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.generateSpeech = void 0;
|
4
4
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
|
-
async function generateSpeech(model, text, options) {
|
6
|
-
const
|
5
|
+
async function generateSpeech({ model, text, fullResponse, ...options }) {
|
6
|
+
const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
|
7
7
|
functionType: "generate-speech",
|
8
8
|
input: text,
|
9
9
|
model,
|
@@ -16,12 +16,12 @@ async function generateSpeech(model, text, options) {
|
|
16
16
|
};
|
17
17
|
},
|
18
18
|
});
|
19
|
-
return
|
19
|
+
return fullResponse
|
20
20
|
? {
|
21
|
-
speech:
|
22
|
-
rawResponse:
|
23
|
-
metadata:
|
21
|
+
speech: callResponse.value,
|
22
|
+
rawResponse: callResponse.rawResponse,
|
23
|
+
metadata: callResponse.metadata,
|
24
24
|
}
|
25
|
-
:
|
25
|
+
: callResponse.value;
|
26
26
|
}
|
27
27
|
exports.generateSpeech = generateSpeech;
|