@ai-sdk/alibaba 0.0.0-6b196531-20260710185421
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 +775 -0
- package/LICENSE +13 -0
- package/README.md +151 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.js +1380 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
- package/src/alibaba-chat-language-model-options.ts +56 -0
- package/src/alibaba-chat-language-model.ts +568 -0
- package/src/alibaba-chat-prompt.ts +67 -0
- package/src/alibaba-config.ts +9 -0
- package/src/alibaba-embedding-model-options.ts +33 -0
- package/src/alibaba-embedding-model.ts +178 -0
- package/src/alibaba-error.ts +17 -0
- package/src/alibaba-provider.ts +187 -0
- package/src/alibaba-video-model-options.ts +77 -0
- package/src/alibaba-video-model.ts +587 -0
- package/src/alibaba-video-settings.ts +16 -0
- package/src/convert-alibaba-usage.ts +37 -0
- package/src/convert-to-alibaba-chat-messages.ts +220 -0
- package/src/get-cache-control.ts +49 -0
- package/src/index.ts +27 -0
- package/src/version.ts +6 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
// src/alibaba-provider.ts
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
10
|
+
|
|
11
|
+
// src/alibaba-chat-language-model.ts
|
|
12
|
+
import {
|
|
13
|
+
getResponseMetadata,
|
|
14
|
+
mapOpenAICompatibleFinishReason,
|
|
15
|
+
prepareTools
|
|
16
|
+
} from "@ai-sdk/openai-compatible/internal";
|
|
17
|
+
import {
|
|
18
|
+
combineHeaders,
|
|
19
|
+
createEventSourceResponseHandler,
|
|
20
|
+
createJsonResponseHandler,
|
|
21
|
+
generateId,
|
|
22
|
+
isCustomReasoning,
|
|
23
|
+
mapReasoningToProviderBudget,
|
|
24
|
+
parseProviderOptions,
|
|
25
|
+
postJsonToApi,
|
|
26
|
+
serializeModelOptions,
|
|
27
|
+
StreamingToolCallTracker,
|
|
28
|
+
WORKFLOW_SERIALIZE,
|
|
29
|
+
WORKFLOW_DESERIALIZE
|
|
30
|
+
} from "@ai-sdk/provider-utils";
|
|
31
|
+
import { z as z3 } from "zod/v4";
|
|
32
|
+
|
|
33
|
+
// src/alibaba-chat-language-model-options.ts
|
|
34
|
+
import { z } from "zod/v4";
|
|
35
|
+
var alibabaLanguageModelChatOptions = z.object({
|
|
36
|
+
/**
|
|
37
|
+
* Enable thinking/reasoning mode for supported models.
|
|
38
|
+
* When enabled, the model generates reasoning content before the response.
|
|
39
|
+
*
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
enableThinking: z.boolean().optional(),
|
|
43
|
+
/**
|
|
44
|
+
* Maximum number of reasoning tokens to generate.
|
|
45
|
+
*/
|
|
46
|
+
thinkingBudget: z.number().positive().optional(),
|
|
47
|
+
/**
|
|
48
|
+
* Whether to enable parallel function calling during tool use.
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
parallelToolCalls: z.boolean().optional()
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/alibaba-error.ts
|
|
56
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
57
|
+
import { z as z2 } from "zod/v4";
|
|
58
|
+
var alibabaErrorDataSchema = z2.object({
|
|
59
|
+
error: z2.object({
|
|
60
|
+
message: z2.string(),
|
|
61
|
+
code: z2.string().nullish(),
|
|
62
|
+
type: z2.string().nullish()
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
var alibabaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
66
|
+
errorSchema: alibabaErrorDataSchema,
|
|
67
|
+
errorToMessage: (data) => data.error.message
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// src/convert-alibaba-usage.ts
|
|
71
|
+
import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
|
|
72
|
+
function convertAlibabaUsage(usage) {
|
|
73
|
+
var _a, _b, _c, _d;
|
|
74
|
+
const baseUsage = convertOpenAICompatibleChatUsage(usage);
|
|
75
|
+
const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
|
|
76
|
+
const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
|
|
77
|
+
return {
|
|
78
|
+
...baseUsage,
|
|
79
|
+
inputTokens: {
|
|
80
|
+
...baseUsage.inputTokens,
|
|
81
|
+
cacheWrite: cacheWriteTokens,
|
|
82
|
+
noCache: noCacheTokens
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/convert-to-alibaba-chat-messages.ts
|
|
88
|
+
import {
|
|
89
|
+
UnsupportedFunctionalityError
|
|
90
|
+
} from "@ai-sdk/provider";
|
|
91
|
+
import {
|
|
92
|
+
convertToBase64,
|
|
93
|
+
getTopLevelMediaType,
|
|
94
|
+
resolveFullMediaType
|
|
95
|
+
} from "@ai-sdk/provider-utils";
|
|
96
|
+
function formatImageUrl({ part }) {
|
|
97
|
+
if (part.data.type === "url") {
|
|
98
|
+
return part.data.url.toString();
|
|
99
|
+
}
|
|
100
|
+
if (part.data.type === "data") {
|
|
101
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
102
|
+
}
|
|
103
|
+
throw new UnsupportedFunctionalityError({
|
|
104
|
+
functionality: `file part data type ${part.data.type}`
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function convertToAlibabaChatMessages({
|
|
108
|
+
prompt,
|
|
109
|
+
cacheControlValidator
|
|
110
|
+
}) {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
const messages = [];
|
|
113
|
+
for (const { role, content, ...message } of prompt) {
|
|
114
|
+
const messageCacheControl = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
|
|
115
|
+
message.providerOptions
|
|
116
|
+
);
|
|
117
|
+
switch (role) {
|
|
118
|
+
case "system": {
|
|
119
|
+
if (messageCacheControl) {
|
|
120
|
+
messages.push({
|
|
121
|
+
role: "system",
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: "text",
|
|
125
|
+
text: content,
|
|
126
|
+
cache_control: messageCacheControl
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
messages.push({ role: "system", content });
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case "user": {
|
|
136
|
+
messages.push({
|
|
137
|
+
role: "user",
|
|
138
|
+
content: content.map((part, index) => {
|
|
139
|
+
var _a2;
|
|
140
|
+
const isLastPart = index === content.length - 1;
|
|
141
|
+
const partCacheControl = (_a2 = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions)) != null ? _a2 : isLastPart ? messageCacheControl : void 0;
|
|
142
|
+
switch (part.type) {
|
|
143
|
+
case "text": {
|
|
144
|
+
return {
|
|
145
|
+
type: "text",
|
|
146
|
+
text: part.text,
|
|
147
|
+
...partCacheControl ? { cache_control: partCacheControl } : {}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case "file": {
|
|
151
|
+
switch (part.data.type) {
|
|
152
|
+
case "reference": {
|
|
153
|
+
throw new UnsupportedFunctionalityError({
|
|
154
|
+
functionality: "file parts with provider references"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
case "text": {
|
|
158
|
+
throw new UnsupportedFunctionalityError({
|
|
159
|
+
functionality: "text file parts"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
case "url":
|
|
163
|
+
case "data": {
|
|
164
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
165
|
+
return {
|
|
166
|
+
type: "image_url",
|
|
167
|
+
image_url: {
|
|
168
|
+
url: formatImageUrl({ part })
|
|
169
|
+
},
|
|
170
|
+
...partCacheControl ? { cache_control: partCacheControl } : {}
|
|
171
|
+
};
|
|
172
|
+
} else {
|
|
173
|
+
throw new UnsupportedFunctionalityError({
|
|
174
|
+
functionality: "Only image file parts are supported"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "assistant": {
|
|
186
|
+
let text = "";
|
|
187
|
+
const toolCalls = [];
|
|
188
|
+
for (const part of content) {
|
|
189
|
+
switch (part.type) {
|
|
190
|
+
case "text": {
|
|
191
|
+
text += part.text;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case "tool-call": {
|
|
195
|
+
toolCalls.push({
|
|
196
|
+
id: part.toolCallId,
|
|
197
|
+
type: "function",
|
|
198
|
+
function: {
|
|
199
|
+
name: part.toolName,
|
|
200
|
+
arguments: JSON.stringify(part.input)
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "reasoning": {
|
|
206
|
+
text += part.text;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
messages.push({
|
|
212
|
+
role: "assistant",
|
|
213
|
+
content: messageCacheControl ? [{ type: "text", text, cache_control: messageCacheControl }] : text || null,
|
|
214
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
215
|
+
});
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case "tool": {
|
|
219
|
+
const toolResponses = content.filter(
|
|
220
|
+
(r) => r.type !== "tool-approval-response"
|
|
221
|
+
);
|
|
222
|
+
for (let i = 0; i < toolResponses.length; i++) {
|
|
223
|
+
const toolResponse = toolResponses[i];
|
|
224
|
+
const output = toolResponse.output;
|
|
225
|
+
const isLastPart = i === toolResponses.length - 1;
|
|
226
|
+
const partCacheControl = (_a = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
|
|
227
|
+
toolResponse.providerOptions
|
|
228
|
+
)) != null ? _a : isLastPart ? messageCacheControl : void 0;
|
|
229
|
+
let contentValue;
|
|
230
|
+
switch (output.type) {
|
|
231
|
+
case "text":
|
|
232
|
+
case "error-text":
|
|
233
|
+
contentValue = output.value;
|
|
234
|
+
break;
|
|
235
|
+
case "execution-denied":
|
|
236
|
+
contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
|
|
237
|
+
break;
|
|
238
|
+
case "content":
|
|
239
|
+
case "json":
|
|
240
|
+
case "error-json":
|
|
241
|
+
contentValue = JSON.stringify(output.value);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
messages.push({
|
|
245
|
+
role: "tool",
|
|
246
|
+
tool_call_id: toolResponse.toolCallId,
|
|
247
|
+
content: partCacheControl ? [
|
|
248
|
+
{
|
|
249
|
+
type: "text",
|
|
250
|
+
text: contentValue,
|
|
251
|
+
cache_control: partCacheControl
|
|
252
|
+
}
|
|
253
|
+
] : contentValue
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
default: {
|
|
259
|
+
const _exhaustiveCheck = role;
|
|
260
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return messages;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/get-cache-control.ts
|
|
268
|
+
var MAX_CACHE_BREAKPOINTS = 4;
|
|
269
|
+
function getCacheControl(providerMetadata) {
|
|
270
|
+
var _a;
|
|
271
|
+
const alibaba2 = providerMetadata == null ? void 0 : providerMetadata.alibaba;
|
|
272
|
+
const cacheControlValue = (_a = alibaba2 == null ? void 0 : alibaba2.cacheControl) != null ? _a : alibaba2 == null ? void 0 : alibaba2.cache_control;
|
|
273
|
+
return cacheControlValue;
|
|
274
|
+
}
|
|
275
|
+
var CacheControlValidator = class {
|
|
276
|
+
constructor() {
|
|
277
|
+
this.breakpointCount = 0;
|
|
278
|
+
this.warnings = [];
|
|
279
|
+
}
|
|
280
|
+
getCacheControl(providerMetadata) {
|
|
281
|
+
const cacheControlValue = getCacheControl(providerMetadata);
|
|
282
|
+
if (!cacheControlValue) {
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
this.breakpointCount++;
|
|
286
|
+
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
287
|
+
this.warnings.push({
|
|
288
|
+
type: "other",
|
|
289
|
+
message: `Max breakpoint limit exceeded. Only the last ${MAX_CACHE_BREAKPOINTS} cache markers will take effect.`
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return cacheControlValue;
|
|
293
|
+
}
|
|
294
|
+
getWarnings() {
|
|
295
|
+
return this.warnings;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/alibaba-chat-language-model.ts
|
|
300
|
+
var AlibabaChatLanguageModel = class _AlibabaChatLanguageModel {
|
|
301
|
+
constructor(modelId, config) {
|
|
302
|
+
this.specificationVersion = "v4";
|
|
303
|
+
this.supportedUrls = {
|
|
304
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
305
|
+
};
|
|
306
|
+
this.modelId = modelId;
|
|
307
|
+
this.config = config;
|
|
308
|
+
}
|
|
309
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
310
|
+
return serializeModelOptions({
|
|
311
|
+
modelId: model.modelId,
|
|
312
|
+
config: model.config
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
316
|
+
return new _AlibabaChatLanguageModel(options.modelId, options.config);
|
|
317
|
+
}
|
|
318
|
+
get provider() {
|
|
319
|
+
return this.config.provider;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Builds request arguments for Alibaba API call.
|
|
323
|
+
* Converts AI SDK options to Alibaba API format.
|
|
324
|
+
*/
|
|
325
|
+
async getArgs({
|
|
326
|
+
prompt,
|
|
327
|
+
maxOutputTokens,
|
|
328
|
+
temperature,
|
|
329
|
+
topP,
|
|
330
|
+
topK,
|
|
331
|
+
frequencyPenalty,
|
|
332
|
+
presencePenalty,
|
|
333
|
+
stopSequences,
|
|
334
|
+
responseFormat,
|
|
335
|
+
seed,
|
|
336
|
+
reasoning,
|
|
337
|
+
providerOptions,
|
|
338
|
+
tools,
|
|
339
|
+
toolChoice
|
|
340
|
+
}) {
|
|
341
|
+
var _a;
|
|
342
|
+
const warnings = [];
|
|
343
|
+
const cacheControlValidator = new CacheControlValidator();
|
|
344
|
+
const alibabaOptions = await parseProviderOptions({
|
|
345
|
+
provider: "alibaba",
|
|
346
|
+
providerOptions,
|
|
347
|
+
schema: alibabaLanguageModelChatOptions
|
|
348
|
+
});
|
|
349
|
+
if (frequencyPenalty != null) {
|
|
350
|
+
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
351
|
+
}
|
|
352
|
+
const baseArgs = {
|
|
353
|
+
model: this.modelId,
|
|
354
|
+
max_tokens: maxOutputTokens,
|
|
355
|
+
temperature,
|
|
356
|
+
top_p: topP,
|
|
357
|
+
top_k: topK,
|
|
358
|
+
presence_penalty: presencePenalty,
|
|
359
|
+
stop: stopSequences,
|
|
360
|
+
seed,
|
|
361
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
362
|
+
type: "json_schema",
|
|
363
|
+
json_schema: {
|
|
364
|
+
schema: responseFormat.schema,
|
|
365
|
+
name: (_a = responseFormat.name) != null ? _a : "response",
|
|
366
|
+
description: responseFormat.description
|
|
367
|
+
}
|
|
368
|
+
} : { type: "json_object" } : void 0,
|
|
369
|
+
...resolveAlibabaThinking({
|
|
370
|
+
reasoning,
|
|
371
|
+
alibabaOptions,
|
|
372
|
+
warnings
|
|
373
|
+
}),
|
|
374
|
+
// Convert messages with cache control support
|
|
375
|
+
messages: convertToAlibabaChatMessages({
|
|
376
|
+
prompt,
|
|
377
|
+
cacheControlValidator
|
|
378
|
+
})
|
|
379
|
+
};
|
|
380
|
+
const {
|
|
381
|
+
tools: alibabaTools,
|
|
382
|
+
toolChoice: alibabaToolChoice,
|
|
383
|
+
toolWarnings
|
|
384
|
+
} = prepareTools({ tools, toolChoice });
|
|
385
|
+
warnings.push(...cacheControlValidator.getWarnings());
|
|
386
|
+
return {
|
|
387
|
+
args: {
|
|
388
|
+
...baseArgs,
|
|
389
|
+
tools: alibabaTools,
|
|
390
|
+
tool_choice: alibabaToolChoice,
|
|
391
|
+
...alibabaTools != null && (alibabaOptions == null ? void 0 : alibabaOptions.parallelToolCalls) !== void 0 ? { parallel_tool_calls: alibabaOptions.parallelToolCalls } : {}
|
|
392
|
+
},
|
|
393
|
+
warnings: [...warnings, ...toolWarnings]
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
async doGenerate(options) {
|
|
397
|
+
var _a, _b, _c, _d;
|
|
398
|
+
const { args, warnings } = await this.getArgs(options);
|
|
399
|
+
const {
|
|
400
|
+
responseHeaders,
|
|
401
|
+
value: response,
|
|
402
|
+
rawValue: rawResponse
|
|
403
|
+
} = await postJsonToApi({
|
|
404
|
+
url: `${this.config.baseURL}/chat/completions`,
|
|
405
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
406
|
+
body: args,
|
|
407
|
+
failedResponseHandler: alibabaFailedResponseHandler,
|
|
408
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
409
|
+
alibabaChatResponseSchema
|
|
410
|
+
),
|
|
411
|
+
abortSignal: options.abortSignal,
|
|
412
|
+
fetch: this.config.fetch
|
|
413
|
+
});
|
|
414
|
+
const choice = response.choices[0];
|
|
415
|
+
const content = [];
|
|
416
|
+
const text = choice.message.content;
|
|
417
|
+
if (text != null && text.length > 0) {
|
|
418
|
+
content.push({ type: "text", text });
|
|
419
|
+
}
|
|
420
|
+
const reasoning = choice.message.reasoning_content;
|
|
421
|
+
if (reasoning != null && reasoning.length > 0) {
|
|
422
|
+
content.push({
|
|
423
|
+
type: "reasoning",
|
|
424
|
+
text: reasoning
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
if (choice.message.tool_calls != null) {
|
|
428
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
429
|
+
content.push({
|
|
430
|
+
type: "tool-call",
|
|
431
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
432
|
+
toolName: toolCall.function.name,
|
|
433
|
+
input: toolCall.function.arguments
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
content,
|
|
439
|
+
finishReason: {
|
|
440
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
441
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
442
|
+
},
|
|
443
|
+
usage: convertAlibabaUsage(response.usage),
|
|
444
|
+
request: { body: JSON.stringify(args) },
|
|
445
|
+
response: {
|
|
446
|
+
...getResponseMetadata(response),
|
|
447
|
+
headers: responseHeaders,
|
|
448
|
+
body: rawResponse
|
|
449
|
+
},
|
|
450
|
+
warnings
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
async doStream(options) {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
const { args, warnings } = await this.getArgs(options);
|
|
456
|
+
const body = {
|
|
457
|
+
...args,
|
|
458
|
+
stream: true,
|
|
459
|
+
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
460
|
+
};
|
|
461
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
462
|
+
url: `${this.config.baseURL}/chat/completions`,
|
|
463
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
464
|
+
body,
|
|
465
|
+
failedResponseHandler: alibabaFailedResponseHandler,
|
|
466
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
467
|
+
alibabaChatChunkSchema
|
|
468
|
+
),
|
|
469
|
+
abortSignal: options.abortSignal,
|
|
470
|
+
fetch: this.config.fetch
|
|
471
|
+
});
|
|
472
|
+
let finishReason = {
|
|
473
|
+
unified: "other",
|
|
474
|
+
raw: void 0
|
|
475
|
+
};
|
|
476
|
+
let usage = void 0;
|
|
477
|
+
let isFirstChunk = true;
|
|
478
|
+
let activeText = false;
|
|
479
|
+
let activeReasoningId = null;
|
|
480
|
+
let toolCallTracker;
|
|
481
|
+
return {
|
|
482
|
+
stream: response.pipeThrough(
|
|
483
|
+
new TransformStream({
|
|
484
|
+
start(controller) {
|
|
485
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
486
|
+
generateId
|
|
487
|
+
});
|
|
488
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
489
|
+
},
|
|
490
|
+
transform(chunk, controller) {
|
|
491
|
+
if (options.includeRawChunks) {
|
|
492
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
493
|
+
}
|
|
494
|
+
if (!chunk.success) {
|
|
495
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const value = chunk.value;
|
|
499
|
+
if (isFirstChunk) {
|
|
500
|
+
isFirstChunk = false;
|
|
501
|
+
controller.enqueue({
|
|
502
|
+
type: "response-metadata",
|
|
503
|
+
...getResponseMetadata(value)
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
if (value.usage != null) {
|
|
507
|
+
usage = value.usage;
|
|
508
|
+
}
|
|
509
|
+
if (value.choices.length === 0) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const choice = value.choices[0];
|
|
513
|
+
const delta = choice.delta;
|
|
514
|
+
if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
|
|
515
|
+
if (activeReasoningId == null) {
|
|
516
|
+
if (activeText) {
|
|
517
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
518
|
+
activeText = false;
|
|
519
|
+
}
|
|
520
|
+
activeReasoningId = generateId();
|
|
521
|
+
controller.enqueue({
|
|
522
|
+
type: "reasoning-start",
|
|
523
|
+
id: activeReasoningId
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
controller.enqueue({
|
|
527
|
+
type: "reasoning-delta",
|
|
528
|
+
id: activeReasoningId,
|
|
529
|
+
delta: delta.reasoning_content
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
533
|
+
if (activeReasoningId != null) {
|
|
534
|
+
controller.enqueue({
|
|
535
|
+
type: "reasoning-end",
|
|
536
|
+
id: activeReasoningId
|
|
537
|
+
});
|
|
538
|
+
activeReasoningId = null;
|
|
539
|
+
}
|
|
540
|
+
if (!activeText) {
|
|
541
|
+
controller.enqueue({ type: "text-start", id: "0" });
|
|
542
|
+
activeText = true;
|
|
543
|
+
}
|
|
544
|
+
controller.enqueue({
|
|
545
|
+
type: "text-delta",
|
|
546
|
+
id: "0",
|
|
547
|
+
delta: delta.content
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
if (delta.tool_calls != null) {
|
|
551
|
+
if (activeReasoningId != null) {
|
|
552
|
+
controller.enqueue({
|
|
553
|
+
type: "reasoning-end",
|
|
554
|
+
id: activeReasoningId
|
|
555
|
+
});
|
|
556
|
+
activeReasoningId = null;
|
|
557
|
+
}
|
|
558
|
+
if (activeText) {
|
|
559
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
560
|
+
activeText = false;
|
|
561
|
+
}
|
|
562
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
563
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (choice.finish_reason != null) {
|
|
567
|
+
finishReason = {
|
|
568
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
569
|
+
raw: choice.finish_reason
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
flush(controller) {
|
|
574
|
+
if (activeReasoningId != null) {
|
|
575
|
+
controller.enqueue({
|
|
576
|
+
type: "reasoning-end",
|
|
577
|
+
id: activeReasoningId
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (activeText) {
|
|
581
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
582
|
+
}
|
|
583
|
+
toolCallTracker.flush();
|
|
584
|
+
controller.enqueue({
|
|
585
|
+
type: "finish",
|
|
586
|
+
finishReason,
|
|
587
|
+
usage: convertAlibabaUsage(usage)
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
})
|
|
591
|
+
),
|
|
592
|
+
request: { body: JSON.stringify(body) },
|
|
593
|
+
response: { headers: responseHeaders }
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
function resolveAlibabaThinking({
|
|
598
|
+
reasoning,
|
|
599
|
+
alibabaOptions,
|
|
600
|
+
warnings
|
|
601
|
+
}) {
|
|
602
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null || (alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null) {
|
|
603
|
+
return {
|
|
604
|
+
...alibabaOptions.enableThinking != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
|
|
605
|
+
...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
if (!isCustomReasoning(reasoning)) {
|
|
609
|
+
return {};
|
|
610
|
+
}
|
|
611
|
+
if (reasoning === "none") {
|
|
612
|
+
return { enable_thinking: false };
|
|
613
|
+
}
|
|
614
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
615
|
+
reasoning,
|
|
616
|
+
maxOutputTokens: 16384,
|
|
617
|
+
maxReasoningBudget: 16384,
|
|
618
|
+
warnings
|
|
619
|
+
});
|
|
620
|
+
return {
|
|
621
|
+
enable_thinking: true,
|
|
622
|
+
...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
var alibabaUsageSchema = z3.object({
|
|
626
|
+
prompt_tokens: z3.number(),
|
|
627
|
+
completion_tokens: z3.number(),
|
|
628
|
+
total_tokens: z3.number(),
|
|
629
|
+
prompt_tokens_details: z3.object({
|
|
630
|
+
cached_tokens: z3.number().nullish(),
|
|
631
|
+
cache_creation_input_tokens: z3.number().nullish()
|
|
632
|
+
}).nullish(),
|
|
633
|
+
completion_tokens_details: z3.object({
|
|
634
|
+
reasoning_tokens: z3.number().nullish()
|
|
635
|
+
}).nullish()
|
|
636
|
+
});
|
|
637
|
+
var alibabaChatResponseSchema = z3.object({
|
|
638
|
+
id: z3.string().nullish(),
|
|
639
|
+
created: z3.number().nullish(),
|
|
640
|
+
model: z3.string().nullish(),
|
|
641
|
+
choices: z3.array(
|
|
642
|
+
z3.object({
|
|
643
|
+
message: z3.object({
|
|
644
|
+
role: z3.literal("assistant").nullish(),
|
|
645
|
+
content: z3.string().nullish(),
|
|
646
|
+
reasoning_content: z3.string().nullish(),
|
|
647
|
+
// Alibaba thinking mode
|
|
648
|
+
tool_calls: z3.array(
|
|
649
|
+
z3.object({
|
|
650
|
+
id: z3.string(),
|
|
651
|
+
type: z3.literal("function"),
|
|
652
|
+
function: z3.object({
|
|
653
|
+
name: z3.string(),
|
|
654
|
+
arguments: z3.string()
|
|
655
|
+
})
|
|
656
|
+
})
|
|
657
|
+
).nullish()
|
|
658
|
+
}),
|
|
659
|
+
finish_reason: z3.string().nullish(),
|
|
660
|
+
index: z3.number()
|
|
661
|
+
})
|
|
662
|
+
),
|
|
663
|
+
usage: alibabaUsageSchema.nullish()
|
|
664
|
+
});
|
|
665
|
+
var alibabaChatChunkSchema = z3.object({
|
|
666
|
+
id: z3.string().nullish(),
|
|
667
|
+
created: z3.number().nullish(),
|
|
668
|
+
model: z3.string().nullish(),
|
|
669
|
+
choices: z3.array(
|
|
670
|
+
z3.object({
|
|
671
|
+
delta: z3.object({
|
|
672
|
+
role: z3.enum(["assistant"]).nullish(),
|
|
673
|
+
content: z3.string().nullish(),
|
|
674
|
+
reasoning_content: z3.string().nullish(),
|
|
675
|
+
// Alibaba thinking mode delta
|
|
676
|
+
tool_calls: z3.array(
|
|
677
|
+
z3.object({
|
|
678
|
+
index: z3.number().nullish(),
|
|
679
|
+
// Index for accumulating tool calls
|
|
680
|
+
id: z3.string().nullish(),
|
|
681
|
+
type: z3.literal("function").nullish(),
|
|
682
|
+
function: z3.object({
|
|
683
|
+
name: z3.string().nullish(),
|
|
684
|
+
arguments: z3.string().nullish()
|
|
685
|
+
}).nullish()
|
|
686
|
+
})
|
|
687
|
+
).nullish()
|
|
688
|
+
}),
|
|
689
|
+
finish_reason: z3.string().nullish(),
|
|
690
|
+
index: z3.number()
|
|
691
|
+
})
|
|
692
|
+
),
|
|
693
|
+
usage: alibabaUsageSchema.nullish()
|
|
694
|
+
// Usage only appears in final chunk
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// src/alibaba-embedding-model.ts
|
|
698
|
+
import {
|
|
699
|
+
TooManyEmbeddingValuesForCallError,
|
|
700
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
701
|
+
} from "@ai-sdk/provider";
|
|
702
|
+
import {
|
|
703
|
+
combineHeaders as combineHeaders2,
|
|
704
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
705
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
706
|
+
parseProviderOptions as parseProviderOptions2,
|
|
707
|
+
postJsonToApi as postJsonToApi2,
|
|
708
|
+
serializeModelOptions as serializeModelOptions2,
|
|
709
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
710
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
711
|
+
} from "@ai-sdk/provider-utils";
|
|
712
|
+
import { z as z5 } from "zod/v4";
|
|
713
|
+
|
|
714
|
+
// src/alibaba-embedding-model-options.ts
|
|
715
|
+
import { z as z4 } from "zod/v4";
|
|
716
|
+
var alibabaEmbeddingModelOptions = z4.object({
|
|
717
|
+
/**
|
|
718
|
+
* Differentiates query text from document text for asymmetric retrieval tasks.
|
|
719
|
+
* Defaults to `document`.
|
|
720
|
+
*/
|
|
721
|
+
textType: z4.enum(["query", "document"]).optional(),
|
|
722
|
+
/**
|
|
723
|
+
* The dimension of the output embedding vectors. Defaults to 1024.
|
|
724
|
+
*
|
|
725
|
+
* `text-embedding-v4` also supports 1536 and 2048 dimensions.
|
|
726
|
+
*/
|
|
727
|
+
dimension: z4.number().optional(),
|
|
728
|
+
/**
|
|
729
|
+
* The output vector type. Defaults to `dense`.
|
|
730
|
+
*
|
|
731
|
+
* Sparse-only output is not supported by the AI SDK embedding interface,
|
|
732
|
+
* which requires dense number arrays.
|
|
733
|
+
*/
|
|
734
|
+
outputType: z4.enum(["dense", "sparse", "dense&sparse"]).optional()
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// src/alibaba-embedding-model.ts
|
|
738
|
+
var alibabaEmbeddingFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
739
|
+
errorSchema: z5.object({
|
|
740
|
+
code: z5.string().nullish(),
|
|
741
|
+
message: z5.string(),
|
|
742
|
+
request_id: z5.string().nullish()
|
|
743
|
+
}),
|
|
744
|
+
errorToMessage: (data) => data.message
|
|
745
|
+
});
|
|
746
|
+
var AlibabaEmbeddingModel = class _AlibabaEmbeddingModel {
|
|
747
|
+
constructor(modelId, config) {
|
|
748
|
+
this.specificationVersion = "v4";
|
|
749
|
+
this.maxEmbeddingsPerCall = 10;
|
|
750
|
+
this.supportsParallelCalls = false;
|
|
751
|
+
this.modelId = modelId;
|
|
752
|
+
this.config = config;
|
|
753
|
+
}
|
|
754
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
755
|
+
return serializeModelOptions2({
|
|
756
|
+
modelId: model.modelId,
|
|
757
|
+
config: model.config
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
761
|
+
return new _AlibabaEmbeddingModel(options.modelId, options.config);
|
|
762
|
+
}
|
|
763
|
+
get provider() {
|
|
764
|
+
return this.config.provider;
|
|
765
|
+
}
|
|
766
|
+
async doEmbed({
|
|
767
|
+
values,
|
|
768
|
+
headers,
|
|
769
|
+
abortSignal,
|
|
770
|
+
providerOptions
|
|
771
|
+
}) {
|
|
772
|
+
var _a, _b;
|
|
773
|
+
if (values.length > this.maxEmbeddingsPerCall) {
|
|
774
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
775
|
+
provider: this.provider,
|
|
776
|
+
modelId: this.modelId,
|
|
777
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
778
|
+
values
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
const alibabaOptions = await parseProviderOptions2({
|
|
782
|
+
provider: "alibaba",
|
|
783
|
+
providerOptions,
|
|
784
|
+
schema: alibabaEmbeddingModelOptions
|
|
785
|
+
});
|
|
786
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.outputType) === "sparse") {
|
|
787
|
+
throw new UnsupportedFunctionalityError2({
|
|
788
|
+
functionality: "Alibaba embedding outputType 'sparse'",
|
|
789
|
+
message: "Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays. Use 'dense' or 'dense&sparse' instead."
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
const {
|
|
793
|
+
responseHeaders,
|
|
794
|
+
value: response,
|
|
795
|
+
rawValue
|
|
796
|
+
} = await postJsonToApi2({
|
|
797
|
+
url: `${this.config.baseURL}/services/embeddings/text-embedding/text-embedding`,
|
|
798
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
799
|
+
body: {
|
|
800
|
+
model: this.modelId,
|
|
801
|
+
input: {
|
|
802
|
+
texts: values
|
|
803
|
+
},
|
|
804
|
+
parameters: {
|
|
805
|
+
text_type: alibabaOptions == null ? void 0 : alibabaOptions.textType,
|
|
806
|
+
dimension: alibabaOptions == null ? void 0 : alibabaOptions.dimension,
|
|
807
|
+
output_type: alibabaOptions == null ? void 0 : alibabaOptions.outputType
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
failedResponseHandler: alibabaEmbeddingFailedResponseHandler,
|
|
811
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
812
|
+
alibabaTextEmbeddingResponseSchema
|
|
813
|
+
),
|
|
814
|
+
abortSignal,
|
|
815
|
+
fetch: this.config.fetch
|
|
816
|
+
});
|
|
817
|
+
const sortedEmbeddings = response.output.embeddings.sort(
|
|
818
|
+
(a, b) => a.text_index - b.text_index
|
|
819
|
+
);
|
|
820
|
+
const sparseEmbeddings = sortedEmbeddings.map(
|
|
821
|
+
(item) => item.sparse_embedding == null ? void 0 : {
|
|
822
|
+
textIndex: item.text_index,
|
|
823
|
+
sparseEmbedding: item.sparse_embedding
|
|
824
|
+
}
|
|
825
|
+
).filter((item) => item != null);
|
|
826
|
+
return {
|
|
827
|
+
warnings: [],
|
|
828
|
+
embeddings: sortedEmbeddings.map((item) => item.embedding),
|
|
829
|
+
usage: response.usage ? { tokens: response.usage.total_tokens } : void 0,
|
|
830
|
+
providerMetadata: sparseEmbeddings.length > 0 ? {
|
|
831
|
+
alibaba: {
|
|
832
|
+
sparseEmbeddings
|
|
833
|
+
}
|
|
834
|
+
} : void 0,
|
|
835
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var alibabaTextEmbeddingSparseEmbeddingSchema = z5.object({
|
|
840
|
+
index: z5.number(),
|
|
841
|
+
value: z5.number(),
|
|
842
|
+
token: z5.string().nullish()
|
|
843
|
+
});
|
|
844
|
+
var alibabaTextEmbeddingResponseSchema = z5.object({
|
|
845
|
+
output: z5.object({
|
|
846
|
+
embeddings: z5.array(
|
|
847
|
+
z5.object({
|
|
848
|
+
embedding: z5.array(z5.number()),
|
|
849
|
+
text_index: z5.number(),
|
|
850
|
+
sparse_embedding: z5.array(alibabaTextEmbeddingSparseEmbeddingSchema).nullish()
|
|
851
|
+
})
|
|
852
|
+
)
|
|
853
|
+
}),
|
|
854
|
+
usage: z5.object({
|
|
855
|
+
total_tokens: z5.number()
|
|
856
|
+
}).nullish()
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
// src/alibaba-video-model.ts
|
|
860
|
+
import {
|
|
861
|
+
AISDKError
|
|
862
|
+
} from "@ai-sdk/provider";
|
|
863
|
+
import {
|
|
864
|
+
combineHeaders as combineHeaders3,
|
|
865
|
+
convertImageModelFileToDataUri,
|
|
866
|
+
convertUint8ArrayToBase64,
|
|
867
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
868
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
869
|
+
delay,
|
|
870
|
+
getFromApi,
|
|
871
|
+
parseProviderOptions as parseProviderOptions3,
|
|
872
|
+
postJsonToApi as postJsonToApi3,
|
|
873
|
+
resolve
|
|
874
|
+
} from "@ai-sdk/provider-utils";
|
|
875
|
+
import { z as z7 } from "zod/v4";
|
|
876
|
+
|
|
877
|
+
// src/alibaba-video-model-options.ts
|
|
878
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
879
|
+
import { z as z6 } from "zod/v4";
|
|
880
|
+
var alibabaVideoModelOptionsSchema = lazySchema(
|
|
881
|
+
() => zodSchema(
|
|
882
|
+
z6.looseObject({
|
|
883
|
+
negativePrompt: z6.string().nullish(),
|
|
884
|
+
audioUrl: z6.string().nullish(),
|
|
885
|
+
promptExtend: z6.boolean().nullish(),
|
|
886
|
+
shotType: z6.enum(["single", "multi"]).nullish(),
|
|
887
|
+
watermark: z6.boolean().nullish(),
|
|
888
|
+
audio: z6.boolean().nullish(),
|
|
889
|
+
referenceUrls: z6.array(z6.string()).nullish(),
|
|
890
|
+
media: z6.array(
|
|
891
|
+
z6.object({
|
|
892
|
+
type: z6.enum(["reference_image", "reference_video", "first_frame"]),
|
|
893
|
+
url: z6.string(),
|
|
894
|
+
referenceVoice: z6.string().nullish()
|
|
895
|
+
})
|
|
896
|
+
).nullish(),
|
|
897
|
+
ratio: z6.enum(["16:9", "9:16", "1:1", "4:3", "3:4"]).nullish(),
|
|
898
|
+
pollIntervalMs: z6.number().positive().nullish(),
|
|
899
|
+
pollTimeoutMs: z6.number().positive().nullish()
|
|
900
|
+
})
|
|
901
|
+
)
|
|
902
|
+
);
|
|
903
|
+
|
|
904
|
+
// src/alibaba-video-model.ts
|
|
905
|
+
var alibabaVideoErrorSchema = z7.object({
|
|
906
|
+
code: z7.string().nullish(),
|
|
907
|
+
message: z7.string(),
|
|
908
|
+
request_id: z7.string().nullish()
|
|
909
|
+
});
|
|
910
|
+
var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler3({
|
|
911
|
+
errorSchema: alibabaVideoErrorSchema,
|
|
912
|
+
errorToMessage: (data) => data.message
|
|
913
|
+
});
|
|
914
|
+
var alibabaVideoCreateTaskSchema = z7.object({
|
|
915
|
+
output: z7.object({
|
|
916
|
+
task_status: z7.string(),
|
|
917
|
+
task_id: z7.string()
|
|
918
|
+
}).nullish(),
|
|
919
|
+
request_id: z7.string().nullish()
|
|
920
|
+
});
|
|
921
|
+
var alibabaVideoTaskStatusSchema = z7.object({
|
|
922
|
+
output: z7.object({
|
|
923
|
+
task_id: z7.string(),
|
|
924
|
+
task_status: z7.string(),
|
|
925
|
+
video_url: z7.string().nullish(),
|
|
926
|
+
submit_time: z7.string().nullish(),
|
|
927
|
+
scheduled_time: z7.string().nullish(),
|
|
928
|
+
end_time: z7.string().nullish(),
|
|
929
|
+
orig_prompt: z7.string().nullish(),
|
|
930
|
+
actual_prompt: z7.string().nullish(),
|
|
931
|
+
code: z7.string().nullish(),
|
|
932
|
+
message: z7.string().nullish()
|
|
933
|
+
}).nullish(),
|
|
934
|
+
usage: z7.object({
|
|
935
|
+
duration: z7.number().nullish(),
|
|
936
|
+
output_video_duration: z7.number().nullish(),
|
|
937
|
+
SR: z7.number().nullish(),
|
|
938
|
+
size: z7.string().nullish()
|
|
939
|
+
}).nullish(),
|
|
940
|
+
request_id: z7.string().nullish()
|
|
941
|
+
});
|
|
942
|
+
function detectMode(modelId) {
|
|
943
|
+
if (modelId.includes("-i2v")) return "i2v";
|
|
944
|
+
if (modelId.includes("-r2v")) return "r2v";
|
|
945
|
+
return "t2v";
|
|
946
|
+
}
|
|
947
|
+
function isWan27Model(modelId) {
|
|
948
|
+
return modelId.startsWith("wan2.7");
|
|
949
|
+
}
|
|
950
|
+
var resolutionTierMap = {
|
|
951
|
+
"1280x720": "720P",
|
|
952
|
+
"720x1280": "720P",
|
|
953
|
+
"960x960": "720P",
|
|
954
|
+
"1088x832": "720P",
|
|
955
|
+
"832x1088": "720P",
|
|
956
|
+
"1920x1080": "1080P",
|
|
957
|
+
"1080x1920": "1080P",
|
|
958
|
+
"1440x1440": "1080P",
|
|
959
|
+
"1632x1248": "1080P",
|
|
960
|
+
"1248x1632": "1080P",
|
|
961
|
+
"832x480": "480P",
|
|
962
|
+
"480x832": "480P",
|
|
963
|
+
"624x624": "480P"
|
|
964
|
+
};
|
|
965
|
+
var supportedRatios = /* @__PURE__ */ new Set(["16:9", "9:16", "1:1", "4:3", "3:4"]);
|
|
966
|
+
function deriveRatioFromResolution(resolution) {
|
|
967
|
+
const [width, height] = resolution.split("x").map(Number);
|
|
968
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) {
|
|
969
|
+
return void 0;
|
|
970
|
+
}
|
|
971
|
+
let a = width;
|
|
972
|
+
let b = height;
|
|
973
|
+
while (b !== 0) {
|
|
974
|
+
[a, b] = [b, a % b];
|
|
975
|
+
}
|
|
976
|
+
const ratio = `${width / a}:${height / a}`;
|
|
977
|
+
return supportedRatios.has(ratio) ? ratio : void 0;
|
|
978
|
+
}
|
|
979
|
+
function fileToImageString(file) {
|
|
980
|
+
if (file.type === "url") {
|
|
981
|
+
return file.url;
|
|
982
|
+
}
|
|
983
|
+
return typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
|
|
984
|
+
}
|
|
985
|
+
function getFirstFrameImage(options) {
|
|
986
|
+
var _a, _b;
|
|
987
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
988
|
+
}
|
|
989
|
+
function resolveStartImage(options) {
|
|
990
|
+
var _a;
|
|
991
|
+
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
992
|
+
}
|
|
993
|
+
function isVideoUrl(url) {
|
|
994
|
+
return /\.(mp4|mov)([?#]|$)/i.test(url);
|
|
995
|
+
}
|
|
996
|
+
function resolveMedia(options, alibabaOptions, warnings) {
|
|
997
|
+
var _a;
|
|
998
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.media) != null && alibabaOptions.media.length > 0) {
|
|
999
|
+
return alibabaOptions.media.map((item) => ({
|
|
1000
|
+
type: item.type,
|
|
1001
|
+
url: item.url,
|
|
1002
|
+
...item.referenceVoice != null ? { reference_voice: item.referenceVoice } : {}
|
|
1003
|
+
}));
|
|
1004
|
+
}
|
|
1005
|
+
const media = [];
|
|
1006
|
+
for (const reference of (_a = options.inputReferences) != null ? _a : []) {
|
|
1007
|
+
if (reference.type === "url") {
|
|
1008
|
+
media.push({
|
|
1009
|
+
type: isVideoUrl(reference.url) ? "reference_video" : "reference_image",
|
|
1010
|
+
url: reference.url
|
|
1011
|
+
});
|
|
1012
|
+
} else if (reference.mediaType.startsWith("image/")) {
|
|
1013
|
+
media.push({
|
|
1014
|
+
type: "reference_image",
|
|
1015
|
+
url: convertImageModelFileToDataUri(reference)
|
|
1016
|
+
});
|
|
1017
|
+
} else {
|
|
1018
|
+
warnings.push({
|
|
1019
|
+
type: "unsupported",
|
|
1020
|
+
feature: "inputReferences",
|
|
1021
|
+
details: "Alibaba reference-to-video requires URL references for videos. Non-URL video reference was skipped."
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
const firstFrame = getFirstFrameImage(options);
|
|
1026
|
+
if (firstFrame != null) {
|
|
1027
|
+
media.push({
|
|
1028
|
+
type: "first_frame",
|
|
1029
|
+
url: convertImageModelFileToDataUri(firstFrame)
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
return media.length > 0 ? media : void 0;
|
|
1033
|
+
}
|
|
1034
|
+
function resolveReferenceUrls(options, alibabaOptions, warnings) {
|
|
1035
|
+
var _a;
|
|
1036
|
+
if (options.frameImages != null && options.frameImages.length > 0) {
|
|
1037
|
+
return void 0;
|
|
1038
|
+
}
|
|
1039
|
+
if (options.inputReferences != null && options.inputReferences.length > 0) {
|
|
1040
|
+
const urls = [];
|
|
1041
|
+
for (const reference of options.inputReferences) {
|
|
1042
|
+
if (reference.type === "url") {
|
|
1043
|
+
urls.push(reference.url);
|
|
1044
|
+
} else {
|
|
1045
|
+
warnings.push({
|
|
1046
|
+
type: "unsupported",
|
|
1047
|
+
feature: "inputReferences",
|
|
1048
|
+
details: "Alibaba reference-to-video requires URL references. Non-URL reference was skipped."
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
return urls.length > 0 ? urls : void 0;
|
|
1053
|
+
}
|
|
1054
|
+
return (_a = alibabaOptions == null ? void 0 : alibabaOptions.referenceUrls) != null ? _a : void 0;
|
|
1055
|
+
}
|
|
1056
|
+
var AlibabaVideoModel = class {
|
|
1057
|
+
constructor(modelId, config) {
|
|
1058
|
+
this.modelId = modelId;
|
|
1059
|
+
this.config = config;
|
|
1060
|
+
this.specificationVersion = "v4";
|
|
1061
|
+
this.maxVideosPerCall = 1;
|
|
1062
|
+
}
|
|
1063
|
+
get provider() {
|
|
1064
|
+
return this.config.provider;
|
|
1065
|
+
}
|
|
1066
|
+
async doGenerate(options) {
|
|
1067
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1068
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1069
|
+
const warnings = [];
|
|
1070
|
+
const mode = detectMode(this.modelId);
|
|
1071
|
+
const alibabaOptions = await parseProviderOptions3({
|
|
1072
|
+
provider: "alibaba",
|
|
1073
|
+
providerOptions: options.providerOptions,
|
|
1074
|
+
schema: alibabaVideoModelOptionsSchema
|
|
1075
|
+
});
|
|
1076
|
+
const input = {};
|
|
1077
|
+
if (options.prompt != null) {
|
|
1078
|
+
input.prompt = options.prompt;
|
|
1079
|
+
}
|
|
1080
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.negativePrompt) != null) {
|
|
1081
|
+
input.negative_prompt = alibabaOptions.negativePrompt;
|
|
1082
|
+
}
|
|
1083
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.audioUrl) != null) {
|
|
1084
|
+
input.audio_url = alibabaOptions.audioUrl;
|
|
1085
|
+
}
|
|
1086
|
+
const startImage = resolveStartImage(options);
|
|
1087
|
+
const wan27 = isWan27Model(this.modelId);
|
|
1088
|
+
const supportsRatio = wan27 && mode !== "i2v";
|
|
1089
|
+
if (mode === "i2v" && startImage != null) {
|
|
1090
|
+
input.img_url = fileToImageString(startImage);
|
|
1091
|
+
}
|
|
1092
|
+
if (mode === "r2v") {
|
|
1093
|
+
if (wan27) {
|
|
1094
|
+
const media = resolveMedia(options, alibabaOptions, warnings);
|
|
1095
|
+
if (media != null) {
|
|
1096
|
+
input.media = media;
|
|
1097
|
+
}
|
|
1098
|
+
} else {
|
|
1099
|
+
const referenceUrls = resolveReferenceUrls(
|
|
1100
|
+
options,
|
|
1101
|
+
alibabaOptions,
|
|
1102
|
+
warnings
|
|
1103
|
+
);
|
|
1104
|
+
if (referenceUrls != null && referenceUrls.length > 0) {
|
|
1105
|
+
input.reference_urls = referenceUrls;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
const lastFrame = (_e = (_d = options.frameImages) == null ? void 0 : _d.find(
|
|
1110
|
+
(frame) => frame.frameType === "last_frame"
|
|
1111
|
+
)) == null ? void 0 : _e.image;
|
|
1112
|
+
if (lastFrame != null) {
|
|
1113
|
+
warnings.push({
|
|
1114
|
+
type: "unsupported",
|
|
1115
|
+
feature: "frameImages",
|
|
1116
|
+
details: "This model does not support last_frame. The last frame image was ignored."
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
if (options.inputReferences != null && options.inputReferences.length > 0 && mode !== "r2v") {
|
|
1120
|
+
warnings.push({
|
|
1121
|
+
type: "unsupported",
|
|
1122
|
+
feature: "inputReferences",
|
|
1123
|
+
details: "Alibaba only supports inputReferences (reference-to-video) on reference-to-video models. The reference images were ignored."
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
const parameters = {};
|
|
1127
|
+
if (options.duration != null) {
|
|
1128
|
+
parameters.duration = options.duration;
|
|
1129
|
+
}
|
|
1130
|
+
if (options.seed != null) {
|
|
1131
|
+
parameters.seed = options.seed;
|
|
1132
|
+
}
|
|
1133
|
+
if (options.resolution != null) {
|
|
1134
|
+
if (mode === "i2v" || wan27) {
|
|
1135
|
+
const resolutionTier = resolutionTierMap[options.resolution] || options.resolution;
|
|
1136
|
+
if (wan27 && resolutionTier !== "720P" && resolutionTier !== "1080P") {
|
|
1137
|
+
warnings.push({
|
|
1138
|
+
type: "unsupported",
|
|
1139
|
+
feature: "resolution",
|
|
1140
|
+
details: `wan2.7 models only support 720P and 1080P resolutions. The resolution "${options.resolution}" was ignored.`
|
|
1141
|
+
});
|
|
1142
|
+
} else {
|
|
1143
|
+
parameters.resolution = resolutionTier;
|
|
1144
|
+
}
|
|
1145
|
+
} else {
|
|
1146
|
+
parameters.size = options.resolution.replace("x", "*");
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (supportsRatio) {
|
|
1150
|
+
const ratio = (_g = (_f = alibabaOptions == null ? void 0 : alibabaOptions.ratio) != null ? _f : options.aspectRatio) != null ? _g : options.resolution != null ? deriveRatioFromResolution(options.resolution) : void 0;
|
|
1151
|
+
if (ratio != null) {
|
|
1152
|
+
parameters.ratio = ratio;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.promptExtend) != null) {
|
|
1156
|
+
parameters.prompt_extend = alibabaOptions.promptExtend;
|
|
1157
|
+
}
|
|
1158
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.shotType) != null) {
|
|
1159
|
+
if (wan27) {
|
|
1160
|
+
warnings.push({
|
|
1161
|
+
type: "unsupported",
|
|
1162
|
+
feature: "shotType",
|
|
1163
|
+
details: "wan2.7 models do not support the shotType option. Describe the shot structure in the prompt instead."
|
|
1164
|
+
});
|
|
1165
|
+
} else {
|
|
1166
|
+
parameters.shot_type = alibabaOptions.shotType;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.watermark) != null) {
|
|
1170
|
+
parameters.watermark = alibabaOptions.watermark;
|
|
1171
|
+
}
|
|
1172
|
+
const audio = (_h = options.generateAudio) != null ? _h : alibabaOptions == null ? void 0 : alibabaOptions.audio;
|
|
1173
|
+
if (audio != null) {
|
|
1174
|
+
if (wan27) {
|
|
1175
|
+
warnings.push({
|
|
1176
|
+
type: "unsupported",
|
|
1177
|
+
feature: "generateAudio",
|
|
1178
|
+
details: "wan2.7 models always generate audio. The audio option was ignored."
|
|
1179
|
+
});
|
|
1180
|
+
} else {
|
|
1181
|
+
parameters.audio = audio;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
if (options.aspectRatio && !supportsRatio) {
|
|
1185
|
+
warnings.push({
|
|
1186
|
+
type: "unsupported",
|
|
1187
|
+
feature: "aspectRatio",
|
|
1188
|
+
details: "Alibaba video models use explicit size/resolution dimensions. Use the resolution option or providerOptions.alibaba for size control."
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
if (options.fps) {
|
|
1192
|
+
warnings.push({
|
|
1193
|
+
type: "unsupported",
|
|
1194
|
+
feature: "fps",
|
|
1195
|
+
details: "Alibaba video models do not support custom FPS."
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
if (options.n != null && options.n > 1) {
|
|
1199
|
+
warnings.push({
|
|
1200
|
+
type: "unsupported",
|
|
1201
|
+
feature: "n",
|
|
1202
|
+
details: "Alibaba video models only support generating 1 video per call."
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
const { value: createResponse } = await postJsonToApi3({
|
|
1206
|
+
url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
|
|
1207
|
+
headers: combineHeaders3(
|
|
1208
|
+
await resolve(this.config.headers),
|
|
1209
|
+
options.headers,
|
|
1210
|
+
{
|
|
1211
|
+
"X-DashScope-Async": "enable"
|
|
1212
|
+
}
|
|
1213
|
+
),
|
|
1214
|
+
body: {
|
|
1215
|
+
model: this.modelId,
|
|
1216
|
+
input,
|
|
1217
|
+
parameters
|
|
1218
|
+
},
|
|
1219
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1220
|
+
alibabaVideoCreateTaskSchema
|
|
1221
|
+
),
|
|
1222
|
+
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
1223
|
+
abortSignal: options.abortSignal,
|
|
1224
|
+
fetch: this.config.fetch
|
|
1225
|
+
});
|
|
1226
|
+
const taskId = (_i = createResponse.output) == null ? void 0 : _i.task_id;
|
|
1227
|
+
if (!taskId) {
|
|
1228
|
+
throw new AISDKError({
|
|
1229
|
+
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
1230
|
+
message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
const pollIntervalMs = (_j = alibabaOptions == null ? void 0 : alibabaOptions.pollIntervalMs) != null ? _j : 5e3;
|
|
1234
|
+
const pollTimeoutMs = (_k = alibabaOptions == null ? void 0 : alibabaOptions.pollTimeoutMs) != null ? _k : 6e5;
|
|
1235
|
+
const startTime = Date.now();
|
|
1236
|
+
let finalResponse;
|
|
1237
|
+
let responseHeaders;
|
|
1238
|
+
while (true) {
|
|
1239
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
1240
|
+
if (Date.now() - startTime > pollTimeoutMs) {
|
|
1241
|
+
throw new AISDKError({
|
|
1242
|
+
name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
|
|
1243
|
+
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
|
|
1247
|
+
url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
|
|
1248
|
+
headers: combineHeaders3(
|
|
1249
|
+
await resolve(this.config.headers),
|
|
1250
|
+
options.headers
|
|
1251
|
+
),
|
|
1252
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
1253
|
+
alibabaVideoTaskStatusSchema
|
|
1254
|
+
),
|
|
1255
|
+
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
1256
|
+
abortSignal: options.abortSignal,
|
|
1257
|
+
fetch: this.config.fetch
|
|
1258
|
+
});
|
|
1259
|
+
responseHeaders = pollHeaders;
|
|
1260
|
+
const taskStatus = (_l = statusResponse.output) == null ? void 0 : _l.task_status;
|
|
1261
|
+
if (taskStatus === "SUCCEEDED") {
|
|
1262
|
+
finalResponse = statusResponse;
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
|
|
1266
|
+
throw new AISDKError({
|
|
1267
|
+
name: "ALIBABA_VIDEO_GENERATION_FAILED",
|
|
1268
|
+
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_n = (_m = statusResponse.output) == null ? void 0 : _m.message) != null ? _n : ""}`
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const videoUrl = (_o = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _o.video_url;
|
|
1273
|
+
if (!videoUrl) {
|
|
1274
|
+
throw new AISDKError({
|
|
1275
|
+
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
1276
|
+
message: `No video URL in response. Task ID: ${taskId}`
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
return {
|
|
1280
|
+
videos: [
|
|
1281
|
+
{
|
|
1282
|
+
type: "url",
|
|
1283
|
+
url: videoUrl,
|
|
1284
|
+
mediaType: "video/mp4"
|
|
1285
|
+
}
|
|
1286
|
+
],
|
|
1287
|
+
warnings,
|
|
1288
|
+
response: {
|
|
1289
|
+
timestamp: currentDate,
|
|
1290
|
+
modelId: this.modelId,
|
|
1291
|
+
headers: responseHeaders
|
|
1292
|
+
},
|
|
1293
|
+
providerMetadata: {
|
|
1294
|
+
alibaba: {
|
|
1295
|
+
taskId,
|
|
1296
|
+
videoUrl,
|
|
1297
|
+
...((_p = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _p.actual_prompt) ? { actualPrompt: finalResponse.output.actual_prompt } : {},
|
|
1298
|
+
...(finalResponse == null ? void 0 : finalResponse.usage) ? {
|
|
1299
|
+
usage: {
|
|
1300
|
+
duration: finalResponse.usage.duration,
|
|
1301
|
+
outputVideoDuration: finalResponse.usage.output_video_duration,
|
|
1302
|
+
resolution: finalResponse.usage.SR,
|
|
1303
|
+
size: finalResponse.usage.size
|
|
1304
|
+
}
|
|
1305
|
+
} : {}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
// src/version.ts
|
|
1313
|
+
var VERSION = true ? "0.0.0-6b196531-20260710185421" : "0.0.0-test";
|
|
1314
|
+
|
|
1315
|
+
// src/alibaba-provider.ts
|
|
1316
|
+
function createAlibaba(options = {}) {
|
|
1317
|
+
var _a, _b, _c;
|
|
1318
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
|
|
1319
|
+
const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
|
|
1320
|
+
const embeddingBaseURL = (_c = withoutTrailingSlash(options.embeddingBaseURL)) != null ? _c : "https://dashscope-intl.aliyuncs.com/api/v1";
|
|
1321
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1322
|
+
{
|
|
1323
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1324
|
+
apiKey: options.apiKey,
|
|
1325
|
+
environmentVariableName: "ALIBABA_API_KEY",
|
|
1326
|
+
description: "Alibaba Cloud (DashScope)"
|
|
1327
|
+
})}`,
|
|
1328
|
+
...options.headers
|
|
1329
|
+
},
|
|
1330
|
+
`ai-sdk/alibaba/${VERSION}`
|
|
1331
|
+
);
|
|
1332
|
+
const createLanguageModel = (modelId) => {
|
|
1333
|
+
var _a2;
|
|
1334
|
+
return new AlibabaChatLanguageModel(modelId, {
|
|
1335
|
+
provider: "alibaba.chat",
|
|
1336
|
+
baseURL,
|
|
1337
|
+
headers: getHeaders,
|
|
1338
|
+
fetch: options.fetch,
|
|
1339
|
+
includeUsage: (_a2 = options.includeUsage) != null ? _a2 : true
|
|
1340
|
+
});
|
|
1341
|
+
};
|
|
1342
|
+
const createEmbeddingModel = (modelId) => new AlibabaEmbeddingModel(modelId, {
|
|
1343
|
+
provider: "alibaba.embedding",
|
|
1344
|
+
baseURL: embeddingBaseURL,
|
|
1345
|
+
headers: getHeaders,
|
|
1346
|
+
fetch: options.fetch
|
|
1347
|
+
});
|
|
1348
|
+
const createVideoModel = (modelId) => new AlibabaVideoModel(modelId, {
|
|
1349
|
+
provider: "alibaba.video",
|
|
1350
|
+
baseURL: videoBaseURL,
|
|
1351
|
+
headers: getHeaders,
|
|
1352
|
+
fetch: options.fetch
|
|
1353
|
+
});
|
|
1354
|
+
const provider = function(modelId) {
|
|
1355
|
+
if (new.target) {
|
|
1356
|
+
throw new Error(
|
|
1357
|
+
"The Alibaba model function cannot be called with the new keyword."
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
return createLanguageModel(modelId);
|
|
1361
|
+
};
|
|
1362
|
+
provider.specificationVersion = "v4";
|
|
1363
|
+
provider.languageModel = createLanguageModel;
|
|
1364
|
+
provider.chatModel = createLanguageModel;
|
|
1365
|
+
provider.embedding = createEmbeddingModel;
|
|
1366
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
1367
|
+
provider.video = createVideoModel;
|
|
1368
|
+
provider.videoModel = createVideoModel;
|
|
1369
|
+
provider.imageModel = (modelId) => {
|
|
1370
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1371
|
+
};
|
|
1372
|
+
return provider;
|
|
1373
|
+
}
|
|
1374
|
+
var alibaba = createAlibaba();
|
|
1375
|
+
export {
|
|
1376
|
+
VERSION,
|
|
1377
|
+
alibaba,
|
|
1378
|
+
createAlibaba
|
|
1379
|
+
};
|
|
1380
|
+
//# sourceMappingURL=index.js.map
|