workers-ai-provider 3.1.8 → 3.1.9
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/README.md +22 -21
- package/dist/index.d.mts +422 -0
- package/dist/index.mjs +1553 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/index.d.ts +0 -397
- package/dist/index.js +0 -1618
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ export default {
|
|
|
20
20
|
const workersai = createWorkersAI({ binding: env.AI });
|
|
21
21
|
|
|
22
22
|
const result = streamText({
|
|
23
|
-
model: workersai("@cf/
|
|
23
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
24
24
|
messages: [{ role: "user", content: "Write a haiku about Cloudflare" }],
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -71,19 +71,20 @@ Browse the full catalog at [developers.cloudflare.com/workers-ai/models](https:/
|
|
|
71
71
|
|
|
72
72
|
Some good defaults:
|
|
73
73
|
|
|
74
|
-
| Task | Model
|
|
75
|
-
| -------------- |
|
|
76
|
-
| Chat | `@cf/
|
|
77
|
-
| Chat | `@cf/
|
|
78
|
-
| Chat | `@cf/openai/gpt-oss-120b`
|
|
79
|
-
| Reasoning | `@cf/
|
|
80
|
-
|
|
|
81
|
-
| Embeddings | `@cf/
|
|
82
|
-
|
|
|
83
|
-
|
|
|
84
|
-
| Transcription | `@cf/
|
|
85
|
-
|
|
|
86
|
-
|
|
|
74
|
+
| Task | Model | Notes |
|
|
75
|
+
| -------------- | -------------------------------------- | ----------------------------------- |
|
|
76
|
+
| Chat | `@cf/moonshotai/kimi-k2.5` | 256k ctx, tools, vision, reasoning |
|
|
77
|
+
| Chat | `@cf/zai-org/glm-4.7-flash` | Fast, multilingual, 131k ctx |
|
|
78
|
+
| Chat | `@cf/openai/gpt-oss-120b` | OpenAI open-weights, high reasoning |
|
|
79
|
+
| Reasoning | `@cf/moonshotai/kimi-k2.5` | Configurable `reasoning_effort` |
|
|
80
|
+
| Reasoning | `@cf/qwen/qwq-32b` | Emits `reasoning_content` |
|
|
81
|
+
| Embeddings | `@cf/baai/bge-base-en-v1.5` | 768-dim, English |
|
|
82
|
+
| Embeddings | `@cf/google/embeddinggemma-300m` | 100+ languages, by Google |
|
|
83
|
+
| Images | `@cf/black-forest-labs/flux-1-schnell` | Fast, free-tier image generation |
|
|
84
|
+
| Transcription | `@cf/openai/whisper-large-v3-turbo` | Best accuracy, multilingual |
|
|
85
|
+
| Transcription | `@cf/deepgram/nova-3` | Fast, high accuracy |
|
|
86
|
+
| Text-to-Speech | `@cf/deepgram/aura-2-en` | Context-aware, natural pacing |
|
|
87
|
+
| Reranking | `@cf/baai/bge-reranker-base` | Fast document reranking |
|
|
87
88
|
|
|
88
89
|
## Text Generation
|
|
89
90
|
|
|
@@ -91,7 +92,7 @@ Some good defaults:
|
|
|
91
92
|
import { generateText } from "ai";
|
|
92
93
|
|
|
93
94
|
const { text } = await generateText({
|
|
94
|
-
model: workersai("@cf/
|
|
95
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
95
96
|
prompt: "Explain Workers AI in one paragraph",
|
|
96
97
|
});
|
|
97
98
|
```
|
|
@@ -102,7 +103,7 @@ Streaming:
|
|
|
102
103
|
import { streamText } from "ai";
|
|
103
104
|
|
|
104
105
|
const result = streamText({
|
|
105
|
-
model: workersai("@cf/
|
|
106
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
106
107
|
messages: [{ role: "user", content: "Write a short story" }],
|
|
107
108
|
});
|
|
108
109
|
|
|
@@ -113,13 +114,13 @@ for await (const chunk of result.textStream) {
|
|
|
113
114
|
|
|
114
115
|
## Vision (Image Inputs)
|
|
115
116
|
|
|
116
|
-
Send images to vision-capable models like
|
|
117
|
+
Send images to vision-capable models like Kimi K2.5:
|
|
117
118
|
|
|
118
119
|
```ts
|
|
119
120
|
import { generateText } from "ai";
|
|
120
121
|
|
|
121
122
|
const { text } = await generateText({
|
|
122
|
-
model: workersai("@cf/
|
|
123
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
123
124
|
messages: [
|
|
124
125
|
{
|
|
125
126
|
role: "user",
|
|
@@ -141,7 +142,7 @@ import { generateText, stepCountIs } from "ai";
|
|
|
141
142
|
import { z } from "zod";
|
|
142
143
|
|
|
143
144
|
const { text } = await generateText({
|
|
144
|
-
model: workersai("@cf/
|
|
145
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
145
146
|
prompt: "What's the weather in London?",
|
|
146
147
|
tools: {
|
|
147
148
|
getWeather: {
|
|
@@ -161,7 +162,7 @@ import { generateText, Output } from "ai";
|
|
|
161
162
|
import { z } from "zod";
|
|
162
163
|
|
|
163
164
|
const { output } = await generateText({
|
|
164
|
-
model: workersai("@cf/
|
|
165
|
+
model: workersai("@cf/moonshotai/kimi-k2.5"),
|
|
165
166
|
prompt: "Recipe for spaghetti bolognese",
|
|
166
167
|
output: Output.object({
|
|
167
168
|
schema: z.object({
|
|
@@ -313,7 +314,7 @@ Streaming works the same way — use `streamText` instead of `generateText`.
|
|
|
313
314
|
Returns a provider with model factories. Each factory accepts an optional second argument for per-model settings:
|
|
314
315
|
|
|
315
316
|
```ts
|
|
316
|
-
workersai("@cf/
|
|
317
|
+
workersai("@cf/moonshotai/kimi-k2.5", {
|
|
317
318
|
sessionAffinity: "my-unique-session-id",
|
|
318
319
|
});
|
|
319
320
|
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ImageModelV3, LanguageModelV3, RerankingModelV3, SpeechModelV3, TranscriptionModelV3 } from "@ai-sdk/provider";
|
|
2
|
+
|
|
3
|
+
//#region src/aisearch-chat-settings.d.ts
|
|
4
|
+
type AISearchChatSettings = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to inject a safety prompt before all conversations.
|
|
7
|
+
* Defaults to `false`.
|
|
8
|
+
*/
|
|
9
|
+
safePrompt?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Passthrough settings that are provided directly to the run function.
|
|
12
|
+
*/
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/workersai-models.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* The names of the BaseAiTextGeneration models.
|
|
19
|
+
*
|
|
20
|
+
* Accepts any string at runtime, but provides autocomplete for known models.
|
|
21
|
+
*/
|
|
22
|
+
type TextGenerationModels = Exclude<value2key<AiModels, BaseAiTextGeneration>, value2key<AiModels, BaseAiTextToImage>> | (string & {});
|
|
23
|
+
type ImageGenerationModels = value2key<AiModels, BaseAiTextToImage> | (string & {});
|
|
24
|
+
/**
|
|
25
|
+
* The names of the BaseAiTextToEmbeddings models.
|
|
26
|
+
*
|
|
27
|
+
* Accepts any string at runtime, but provides autocomplete for known models.
|
|
28
|
+
*/
|
|
29
|
+
type EmbeddingModels = value2key<AiModels, BaseAiTextEmbeddings> | (string & {});
|
|
30
|
+
/**
|
|
31
|
+
* Workers AI models that support speech-to-text transcription.
|
|
32
|
+
*
|
|
33
|
+
* Includes Whisper variants from `@cloudflare/workers-types` plus
|
|
34
|
+
* Deepgram partner models that may not be in the typed interface yet.
|
|
35
|
+
* Accepts any string at runtime, but provides autocomplete for known models.
|
|
36
|
+
*/
|
|
37
|
+
type TranscriptionModels = value2key<AiModels, BaseAiAutomaticSpeechRecognition> | "@cf/deepgram/nova-3" | (string & {});
|
|
38
|
+
/**
|
|
39
|
+
* Workers AI models that support text-to-speech.
|
|
40
|
+
*
|
|
41
|
+
* Includes models from `@cloudflare/workers-types` plus Deepgram partner
|
|
42
|
+
* models that may not be in the typed interface yet.
|
|
43
|
+
* Accepts any string at runtime, but provides autocomplete for known models.
|
|
44
|
+
*/
|
|
45
|
+
type SpeechModels = value2key<AiModels, BaseAiTextToSpeech> | "@cf/deepgram/aura-1" | "@cf/deepgram/aura-2-en" | "@cf/deepgram/aura-2-es" | (string & {});
|
|
46
|
+
/**
|
|
47
|
+
* Workers AI models that support reranking.
|
|
48
|
+
*
|
|
49
|
+
* Accepts any string at runtime, but provides autocomplete for known models.
|
|
50
|
+
*/
|
|
51
|
+
type RerankingModels = "@cf/baai/bge-reranker-base" | "@cf/baai/bge-reranker-v2-m3" | (string & {});
|
|
52
|
+
type value2key<T, V> = { [K in keyof T]: T[K] extends V ? K : never }[keyof T];
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/aisearch-chat-language-model.d.ts
|
|
55
|
+
type AISearchChatConfig = {
|
|
56
|
+
provider: string;
|
|
57
|
+
binding: AutoRAG;
|
|
58
|
+
gateway?: GatewayOptions;
|
|
59
|
+
};
|
|
60
|
+
declare class AISearchChatLanguageModel implements LanguageModelV3 {
|
|
61
|
+
readonly specificationVersion = "v3";
|
|
62
|
+
readonly defaultObjectGenerationMode = "json";
|
|
63
|
+
readonly supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
64
|
+
readonly modelId: TextGenerationModels;
|
|
65
|
+
readonly settings: AISearchChatSettings;
|
|
66
|
+
private readonly config;
|
|
67
|
+
constructor(modelId: TextGenerationModels, settings: AISearchChatSettings, config: AISearchChatConfig);
|
|
68
|
+
get provider(): string;
|
|
69
|
+
private getWarnings;
|
|
70
|
+
/**
|
|
71
|
+
* Build the search query from messages.
|
|
72
|
+
* Flattens the conversation into a single string for aiSearch.
|
|
73
|
+
*/
|
|
74
|
+
private buildQuery;
|
|
75
|
+
doGenerate(options: Parameters<LanguageModelV3["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV3["doGenerate"]>>>;
|
|
76
|
+
doStream(options: Parameters<LanguageModelV3["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV3["doStream"]>>>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/workersai-embedding-model.d.ts
|
|
80
|
+
type WorkersAIEmbeddingConfig = {
|
|
81
|
+
provider: string;
|
|
82
|
+
binding: Ai;
|
|
83
|
+
gateway?: GatewayOptions;
|
|
84
|
+
};
|
|
85
|
+
type WorkersAIEmbeddingSettings = {
|
|
86
|
+
gateway?: GatewayOptions;
|
|
87
|
+
maxEmbeddingsPerCall?: number;
|
|
88
|
+
supportsParallelCalls?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Passthrough settings that are provided directly to the run function.
|
|
91
|
+
*/
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
};
|
|
94
|
+
declare class WorkersAIEmbeddingModel implements EmbeddingModelV3 {
|
|
95
|
+
readonly specificationVersion = "v3";
|
|
96
|
+
readonly modelId: EmbeddingModels;
|
|
97
|
+
private readonly config;
|
|
98
|
+
private readonly settings;
|
|
99
|
+
get provider(): string;
|
|
100
|
+
get maxEmbeddingsPerCall(): number;
|
|
101
|
+
get supportsParallelCalls(): boolean;
|
|
102
|
+
constructor(modelId: EmbeddingModels, settings: WorkersAIEmbeddingSettings, config: WorkersAIEmbeddingConfig);
|
|
103
|
+
doEmbed({
|
|
104
|
+
values,
|
|
105
|
+
abortSignal
|
|
106
|
+
}: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/workersai-chat-settings.d.ts
|
|
110
|
+
type WorkersAIChatSettings = {
|
|
111
|
+
/**
|
|
112
|
+
* Whether to inject a safety prompt before all conversations.
|
|
113
|
+
* Defaults to `false`.
|
|
114
|
+
*/
|
|
115
|
+
safePrompt?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Optionally set Cloudflare AI Gateway options.
|
|
118
|
+
*/
|
|
119
|
+
gateway?: GatewayOptions;
|
|
120
|
+
/**
|
|
121
|
+
* Session affinity key for prefix-cache optimization.
|
|
122
|
+
* Routes requests with the same key to the same backend replica.
|
|
123
|
+
*/
|
|
124
|
+
sessionAffinity?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Passthrough settings that are provided directly to the run function.
|
|
127
|
+
* Use this for any provider-specific options not covered by the typed fields.
|
|
128
|
+
*/
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/workersai-chat-language-model.d.ts
|
|
133
|
+
type WorkersAIChatConfig = {
|
|
134
|
+
provider: string;
|
|
135
|
+
binding: Ai;
|
|
136
|
+
gateway?: GatewayOptions; /** True when using a real Workers AI binding (not the REST shim). */
|
|
137
|
+
isBinding: boolean;
|
|
138
|
+
};
|
|
139
|
+
declare class WorkersAIChatLanguageModel implements LanguageModelV3 {
|
|
140
|
+
readonly specificationVersion = "v3";
|
|
141
|
+
readonly defaultObjectGenerationMode = "json";
|
|
142
|
+
readonly supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
143
|
+
readonly modelId: TextGenerationModels;
|
|
144
|
+
readonly settings: WorkersAIChatSettings;
|
|
145
|
+
private readonly config;
|
|
146
|
+
constructor(modelId: TextGenerationModels, settings: WorkersAIChatSettings, config: WorkersAIChatConfig);
|
|
147
|
+
get provider(): string;
|
|
148
|
+
private getArgs;
|
|
149
|
+
/**
|
|
150
|
+
* Build the inputs object for `binding.run()`, shared by doGenerate and doStream.
|
|
151
|
+
*
|
|
152
|
+
* Images are embedded inline in messages as OpenAI-compatible content
|
|
153
|
+
* arrays with `image_url` parts. Both the REST API and the binding
|
|
154
|
+
* accept this format at runtime.
|
|
155
|
+
*
|
|
156
|
+
* The binding path additionally normalises null content to empty strings.
|
|
157
|
+
*/
|
|
158
|
+
private buildRunInputs;
|
|
159
|
+
/**
|
|
160
|
+
* Get passthrough options for binding.run() from settings.
|
|
161
|
+
*/
|
|
162
|
+
private getRunOptions;
|
|
163
|
+
doGenerate(options: Parameters<LanguageModelV3["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV3["doGenerate"]>>>;
|
|
164
|
+
doStream(options: Parameters<LanguageModelV3["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV3["doStream"]>>>;
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/workersai-image-settings.d.ts
|
|
168
|
+
type WorkersAIImageSettings = {
|
|
169
|
+
maxImagesPerCall?: number;
|
|
170
|
+
};
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/workersai-image-model.d.ts
|
|
173
|
+
type WorkersAIImageConfig = {
|
|
174
|
+
provider: string;
|
|
175
|
+
binding: Ai;
|
|
176
|
+
gateway?: GatewayOptions;
|
|
177
|
+
};
|
|
178
|
+
declare class WorkersAIImageModel implements ImageModelV3 {
|
|
179
|
+
readonly modelId: ImageGenerationModels;
|
|
180
|
+
readonly settings: WorkersAIImageSettings;
|
|
181
|
+
readonly config: WorkersAIImageConfig;
|
|
182
|
+
readonly specificationVersion = "v3";
|
|
183
|
+
get maxImagesPerCall(): number;
|
|
184
|
+
get provider(): string;
|
|
185
|
+
constructor(modelId: ImageGenerationModels, settings: WorkersAIImageSettings, config: WorkersAIImageConfig);
|
|
186
|
+
doGenerate({
|
|
187
|
+
prompt,
|
|
188
|
+
n,
|
|
189
|
+
size,
|
|
190
|
+
aspectRatio,
|
|
191
|
+
seed,
|
|
192
|
+
abortSignal
|
|
193
|
+
}: Parameters<ImageModelV3["doGenerate"]>[0]): Promise<Awaited<ReturnType<ImageModelV3["doGenerate"]>>>;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/workersai-transcription-settings.d.ts
|
|
197
|
+
type WorkersAITranscriptionSettings = {
|
|
198
|
+
/**
|
|
199
|
+
* Language of the audio, as an ISO-639-1 code (e.g. "en", "fr").
|
|
200
|
+
* Only supported by Whisper models. Nova-3 detects language automatically.
|
|
201
|
+
*/
|
|
202
|
+
language?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Initial prompt / context to guide the transcription.
|
|
205
|
+
* Mapped to `initial_prompt` for Whisper models.
|
|
206
|
+
*/
|
|
207
|
+
prompt?: string;
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/utils.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Parameters for configuring the Cloudflare-based AI runner.
|
|
213
|
+
*/
|
|
214
|
+
interface CreateRunConfig {
|
|
215
|
+
/** Your Cloudflare account identifier. */
|
|
216
|
+
accountId: string;
|
|
217
|
+
/** Cloudflare API token/key with appropriate permissions. */
|
|
218
|
+
apiKey: string;
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/workersai-transcription-model.d.ts
|
|
222
|
+
type WorkersAITranscriptionConfig = {
|
|
223
|
+
provider: string;
|
|
224
|
+
binding: Ai;
|
|
225
|
+
gateway?: GatewayOptions;
|
|
226
|
+
/**
|
|
227
|
+
* Whether the binding is a real `env.AI` binding (true) or a REST shim (false).
|
|
228
|
+
* Nova-3 uses different upload paths depending on this.
|
|
229
|
+
*/
|
|
230
|
+
isBinding: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* REST credentials, only set when `isBinding` is false.
|
|
233
|
+
* Needed for Nova-3 which requires binary upload, bypassing the JSON-based REST shim.
|
|
234
|
+
*/
|
|
235
|
+
credentials?: CreateRunConfig;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Workers AI transcription model implementing the AI SDK's `TranscriptionModelV3` interface.
|
|
239
|
+
*
|
|
240
|
+
* Supports:
|
|
241
|
+
* - Whisper models (`@cf/openai/whisper`, `whisper-tiny-en`, `whisper-large-v3-turbo`)
|
|
242
|
+
* - Deepgram Nova-3 (`@cf/deepgram/nova-3`) — uses a different input/output format
|
|
243
|
+
*/
|
|
244
|
+
declare class WorkersAITranscriptionModel implements TranscriptionModelV3 {
|
|
245
|
+
readonly modelId: TranscriptionModels;
|
|
246
|
+
readonly settings: WorkersAITranscriptionSettings;
|
|
247
|
+
readonly config: WorkersAITranscriptionConfig;
|
|
248
|
+
readonly specificationVersion = "v3";
|
|
249
|
+
get provider(): string;
|
|
250
|
+
constructor(modelId: TranscriptionModels, settings: WorkersAITranscriptionSettings, config: WorkersAITranscriptionConfig);
|
|
251
|
+
doGenerate(options: Parameters<TranscriptionModelV3["doGenerate"]>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3["doGenerate"]>>>;
|
|
252
|
+
private runWhisper;
|
|
253
|
+
private normalizeWhisperResponse;
|
|
254
|
+
private runNova3;
|
|
255
|
+
private normalizeNova3Response;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/workersai-speech-settings.d.ts
|
|
259
|
+
type WorkersAISpeechSettings = {};
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/workersai-speech-model.d.ts
|
|
262
|
+
type WorkersAISpeechConfig = {
|
|
263
|
+
provider: string;
|
|
264
|
+
binding: Ai;
|
|
265
|
+
gateway?: GatewayOptions;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Workers AI speech (text-to-speech) model implementing the AI SDK's `SpeechModelV3` interface.
|
|
269
|
+
*
|
|
270
|
+
* Currently supports Deepgram Aura-1 (`@cf/deepgram/aura-1`).
|
|
271
|
+
* The model accepts `{ text, voice?, speed? }` and returns raw audio bytes.
|
|
272
|
+
*/
|
|
273
|
+
declare class WorkersAISpeechModel implements SpeechModelV3 {
|
|
274
|
+
readonly modelId: SpeechModels;
|
|
275
|
+
readonly settings: WorkersAISpeechSettings;
|
|
276
|
+
readonly config: WorkersAISpeechConfig;
|
|
277
|
+
readonly specificationVersion = "v3";
|
|
278
|
+
get provider(): string;
|
|
279
|
+
constructor(modelId: SpeechModels, settings: WorkersAISpeechSettings, config: WorkersAISpeechConfig);
|
|
280
|
+
doGenerate(options: Parameters<SpeechModelV3["doGenerate"]>[0]): Promise<Awaited<ReturnType<SpeechModelV3["doGenerate"]>>>;
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/workersai-reranking-settings.d.ts
|
|
284
|
+
type WorkersAIRerankingSettings = {};
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/workersai-reranking-model.d.ts
|
|
287
|
+
type WorkersAIRerankingConfig = {
|
|
288
|
+
provider: string;
|
|
289
|
+
binding: Ai;
|
|
290
|
+
gateway?: GatewayOptions;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Workers AI reranking model implementing the AI SDK's `RerankingModelV3` interface.
|
|
294
|
+
*
|
|
295
|
+
* Supports BGE reranker models (`@cf/baai/bge-reranker-base`, `bge-reranker-v2-m3`).
|
|
296
|
+
*
|
|
297
|
+
* Workers AI reranking API:
|
|
298
|
+
* - Input: `{ query, contexts: [{ text }], top_k? }`
|
|
299
|
+
* - Output: `{ response: [{ id, score }] }`
|
|
300
|
+
*/
|
|
301
|
+
declare class WorkersAIRerankingModel implements RerankingModelV3 {
|
|
302
|
+
readonly modelId: RerankingModels;
|
|
303
|
+
readonly settings: WorkersAIRerankingSettings;
|
|
304
|
+
readonly config: WorkersAIRerankingConfig;
|
|
305
|
+
readonly specificationVersion = "v3";
|
|
306
|
+
get provider(): string;
|
|
307
|
+
constructor(modelId: RerankingModels, settings: WorkersAIRerankingSettings, config: WorkersAIRerankingConfig);
|
|
308
|
+
doRerank(options: Parameters<RerankingModelV3["doRerank"]>[0]): Promise<Awaited<ReturnType<RerankingModelV3["doRerank"]>>>;
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/autorag-chat-language-model.d.ts
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Use `AISearchChatLanguageModel` instead. AutoRAG has been renamed to AI Search.
|
|
314
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
315
|
+
*/
|
|
316
|
+
declare class AutoRAGChatLanguageModel extends AISearchChatLanguageModel {}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/autorag-chat-settings.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* @deprecated Use `AISearchChatSettings` instead. AutoRAG has been renamed to AI Search.
|
|
321
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
322
|
+
*/
|
|
323
|
+
type AutoRAGChatSettings = AISearchChatSettings;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/index.d.ts
|
|
326
|
+
type WorkersAISettings = ({
|
|
327
|
+
/**
|
|
328
|
+
* Provide a Cloudflare AI binding.
|
|
329
|
+
*/
|
|
330
|
+
binding: Ai;
|
|
331
|
+
/**
|
|
332
|
+
* Credentials must be absent when a binding is given.
|
|
333
|
+
*/
|
|
334
|
+
accountId?: never;
|
|
335
|
+
apiKey?: never;
|
|
336
|
+
} | {
|
|
337
|
+
/**
|
|
338
|
+
* Provide Cloudflare API credentials directly. Must be used if a binding is not specified.
|
|
339
|
+
*/
|
|
340
|
+
accountId: string;
|
|
341
|
+
apiKey: string;
|
|
342
|
+
/**
|
|
343
|
+
* Both binding must be absent if credentials are used directly.
|
|
344
|
+
*/
|
|
345
|
+
binding?: never;
|
|
346
|
+
}) & {
|
|
347
|
+
/**
|
|
348
|
+
* Optionally specify a gateway.
|
|
349
|
+
*/
|
|
350
|
+
gateway?: GatewayOptions;
|
|
351
|
+
};
|
|
352
|
+
interface WorkersAI {
|
|
353
|
+
(modelId: TextGenerationModels, settings?: WorkersAIChatSettings): WorkersAIChatLanguageModel;
|
|
354
|
+
/**
|
|
355
|
+
* Creates a model for text generation.
|
|
356
|
+
**/
|
|
357
|
+
chat(modelId: TextGenerationModels, settings?: WorkersAIChatSettings): WorkersAIChatLanguageModel;
|
|
358
|
+
embedding(modelId: EmbeddingModels, settings?: WorkersAIEmbeddingSettings): WorkersAIEmbeddingModel;
|
|
359
|
+
textEmbedding(modelId: EmbeddingModels, settings?: WorkersAIEmbeddingSettings): WorkersAIEmbeddingModel;
|
|
360
|
+
textEmbeddingModel(modelId: EmbeddingModels, settings?: WorkersAIEmbeddingSettings): WorkersAIEmbeddingModel;
|
|
361
|
+
/**
|
|
362
|
+
* Creates a model for image generation.
|
|
363
|
+
**/
|
|
364
|
+
image(modelId: ImageGenerationModels, settings?: WorkersAIImageSettings): WorkersAIImageModel;
|
|
365
|
+
imageModel(modelId: ImageGenerationModels, settings?: WorkersAIImageSettings): WorkersAIImageModel;
|
|
366
|
+
/**
|
|
367
|
+
* Creates a model for speech-to-text transcription.
|
|
368
|
+
**/
|
|
369
|
+
transcription(modelId: TranscriptionModels, settings?: WorkersAITranscriptionSettings): WorkersAITranscriptionModel;
|
|
370
|
+
transcriptionModel(modelId: TranscriptionModels, settings?: WorkersAITranscriptionSettings): WorkersAITranscriptionModel;
|
|
371
|
+
/**
|
|
372
|
+
* Creates a model for text-to-speech synthesis.
|
|
373
|
+
**/
|
|
374
|
+
speech(modelId: SpeechModels, settings?: WorkersAISpeechSettings): WorkersAISpeechModel;
|
|
375
|
+
speechModel(modelId: SpeechModels, settings?: WorkersAISpeechSettings): WorkersAISpeechModel;
|
|
376
|
+
/**
|
|
377
|
+
* Creates a model for document reranking.
|
|
378
|
+
**/
|
|
379
|
+
reranking(modelId: RerankingModels, settings?: WorkersAIRerankingSettings): WorkersAIRerankingModel;
|
|
380
|
+
rerankingModel(modelId: RerankingModels, settings?: WorkersAIRerankingSettings): WorkersAIRerankingModel;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Create a Workers AI provider instance.
|
|
384
|
+
*/
|
|
385
|
+
declare function createWorkersAI(options: WorkersAISettings): WorkersAI;
|
|
386
|
+
type AISearchSettings = {
|
|
387
|
+
binding: AutoRAG;
|
|
388
|
+
};
|
|
389
|
+
interface AISearchProvider {
|
|
390
|
+
(settings?: AISearchChatSettings): AISearchChatLanguageModel;
|
|
391
|
+
/**
|
|
392
|
+
* Creates a model for text generation.
|
|
393
|
+
**/
|
|
394
|
+
chat(settings?: AISearchChatSettings): AISearchChatLanguageModel;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Create an AI Search provider instance.
|
|
398
|
+
*
|
|
399
|
+
* AI Search (formerly AutoRAG) is Cloudflare's managed search service.
|
|
400
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
401
|
+
*/
|
|
402
|
+
declare function createAISearch(options: AISearchSettings, /** @internal */
|
|
403
|
+
|
|
404
|
+
providerName?: string): AISearchProvider;
|
|
405
|
+
/**
|
|
406
|
+
* @deprecated Use `AISearchSettings` instead. AutoRAG has been renamed to AI Search.
|
|
407
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
408
|
+
*/
|
|
409
|
+
type AutoRAGSettings = AISearchSettings;
|
|
410
|
+
/**
|
|
411
|
+
* @deprecated Use `AISearchProvider` instead. AutoRAG has been renamed to AI Search.
|
|
412
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
413
|
+
*/
|
|
414
|
+
type AutoRAGProvider = AISearchProvider;
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated Use `createAISearch` instead. AutoRAG has been renamed to AI Search.
|
|
417
|
+
* @see https://developers.cloudflare.com/ai-search/
|
|
418
|
+
*/
|
|
419
|
+
declare function createAutoRAG(options: AISearchSettings): AISearchProvider;
|
|
420
|
+
//#endregion
|
|
421
|
+
export { AISearchChatLanguageModel, type AISearchChatSettings, AISearchProvider, AISearchSettings, AutoRAGChatLanguageModel, type AutoRAGChatSettings, AutoRAGProvider, AutoRAGSettings, WorkersAI, WorkersAIRerankingModel, type WorkersAIRerankingSettings, WorkersAISettings, WorkersAISpeechModel, type WorkersAISpeechSettings, WorkersAITranscriptionModel, type WorkersAITranscriptionSettings, createAISearch, createAutoRAG, createWorkersAI };
|
|
422
|
+
//# sourceMappingURL=index.d.mts.map
|