@ai-sdk/alibaba 2.0.0-beta.2 → 2.0.0-beta.21
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 +158 -0
- package/README.md +2 -0
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +55 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
- package/src/alibaba-chat-language-model.ts +73 -27
- package/src/alibaba-provider.ts +10 -10
- package/src/alibaba-video-model.ts +7 -7
- package/src/convert-alibaba-usage.ts +2 -2
- package/src/convert-to-alibaba-chat-messages.ts +21 -30
- package/src/get-cache-control.ts +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AISDKError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type Experimental_VideoModelV4,
|
|
4
|
+
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
@@ -133,8 +133,8 @@ function detectMode(modelId: string): 't2v' | 'i2v' | 'r2v' {
|
|
|
133
133
|
return 't2v';
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
export class AlibabaVideoModel implements
|
|
137
|
-
readonly specificationVersion = '
|
|
136
|
+
export class AlibabaVideoModel implements Experimental_VideoModelV4 {
|
|
137
|
+
readonly specificationVersion = 'v4';
|
|
138
138
|
readonly maxVideosPerCall = 1;
|
|
139
139
|
|
|
140
140
|
get provider(): string {
|
|
@@ -147,10 +147,10 @@ export class AlibabaVideoModel implements Experimental_VideoModelV3 {
|
|
|
147
147
|
) {}
|
|
148
148
|
|
|
149
149
|
async doGenerate(
|
|
150
|
-
options: Parameters<
|
|
151
|
-
): Promise<Awaited<ReturnType<
|
|
150
|
+
options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
|
|
151
|
+
): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
|
|
152
152
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
153
|
-
const warnings:
|
|
153
|
+
const warnings: SharedV4Warning[] = [];
|
|
154
154
|
const mode = detectMode(this.modelId);
|
|
155
155
|
|
|
156
156
|
const alibabaOptions = (await parseProviderOptions({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { convertOpenAICompatibleChatUsage } from '@ai-sdk/openai-compatible/internal';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
3
3
|
|
|
4
4
|
export type AlibabaUsage = {
|
|
5
5
|
prompt_tokens?: number | null;
|
|
@@ -16,7 +16,7 @@ export type AlibabaUsage = {
|
|
|
16
16
|
|
|
17
17
|
export function convertAlibabaUsage(
|
|
18
18
|
usage: AlibabaUsage | undefined | null,
|
|
19
|
-
):
|
|
19
|
+
): LanguageModelV4Usage {
|
|
20
20
|
const baseUsage = convertOpenAICompatibleChatUsage(usage);
|
|
21
21
|
|
|
22
22
|
const cacheWriteTokens =
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
type
|
|
2
|
+
type LanguageModelV4DataContent,
|
|
3
|
+
type LanguageModelV4Prompt,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
6
|
+
import { convertToBase64, isProviderReference } from '@ai-sdk/provider-utils';
|
|
7
7
|
import type { AlibabaChatPrompt } from './alibaba-chat-prompt';
|
|
8
8
|
import type { CacheControlValidator } from './get-cache-control';
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ function formatImageUrl({
|
|
|
11
11
|
data,
|
|
12
12
|
mediaType,
|
|
13
13
|
}: {
|
|
14
|
-
data:
|
|
14
|
+
data: LanguageModelV4DataContent;
|
|
15
15
|
mediaType: string;
|
|
16
16
|
}): string {
|
|
17
17
|
return data instanceof URL
|
|
@@ -23,7 +23,7 @@ export function convertToAlibabaChatMessages({
|
|
|
23
23
|
prompt,
|
|
24
24
|
cacheControlValidator,
|
|
25
25
|
}: {
|
|
26
|
-
prompt:
|
|
26
|
+
prompt: LanguageModelV4Prompt;
|
|
27
27
|
cacheControlValidator?: CacheControlValidator;
|
|
28
28
|
}): AlibabaChatPrompt {
|
|
29
29
|
const messages: AlibabaChatPrompt = [];
|
|
@@ -53,26 +53,13 @@ export function convertToAlibabaChatMessages({
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
case 'user': {
|
|
56
|
-
const isSinglePart = content.length === 1;
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
isSinglePart &&
|
|
60
|
-
content[0].type === 'text' &&
|
|
61
|
-
!messageCacheControl
|
|
62
|
-
) {
|
|
63
|
-
messages.push({
|
|
64
|
-
role: 'user',
|
|
65
|
-
content: content[0].text,
|
|
66
|
-
});
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
56
|
messages.push({
|
|
71
57
|
role: 'user',
|
|
72
|
-
content: content.map(part => {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
content: content.map((part, index) => {
|
|
59
|
+
const isLastPart = index === content.length - 1;
|
|
60
|
+
const partCacheControl =
|
|
61
|
+
cacheControlValidator?.getCacheControl(part.providerOptions) ??
|
|
62
|
+
(isLastPart ? messageCacheControl : undefined);
|
|
76
63
|
|
|
77
64
|
switch (part.type) {
|
|
78
65
|
case 'text': {
|
|
@@ -86,6 +73,12 @@ export function convertToAlibabaChatMessages({
|
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
case 'file': {
|
|
76
|
+
if (isProviderReference(part.data)) {
|
|
77
|
+
throw new UnsupportedFunctionalityError({
|
|
78
|
+
functionality: 'file parts with provider references',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
89
82
|
if (part.mediaType.startsWith('image/')) {
|
|
90
83
|
const mediaType =
|
|
91
84
|
part.mediaType === 'image/*'
|
|
@@ -163,17 +156,15 @@ export function convertToAlibabaChatMessages({
|
|
|
163
156
|
r => r.type !== 'tool-approval-response',
|
|
164
157
|
);
|
|
165
158
|
|
|
166
|
-
const isSinglePart = toolResponses.length === 1;
|
|
167
|
-
|
|
168
159
|
for (let i = 0; i < toolResponses.length; i++) {
|
|
169
160
|
const toolResponse = toolResponses[i];
|
|
170
161
|
const output = toolResponse.output;
|
|
162
|
+
const isLastPart = i === toolResponses.length - 1;
|
|
171
163
|
|
|
172
|
-
const partCacheControl =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
);
|
|
164
|
+
const partCacheControl =
|
|
165
|
+
cacheControlValidator?.getCacheControl(
|
|
166
|
+
toolResponse.providerOptions,
|
|
167
|
+
) ?? (isLastPart ? messageCacheControl : undefined);
|
|
177
168
|
|
|
178
169
|
let contentValue: string;
|
|
179
170
|
switch (output.type) {
|
package/src/get-cache-control.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SharedV4ProviderMetadata,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import type { AlibabaCacheControl } from './alibaba-chat-prompt';
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ import type { AlibabaCacheControl } from './alibaba-chat-prompt';
|
|
|
8
8
|
const MAX_CACHE_BREAKPOINTS = 4;
|
|
9
9
|
|
|
10
10
|
function getCacheControl(
|
|
11
|
-
providerMetadata:
|
|
11
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
12
12
|
): AlibabaCacheControl | undefined {
|
|
13
13
|
const alibaba = providerMetadata?.alibaba;
|
|
14
14
|
|
|
@@ -21,10 +21,10 @@ function getCacheControl(
|
|
|
21
21
|
|
|
22
22
|
export class CacheControlValidator {
|
|
23
23
|
private breakpointCount = 0;
|
|
24
|
-
private warnings:
|
|
24
|
+
private warnings: SharedV4Warning[] = [];
|
|
25
25
|
|
|
26
26
|
getCacheControl(
|
|
27
|
-
providerMetadata:
|
|
27
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
28
28
|
): AlibabaCacheControl | undefined {
|
|
29
29
|
const cacheControlValue = getCacheControl(providerMetadata);
|
|
30
30
|
|
|
@@ -43,7 +43,7 @@ export class CacheControlValidator {
|
|
|
43
43
|
return cacheControlValue;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
getWarnings():
|
|
46
|
+
getWarnings(): SharedV4Warning[] {
|
|
47
47
|
return this.warnings;
|
|
48
48
|
}
|
|
49
49
|
}
|