modelfusion 0.122.0 → 0.124.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 +56 -0
- package/README.md +42 -2
- package/index.cjs +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/model-function/ModelCallEvent.d.ts +3 -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/index.cjs +1 -0
- package/model-function/index.d.ts +1 -0
- package/model-function/index.js +1 -0
- package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.d.ts +9 -9
- package/model-provider/openai/AbstractOpenAITextEmbeddingModel.cjs +82 -0
- package/model-provider/openai/AbstractOpenAITextEmbeddingModel.d.ts +91 -0
- package/model-provider/openai/AbstractOpenAITextEmbeddingModel.js +78 -0
- package/model-provider/openai/OpenAIFacade.cjs +18 -18
- package/model-provider/openai/OpenAIFacade.d.ts +18 -18
- package/model-provider/openai/OpenAIFacade.js +18 -18
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +3 -68
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +4 -82
- package/model-provider/openai/OpenAITextEmbeddingModel.js +3 -68
- package/model-provider/openai/index.cjs +1 -0
- package/model-provider/openai/index.d.ts +1 -0
- package/model-provider/openai/index.js +1 -0
- package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +2 -0
- package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.d.ts +2 -0
- package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +28 -7
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +24 -6
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +26 -6
- package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.cjs +27 -0
- package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.d.ts +18 -0
- package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.js +23 -0
- package/model-provider/openai-compatible/index.cjs +1 -0
- package/model-provider/openai-compatible/index.d.ts +1 -0
- package/model-provider/openai-compatible/index.js +1 -0
- package/package.json +1 -1
- package/classifier/SemanticClassifier.cjs +0 -81
- package/classifier/SemanticClassifier.d.ts +0 -25
- package/classifier/SemanticClassifier.js +0 -77
- package/classifier/index.d.ts +0 -1
- package/classifier/index.js +0 -1
@@ -40,11 +40,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
40
40
|
get settingsForEvent(): Partial<OllamaChatModelSettings>;
|
41
41
|
doGenerateTexts(prompt: OllamaChatPrompt, options: FunctionCallOptions): Promise<{
|
42
42
|
rawResponse: {
|
43
|
-
model: string;
|
44
43
|
message: {
|
45
44
|
role: string;
|
46
45
|
content: string;
|
47
46
|
};
|
47
|
+
model: string;
|
48
48
|
done: true;
|
49
49
|
created_at: string;
|
50
50
|
total_duration: number;
|
@@ -61,11 +61,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
61
61
|
}>;
|
62
62
|
restoreGeneratedTexts(rawResponse: unknown): {
|
63
63
|
rawResponse: {
|
64
|
-
model: string;
|
65
64
|
message: {
|
66
65
|
role: string;
|
67
66
|
content: string;
|
68
67
|
};
|
68
|
+
model: string;
|
69
69
|
done: true;
|
70
70
|
created_at: string;
|
71
71
|
total_duration: number;
|
@@ -82,11 +82,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
82
82
|
};
|
83
83
|
private processTextGenerationResponse;
|
84
84
|
doStreamText(prompt: OllamaChatPrompt, options: FunctionCallOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
|
85
|
-
model: string;
|
86
85
|
message: {
|
87
86
|
role: string;
|
88
87
|
content: string;
|
89
88
|
};
|
89
|
+
model: string;
|
90
90
|
done: false;
|
91
91
|
created_at: string;
|
92
92
|
} | {
|
@@ -141,11 +141,11 @@ declare const ollamaChatResponseSchema: z.ZodObject<{
|
|
141
141
|
eval_count: z.ZodNumber;
|
142
142
|
eval_duration: z.ZodNumber;
|
143
143
|
}, "strip", z.ZodTypeAny, {
|
144
|
-
model: string;
|
145
144
|
message: {
|
146
145
|
role: string;
|
147
146
|
content: string;
|
148
147
|
};
|
148
|
+
model: string;
|
149
149
|
done: true;
|
150
150
|
created_at: string;
|
151
151
|
total_duration: number;
|
@@ -155,11 +155,11 @@ declare const ollamaChatResponseSchema: z.ZodObject<{
|
|
155
155
|
prompt_eval_count?: number | undefined;
|
156
156
|
prompt_eval_duration?: number | undefined;
|
157
157
|
}, {
|
158
|
-
model: string;
|
159
158
|
message: {
|
160
159
|
role: string;
|
161
160
|
content: string;
|
162
161
|
};
|
162
|
+
model: string;
|
163
163
|
done: true;
|
164
164
|
created_at: string;
|
165
165
|
total_duration: number;
|
@@ -185,19 +185,19 @@ declare const ollamaChatStreamChunkSchema: z.ZodDiscriminatedUnion<"done", [z.Zo
|
|
185
185
|
content: string;
|
186
186
|
}>;
|
187
187
|
}, "strip", z.ZodTypeAny, {
|
188
|
-
model: string;
|
189
188
|
message: {
|
190
189
|
role: string;
|
191
190
|
content: string;
|
192
191
|
};
|
192
|
+
model: string;
|
193
193
|
done: false;
|
194
194
|
created_at: string;
|
195
195
|
}, {
|
196
|
-
model: string;
|
197
196
|
message: {
|
198
197
|
role: string;
|
199
198
|
content: string;
|
200
199
|
};
|
200
|
+
model: string;
|
201
201
|
done: false;
|
202
202
|
created_at: string;
|
203
203
|
}>, z.ZodObject<{
|
@@ -247,11 +247,11 @@ export declare const OllamaChatResponseFormat: {
|
|
247
247
|
requestBodyValues: unknown;
|
248
248
|
response: Response;
|
249
249
|
}) => Promise<{
|
250
|
-
model: string;
|
251
250
|
message: {
|
252
251
|
role: string;
|
253
252
|
content: string;
|
254
253
|
};
|
254
|
+
model: string;
|
255
255
|
done: true;
|
256
256
|
created_at: string;
|
257
257
|
total_duration: number;
|
@@ -271,11 +271,11 @@ export declare const OllamaChatResponseFormat: {
|
|
271
271
|
handler: ({ response }: {
|
272
272
|
response: Response;
|
273
273
|
}) => Promise<AsyncIterable<import("../../index.js").Delta<{
|
274
|
-
model: string;
|
275
274
|
message: {
|
276
275
|
role: string;
|
277
276
|
content: string;
|
278
277
|
};
|
278
|
+
model: string;
|
279
279
|
done: false;
|
280
280
|
created_at: string;
|
281
281
|
} | {
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AbstractOpenAITextEmbeddingModel = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
6
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
7
|
+
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
8
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
9
|
+
const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
|
10
|
+
const OpenAIError_js_1 = require("./OpenAIError.cjs");
|
11
|
+
/**
|
12
|
+
* Abstract text embedding model that calls an API that is compatible with the OpenAI embedding API.
|
13
|
+
*
|
14
|
+
* @see https://platform.openai.com/docs/api-reference/embeddings
|
15
|
+
*/
|
16
|
+
class AbstractOpenAITextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
17
|
+
constructor(settings) {
|
18
|
+
super({ settings });
|
19
|
+
Object.defineProperty(this, "isParallelizable", {
|
20
|
+
enumerable: true,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: true
|
24
|
+
});
|
25
|
+
}
|
26
|
+
get maxValuesPerCall() {
|
27
|
+
return this.settings.maxValuesPerCall ?? 2048;
|
28
|
+
}
|
29
|
+
async callAPI(texts, callOptions) {
|
30
|
+
const api = this.settings.api ?? new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration();
|
31
|
+
const abortSignal = callOptions.run?.abortSignal;
|
32
|
+
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
33
|
+
retry: api.retry,
|
34
|
+
throttle: api.throttle,
|
35
|
+
call: async () => (0, postToApi_js_1.postJsonToApi)({
|
36
|
+
url: api.assembleUrl("/embeddings"),
|
37
|
+
headers: api.headers({
|
38
|
+
functionType: callOptions.functionType,
|
39
|
+
functionId: callOptions.functionId,
|
40
|
+
run: callOptions.run,
|
41
|
+
callId: callOptions.callId,
|
42
|
+
}),
|
43
|
+
body: {
|
44
|
+
model: this.modelName,
|
45
|
+
input: texts,
|
46
|
+
user: this.settings.isUserIdForwardingEnabled
|
47
|
+
? callOptions.run?.userId
|
48
|
+
: undefined,
|
49
|
+
},
|
50
|
+
failedResponseHandler: OpenAIError_js_1.failedOpenAICallResponseHandler,
|
51
|
+
successfulResponseHandler: (0, postToApi_js_1.createJsonResponseHandler)((0, ZodSchema_js_1.zodSchema)(openAITextEmbeddingResponseSchema)),
|
52
|
+
abortSignal,
|
53
|
+
}),
|
54
|
+
});
|
55
|
+
}
|
56
|
+
async doEmbedValues(texts, callOptions) {
|
57
|
+
if (texts.length > this.maxValuesPerCall) {
|
58
|
+
throw new Error(`The OpenAI embedding API only supports ${this.maxValuesPerCall} texts per API call.`);
|
59
|
+
}
|
60
|
+
const rawResponse = await this.callAPI(texts, callOptions);
|
61
|
+
return {
|
62
|
+
rawResponse,
|
63
|
+
embeddings: rawResponse.data.map((data) => data.embedding),
|
64
|
+
};
|
65
|
+
}
|
66
|
+
}
|
67
|
+
exports.AbstractOpenAITextEmbeddingModel = AbstractOpenAITextEmbeddingModel;
|
68
|
+
const openAITextEmbeddingResponseSchema = zod_1.z.object({
|
69
|
+
object: zod_1.z.literal("list"),
|
70
|
+
data: zod_1.z.array(zod_1.z.object({
|
71
|
+
object: zod_1.z.literal("embedding"),
|
72
|
+
embedding: zod_1.z.array(zod_1.z.number()),
|
73
|
+
index: zod_1.z.number(),
|
74
|
+
})),
|
75
|
+
model: zod_1.z.string(),
|
76
|
+
usage: zod_1.z
|
77
|
+
.object({
|
78
|
+
prompt_tokens: zod_1.z.number(),
|
79
|
+
total_tokens: zod_1.z.number(),
|
80
|
+
})
|
81
|
+
.optional(), // for openai-compatible models
|
82
|
+
});
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import { FunctionCallOptions } from "../../core/FunctionOptions.js";
|
3
|
+
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
4
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
|
+
import { EmbeddingModelSettings } from "../../model-function/embed/EmbeddingModel.js";
|
6
|
+
export interface AbstractOpenAITextEmbeddingModelSettings extends EmbeddingModelSettings {
|
7
|
+
api?: ApiConfiguration;
|
8
|
+
model: string;
|
9
|
+
maxValuesPerCall?: number | undefined;
|
10
|
+
isUserIdForwardingEnabled?: boolean;
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Abstract text embedding model that calls an API that is compatible with the OpenAI embedding API.
|
14
|
+
*
|
15
|
+
* @see https://platform.openai.com/docs/api-reference/embeddings
|
16
|
+
*/
|
17
|
+
export declare abstract class AbstractOpenAITextEmbeddingModel<SETTINGS extends AbstractOpenAITextEmbeddingModelSettings> extends AbstractModel<SETTINGS> {
|
18
|
+
constructor(settings: SETTINGS);
|
19
|
+
get maxValuesPerCall(): number;
|
20
|
+
readonly isParallelizable = true;
|
21
|
+
callAPI(texts: Array<string>, callOptions: FunctionCallOptions): Promise<OpenAITextEmbeddingResponse>;
|
22
|
+
doEmbedValues(texts: string[], callOptions: FunctionCallOptions): Promise<{
|
23
|
+
rawResponse: {
|
24
|
+
object: "list";
|
25
|
+
data: {
|
26
|
+
object: "embedding";
|
27
|
+
embedding: number[];
|
28
|
+
index: number;
|
29
|
+
}[];
|
30
|
+
model: string;
|
31
|
+
usage?: {
|
32
|
+
prompt_tokens: number;
|
33
|
+
total_tokens: number;
|
34
|
+
} | undefined;
|
35
|
+
};
|
36
|
+
embeddings: number[][];
|
37
|
+
}>;
|
38
|
+
}
|
39
|
+
declare const openAITextEmbeddingResponseSchema: z.ZodObject<{
|
40
|
+
object: z.ZodLiteral<"list">;
|
41
|
+
data: z.ZodArray<z.ZodObject<{
|
42
|
+
object: z.ZodLiteral<"embedding">;
|
43
|
+
embedding: z.ZodArray<z.ZodNumber, "many">;
|
44
|
+
index: z.ZodNumber;
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
46
|
+
object: "embedding";
|
47
|
+
embedding: number[];
|
48
|
+
index: number;
|
49
|
+
}, {
|
50
|
+
object: "embedding";
|
51
|
+
embedding: number[];
|
52
|
+
index: number;
|
53
|
+
}>, "many">;
|
54
|
+
model: z.ZodString;
|
55
|
+
usage: z.ZodOptional<z.ZodObject<{
|
56
|
+
prompt_tokens: z.ZodNumber;
|
57
|
+
total_tokens: z.ZodNumber;
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
59
|
+
prompt_tokens: number;
|
60
|
+
total_tokens: number;
|
61
|
+
}, {
|
62
|
+
prompt_tokens: number;
|
63
|
+
total_tokens: number;
|
64
|
+
}>>;
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
66
|
+
object: "list";
|
67
|
+
data: {
|
68
|
+
object: "embedding";
|
69
|
+
embedding: number[];
|
70
|
+
index: number;
|
71
|
+
}[];
|
72
|
+
model: string;
|
73
|
+
usage?: {
|
74
|
+
prompt_tokens: number;
|
75
|
+
total_tokens: number;
|
76
|
+
} | undefined;
|
77
|
+
}, {
|
78
|
+
object: "list";
|
79
|
+
data: {
|
80
|
+
object: "embedding";
|
81
|
+
embedding: number[];
|
82
|
+
index: number;
|
83
|
+
}[];
|
84
|
+
model: string;
|
85
|
+
usage?: {
|
86
|
+
prompt_tokens: number;
|
87
|
+
total_tokens: number;
|
88
|
+
} | undefined;
|
89
|
+
}>;
|
90
|
+
export type OpenAITextEmbeddingResponse = z.infer<typeof openAITextEmbeddingResponseSchema>;
|
91
|
+
export {};
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
3
|
+
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
4
|
+
import { zodSchema } from "../../core/schema/ZodSchema.js";
|
5
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
6
|
+
import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
|
7
|
+
import { failedOpenAICallResponseHandler } from "./OpenAIError.js";
|
8
|
+
/**
|
9
|
+
* Abstract text embedding model that calls an API that is compatible with the OpenAI embedding API.
|
10
|
+
*
|
11
|
+
* @see https://platform.openai.com/docs/api-reference/embeddings
|
12
|
+
*/
|
13
|
+
export class AbstractOpenAITextEmbeddingModel extends AbstractModel {
|
14
|
+
constructor(settings) {
|
15
|
+
super({ settings });
|
16
|
+
Object.defineProperty(this, "isParallelizable", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: true
|
21
|
+
});
|
22
|
+
}
|
23
|
+
get maxValuesPerCall() {
|
24
|
+
return this.settings.maxValuesPerCall ?? 2048;
|
25
|
+
}
|
26
|
+
async callAPI(texts, callOptions) {
|
27
|
+
const api = this.settings.api ?? new OpenAIApiConfiguration();
|
28
|
+
const abortSignal = callOptions.run?.abortSignal;
|
29
|
+
return callWithRetryAndThrottle({
|
30
|
+
retry: api.retry,
|
31
|
+
throttle: api.throttle,
|
32
|
+
call: async () => postJsonToApi({
|
33
|
+
url: api.assembleUrl("/embeddings"),
|
34
|
+
headers: api.headers({
|
35
|
+
functionType: callOptions.functionType,
|
36
|
+
functionId: callOptions.functionId,
|
37
|
+
run: callOptions.run,
|
38
|
+
callId: callOptions.callId,
|
39
|
+
}),
|
40
|
+
body: {
|
41
|
+
model: this.modelName,
|
42
|
+
input: texts,
|
43
|
+
user: this.settings.isUserIdForwardingEnabled
|
44
|
+
? callOptions.run?.userId
|
45
|
+
: undefined,
|
46
|
+
},
|
47
|
+
failedResponseHandler: failedOpenAICallResponseHandler,
|
48
|
+
successfulResponseHandler: createJsonResponseHandler(zodSchema(openAITextEmbeddingResponseSchema)),
|
49
|
+
abortSignal,
|
50
|
+
}),
|
51
|
+
});
|
52
|
+
}
|
53
|
+
async doEmbedValues(texts, callOptions) {
|
54
|
+
if (texts.length > this.maxValuesPerCall) {
|
55
|
+
throw new Error(`The OpenAI embedding API only supports ${this.maxValuesPerCall} texts per API call.`);
|
56
|
+
}
|
57
|
+
const rawResponse = await this.callAPI(texts, callOptions);
|
58
|
+
return {
|
59
|
+
rawResponse,
|
60
|
+
embeddings: rawResponse.data.map((data) => data.embedding),
|
61
|
+
};
|
62
|
+
}
|
63
|
+
}
|
64
|
+
const openAITextEmbeddingResponseSchema = z.object({
|
65
|
+
object: z.literal("list"),
|
66
|
+
data: z.array(z.object({
|
67
|
+
object: z.literal("embedding"),
|
68
|
+
embedding: z.array(z.number()),
|
69
|
+
index: z.number(),
|
70
|
+
})),
|
71
|
+
model: z.string(),
|
72
|
+
usage: z
|
73
|
+
.object({
|
74
|
+
prompt_tokens: z.number(),
|
75
|
+
total_tokens: z.number(),
|
76
|
+
})
|
77
|
+
.optional(), // for openai-compatible models
|
78
|
+
});
|
@@ -42,10 +42,10 @@ exports.AzureApi = AzureApi;
|
|
42
42
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
43
43
|
* });
|
44
44
|
*
|
45
|
-
* const text = await generateText(
|
45
|
+
* const text = await generateText({
|
46
46
|
* model,
|
47
|
-
* "Write a short story about a robot learning to love:\n\n"
|
48
|
-
* );
|
47
|
+
* prompt: "Write a short story about a robot learning to love:\n\n"
|
48
|
+
* });
|
49
49
|
*
|
50
50
|
* @return A new instance of {@link OpenAICompletionModel}.
|
51
51
|
*/
|
@@ -65,14 +65,14 @@ exports.CompletionTextGenerator = CompletionTextGenerator;
|
|
65
65
|
* maxGenerationTokens: 500,
|
66
66
|
* });
|
67
67
|
*
|
68
|
-
* const text = await generateText(
|
68
|
+
* const text = await generateText({
|
69
69
|
* model,
|
70
|
-
* [
|
70
|
+
* prompt: [
|
71
71
|
* openai.ChatMessage.system(
|
72
72
|
* "Write a short story about a robot learning to love:"
|
73
73
|
* ),
|
74
74
|
* ]
|
75
|
-
* );
|
75
|
+
* });
|
76
76
|
*/
|
77
77
|
function ChatTextGenerator(settings) {
|
78
78
|
return new OpenAIChatModel_js_1.OpenAIChatModel(settings);
|
@@ -84,13 +84,13 @@ exports.ChatTextGenerator = ChatTextGenerator;
|
|
84
84
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
85
85
|
*
|
86
86
|
* @example
|
87
|
-
* const embeddings = await embedMany(
|
88
|
-
* openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
89
|
-
* [
|
87
|
+
* const embeddings = await embedMany({
|
88
|
+
* model: openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
89
|
+
* values: [
|
90
90
|
* "At first, Nox didn't know what to do with the pup.",
|
91
91
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
92
92
|
* ]
|
93
|
-
* );
|
93
|
+
* });
|
94
94
|
*
|
95
95
|
* @returns A new instance of {@link OpenAITextEmbeddingModel}.
|
96
96
|
*/
|
@@ -117,13 +117,13 @@ exports.SpeechGenerator = SpeechGenerator;
|
|
117
117
|
* @example
|
118
118
|
* const data = await fs.promises.readFile("data/test.mp3");
|
119
119
|
*
|
120
|
-
* const transcription = await transcribe(
|
121
|
-
* openai.Transcriber({ model: "whisper-1" }),
|
122
|
-
* {
|
120
|
+
* const transcription = await transcribe({
|
121
|
+
* model: openai.Transcriber({ model: "whisper-1" }),
|
122
|
+
* data: {
|
123
123
|
* type: "mp3",
|
124
124
|
* data,
|
125
125
|
* }
|
126
|
-
* );
|
126
|
+
* });
|
127
127
|
*
|
128
128
|
* @returns A new instance of {@link OpenAITranscriptionModel}.
|
129
129
|
*/
|
@@ -137,10 +137,10 @@ exports.Transcriber = Transcriber;
|
|
137
137
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
138
138
|
*
|
139
139
|
* @example
|
140
|
-
* const image = await generateImage(
|
141
|
-
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
142
|
-
* "the wicked witch of the west in the style of early 19th century painting"
|
143
|
-
* );
|
140
|
+
* const image = await generateImage({
|
141
|
+
* model: new OpenAIImageGenerationModel({ size: "512x512" }),
|
142
|
+
* prompt: "the wicked witch of the west in the style of early 19th century painting"
|
143
|
+
* });
|
144
144
|
*
|
145
145
|
* @returns A new instance of {@link OpenAIImageGenerationModel}.
|
146
146
|
*/
|
@@ -36,10 +36,10 @@ export declare function AzureApi(settings: AzureOpenAIApiConfigurationOptions):
|
|
36
36
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
37
37
|
* });
|
38
38
|
*
|
39
|
-
* const text = await generateText(
|
39
|
+
* const text = await generateText({
|
40
40
|
* model,
|
41
|
-
* "Write a short story about a robot learning to love:\n\n"
|
42
|
-
* );
|
41
|
+
* prompt: "Write a short story about a robot learning to love:\n\n"
|
42
|
+
* });
|
43
43
|
*
|
44
44
|
* @return A new instance of {@link OpenAICompletionModel}.
|
45
45
|
*/
|
@@ -56,14 +56,14 @@ export declare function CompletionTextGenerator(settings: OpenAICompletionModelS
|
|
56
56
|
* maxGenerationTokens: 500,
|
57
57
|
* });
|
58
58
|
*
|
59
|
-
* const text = await generateText(
|
59
|
+
* const text = await generateText({
|
60
60
|
* model,
|
61
|
-
* [
|
61
|
+
* prompt: [
|
62
62
|
* openai.ChatMessage.system(
|
63
63
|
* "Write a short story about a robot learning to love:"
|
64
64
|
* ),
|
65
65
|
* ]
|
66
|
-
* );
|
66
|
+
* });
|
67
67
|
*/
|
68
68
|
export declare function ChatTextGenerator(settings: OpenAIChatSettings): OpenAIChatModel;
|
69
69
|
/**
|
@@ -72,13 +72,13 @@ export declare function ChatTextGenerator(settings: OpenAIChatSettings): OpenAIC
|
|
72
72
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
73
73
|
*
|
74
74
|
* @example
|
75
|
-
* const embeddings = await embedMany(
|
76
|
-
* openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
77
|
-
* [
|
75
|
+
* const embeddings = await embedMany({
|
76
|
+
* model: openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
77
|
+
* values: [
|
78
78
|
* "At first, Nox didn't know what to do with the pup.",
|
79
79
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
80
80
|
* ]
|
81
|
-
* );
|
81
|
+
* });
|
82
82
|
*
|
83
83
|
* @returns A new instance of {@link OpenAITextEmbeddingModel}.
|
84
84
|
*/
|
@@ -99,13 +99,13 @@ export declare function SpeechGenerator(settings: OpenAISpeechModelSettings): Op
|
|
99
99
|
* @example
|
100
100
|
* const data = await fs.promises.readFile("data/test.mp3");
|
101
101
|
*
|
102
|
-
* const transcription = await transcribe(
|
103
|
-
* openai.Transcriber({ model: "whisper-1" }),
|
104
|
-
* {
|
102
|
+
* const transcription = await transcribe({
|
103
|
+
* model: openai.Transcriber({ model: "whisper-1" }),
|
104
|
+
* data: {
|
105
105
|
* type: "mp3",
|
106
106
|
* data,
|
107
107
|
* }
|
108
|
-
* );
|
108
|
+
* });
|
109
109
|
*
|
110
110
|
* @returns A new instance of {@link OpenAITranscriptionModel}.
|
111
111
|
*/
|
@@ -116,10 +116,10 @@ export declare function Transcriber(settings: OpenAITranscriptionModelSettings):
|
|
116
116
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
117
117
|
*
|
118
118
|
* @example
|
119
|
-
* const image = await generateImage(
|
120
|
-
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
121
|
-
* "the wicked witch of the west in the style of early 19th century painting"
|
122
|
-
* );
|
119
|
+
* const image = await generateImage({
|
120
|
+
* model: new OpenAIImageGenerationModel({ size: "512x512" }),
|
121
|
+
* prompt: "the wicked witch of the west in the style of early 19th century painting"
|
122
|
+
* });
|
123
123
|
*
|
124
124
|
* @returns A new instance of {@link OpenAIImageGenerationModel}.
|
125
125
|
*/
|
@@ -37,10 +37,10 @@ export function AzureApi(settings) {
|
|
37
37
|
* retry: retryWithExponentialBackoff({ maxTries: 5 }),
|
38
38
|
* });
|
39
39
|
*
|
40
|
-
* const text = await generateText(
|
40
|
+
* const text = await generateText({
|
41
41
|
* model,
|
42
|
-
* "Write a short story about a robot learning to love:\n\n"
|
43
|
-
* );
|
42
|
+
* prompt: "Write a short story about a robot learning to love:\n\n"
|
43
|
+
* });
|
44
44
|
*
|
45
45
|
* @return A new instance of {@link OpenAICompletionModel}.
|
46
46
|
*/
|
@@ -59,14 +59,14 @@ export function CompletionTextGenerator(settings) {
|
|
59
59
|
* maxGenerationTokens: 500,
|
60
60
|
* });
|
61
61
|
*
|
62
|
-
* const text = await generateText(
|
62
|
+
* const text = await generateText({
|
63
63
|
* model,
|
64
|
-
* [
|
64
|
+
* prompt: [
|
65
65
|
* openai.ChatMessage.system(
|
66
66
|
* "Write a short story about a robot learning to love:"
|
67
67
|
* ),
|
68
68
|
* ]
|
69
|
-
* );
|
69
|
+
* });
|
70
70
|
*/
|
71
71
|
export function ChatTextGenerator(settings) {
|
72
72
|
return new OpenAIChatModel(settings);
|
@@ -77,13 +77,13 @@ export function ChatTextGenerator(settings) {
|
|
77
77
|
* @see https://platform.openai.com/docs/api-reference/embeddings
|
78
78
|
*
|
79
79
|
* @example
|
80
|
-
* const embeddings = await embedMany(
|
81
|
-
* openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
82
|
-
* [
|
80
|
+
* const embeddings = await embedMany({
|
81
|
+
* model: openai.TextEmbedder({ model: "text-embedding-ada-002" }),
|
82
|
+
* values: [
|
83
83
|
* "At first, Nox didn't know what to do with the pup.",
|
84
84
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
85
85
|
* ]
|
86
|
-
* );
|
86
|
+
* });
|
87
87
|
*
|
88
88
|
* @returns A new instance of {@link OpenAITextEmbeddingModel}.
|
89
89
|
*/
|
@@ -108,13 +108,13 @@ export function SpeechGenerator(settings) {
|
|
108
108
|
* @example
|
109
109
|
* const data = await fs.promises.readFile("data/test.mp3");
|
110
110
|
*
|
111
|
-
* const transcription = await transcribe(
|
112
|
-
* openai.Transcriber({ model: "whisper-1" }),
|
113
|
-
* {
|
111
|
+
* const transcription = await transcribe({
|
112
|
+
* model: openai.Transcriber({ model: "whisper-1" }),
|
113
|
+
* data: {
|
114
114
|
* type: "mp3",
|
115
115
|
* data,
|
116
116
|
* }
|
117
|
-
* );
|
117
|
+
* });
|
118
118
|
*
|
119
119
|
* @returns A new instance of {@link OpenAITranscriptionModel}.
|
120
120
|
*/
|
@@ -127,10 +127,10 @@ export function Transcriber(settings) {
|
|
127
127
|
* @see https://platform.openai.com/docs/api-reference/images/create
|
128
128
|
*
|
129
129
|
* @example
|
130
|
-
* const image = await generateImage(
|
131
|
-
* new OpenAIImageGenerationModel({ size: "512x512" }),
|
132
|
-
* "the wicked witch of the west in the style of early 19th century painting"
|
133
|
-
* );
|
130
|
+
* const image = await generateImage({
|
131
|
+
* model: new OpenAIImageGenerationModel({ size: "512x512" }),
|
132
|
+
* prompt: "the wicked witch of the west in the style of early 19th century painting"
|
133
|
+
* });
|
134
134
|
*
|
135
135
|
* @returns A new instance of {@link OpenAIImageGenerationModel}.
|
136
136
|
*/
|