@ai-sdk/xai 4.0.0-beta.7 → 4.0.0-beta.8
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 +6 -0
- package/dist/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/convert-to-xai-chat-messages.ts +5 -5
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +5 -5
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +2 -2
- package/src/responses/xai-responses-language-model.ts +21 -21
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +21 -21
- package/src/xai-image-model.ts +6 -6
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +14 -14
- package/src/xai-video-model.ts +7 -7
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SharedV4Warning,
|
|
3
|
+
LanguageModelV4Prompt,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
7
7
|
import { XaiChatPrompt } from './xai-chat-prompt';
|
|
8
8
|
|
|
9
|
-
export function convertToXaiChatMessages(prompt:
|
|
9
|
+
export function convertToXaiChatMessages(prompt: LanguageModelV4Prompt): {
|
|
10
10
|
messages: XaiChatPrompt;
|
|
11
|
-
warnings: Array<
|
|
11
|
+
warnings: Array<SharedV4Warning>;
|
|
12
12
|
} {
|
|
13
13
|
const messages: XaiChatPrompt = [];
|
|
14
|
-
const warnings: Array<
|
|
14
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
15
15
|
|
|
16
16
|
for (const { role, content } of prompt) {
|
|
17
17
|
switch (role) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
import { XaiChatUsage } from './xai-chat-language-model';
|
|
3
3
|
|
|
4
|
-
export function convertXaiChatUsage(usage: XaiChatUsage):
|
|
4
|
+
export function convertXaiChatUsage(usage: XaiChatUsage): LanguageModelV4Usage {
|
|
5
5
|
const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
6
6
|
const reasoningTokens =
|
|
7
7
|
usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapXaiFinishReason(
|
|
4
4
|
finishReason: string | null | undefined,
|
|
5
|
-
):
|
|
5
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
6
6
|
switch (finishReason) {
|
|
7
7
|
case 'stop':
|
|
8
8
|
return 'stop';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
SharedV4Warning,
|
|
3
|
+
LanguageModelV4Message,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertToBase64 } from '@ai-sdk/provider-utils';
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
export async function convertToXaiResponsesInput({
|
|
13
13
|
prompt,
|
|
14
14
|
}: {
|
|
15
|
-
prompt:
|
|
15
|
+
prompt: LanguageModelV4Message[];
|
|
16
16
|
store?: boolean;
|
|
17
17
|
}): Promise<{
|
|
18
18
|
input: XaiResponsesInput;
|
|
19
|
-
inputWarnings:
|
|
19
|
+
inputWarnings: SharedV4Warning[];
|
|
20
20
|
}> {
|
|
21
21
|
const input: XaiResponsesInput = [];
|
|
22
|
-
const inputWarnings:
|
|
22
|
+
const inputWarnings: SharedV4Warning[] = [];
|
|
23
23
|
|
|
24
24
|
for (const message of prompt) {
|
|
25
25
|
switch (message.role) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
import { XaiResponsesUsage } from './xai-responses-api';
|
|
3
3
|
|
|
4
4
|
export function convertXaiResponsesUsage(
|
|
5
5
|
usage: XaiResponsesUsage,
|
|
6
|
-
):
|
|
6
|
+
): LanguageModelV4Usage {
|
|
7
7
|
const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
8
8
|
const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapXaiResponsesFinishReason(
|
|
4
4
|
finishReason: string | null | undefined,
|
|
5
|
-
):
|
|
5
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
6
6
|
switch (finishReason) {
|
|
7
7
|
case 'stop':
|
|
8
8
|
case 'completed':
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
|
+
LanguageModelV4CallOptions,
|
|
4
|
+
LanguageModelV4Content,
|
|
5
|
+
LanguageModelV4FinishReason,
|
|
6
|
+
LanguageModelV4GenerateResult,
|
|
7
|
+
LanguageModelV4StreamPart,
|
|
8
|
+
LanguageModelV4StreamResult,
|
|
9
|
+
LanguageModelV4Usage,
|
|
10
|
+
SharedV4Warning,
|
|
11
11
|
} from '@ai-sdk/provider';
|
|
12
12
|
import {
|
|
13
13
|
combineHeaders,
|
|
@@ -43,8 +43,8 @@ type XaiResponsesConfig = {
|
|
|
43
43
|
fetch?: FetchFunction;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export class XaiResponsesLanguageModel implements
|
|
47
|
-
readonly specificationVersion = '
|
|
46
|
+
export class XaiResponsesLanguageModel implements LanguageModelV4 {
|
|
47
|
+
readonly specificationVersion = 'v4';
|
|
48
48
|
|
|
49
49
|
readonly modelId: XaiResponsesModelId;
|
|
50
50
|
|
|
@@ -74,8 +74,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
74
74
|
providerOptions,
|
|
75
75
|
tools,
|
|
76
76
|
toolChoice,
|
|
77
|
-
}:
|
|
78
|
-
const warnings:
|
|
77
|
+
}: LanguageModelV4CallOptions) {
|
|
78
|
+
const warnings: SharedV4Warning[] = [];
|
|
79
79
|
|
|
80
80
|
const options =
|
|
81
81
|
(await parseProviderOptions({
|
|
@@ -207,8 +207,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
async doGenerate(
|
|
210
|
-
options:
|
|
211
|
-
): Promise<
|
|
210
|
+
options: LanguageModelV4CallOptions,
|
|
211
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
212
212
|
const {
|
|
213
213
|
args: body,
|
|
214
214
|
warnings,
|
|
@@ -235,7 +235,7 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
235
235
|
fetch: this.config.fetch,
|
|
236
236
|
});
|
|
237
237
|
|
|
238
|
-
const content: Array<
|
|
238
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
239
239
|
|
|
240
240
|
const webSearchSubTools = [
|
|
241
241
|
'web_search',
|
|
@@ -430,8 +430,8 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
async doStream(
|
|
433
|
-
options:
|
|
434
|
-
): Promise<
|
|
433
|
+
options: LanguageModelV4CallOptions,
|
|
434
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
435
435
|
const {
|
|
436
436
|
args,
|
|
437
437
|
warnings,
|
|
@@ -458,11 +458,11 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
458
458
|
fetch: this.config.fetch,
|
|
459
459
|
});
|
|
460
460
|
|
|
461
|
-
let finishReason:
|
|
461
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
462
462
|
unified: 'other',
|
|
463
463
|
raw: undefined,
|
|
464
464
|
};
|
|
465
|
-
let usage:
|
|
465
|
+
let usage: LanguageModelV4Usage | undefined = undefined;
|
|
466
466
|
let isFirstChunk = true;
|
|
467
467
|
const contentBlocks: Record<string, { type: 'text' }> = {};
|
|
468
468
|
const seenToolCalls = new Set<string>();
|
|
@@ -485,7 +485,7 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
|
485
485
|
stream: response.pipeThrough(
|
|
486
486
|
new TransformStream<
|
|
487
487
|
ParseResult<z.infer<typeof xaiResponsesChunkSchema>>,
|
|
488
|
-
|
|
488
|
+
LanguageModelV4StreamPart
|
|
489
489
|
>({
|
|
490
490
|
start(controller) {
|
|
491
491
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { validateTypes } from '@ai-sdk/provider-utils';
|
|
@@ -20,16 +20,16 @@ export async function prepareResponsesTools({
|
|
|
20
20
|
tools,
|
|
21
21
|
toolChoice,
|
|
22
22
|
}: {
|
|
23
|
-
tools:
|
|
24
|
-
toolChoice?:
|
|
23
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
24
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
25
25
|
}): Promise<{
|
|
26
26
|
tools: Array<XaiResponsesTool> | undefined;
|
|
27
27
|
toolChoice: XaiResponsesToolChoice | undefined;
|
|
28
|
-
toolWarnings:
|
|
28
|
+
toolWarnings: SharedV4Warning[];
|
|
29
29
|
}> {
|
|
30
30
|
const normalizedTools = tools?.length ? tools : undefined;
|
|
31
31
|
|
|
32
|
-
const toolWarnings:
|
|
32
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
33
33
|
|
|
34
34
|
if (normalizedTools == null) {
|
|
35
35
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APICallError,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
LanguageModelV4,
|
|
4
|
+
LanguageModelV4CallOptions,
|
|
5
|
+
LanguageModelV4Content,
|
|
6
|
+
LanguageModelV4FinishReason,
|
|
7
|
+
LanguageModelV4GenerateResult,
|
|
8
|
+
LanguageModelV4StreamPart,
|
|
9
|
+
LanguageModelV4StreamResult,
|
|
10
|
+
LanguageModelV4Usage,
|
|
11
|
+
SharedV4Warning,
|
|
12
12
|
} from '@ai-sdk/provider';
|
|
13
13
|
import {
|
|
14
14
|
combineHeaders,
|
|
@@ -41,8 +41,8 @@ type XaiChatConfig = {
|
|
|
41
41
|
fetch?: FetchFunction;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export class XaiChatLanguageModel implements
|
|
45
|
-
readonly specificationVersion = '
|
|
44
|
+
export class XaiChatLanguageModel implements LanguageModelV4 {
|
|
45
|
+
readonly specificationVersion = 'v4';
|
|
46
46
|
|
|
47
47
|
readonly modelId: XaiChatModelId;
|
|
48
48
|
|
|
@@ -75,8 +75,8 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
75
75
|
providerOptions,
|
|
76
76
|
tools,
|
|
77
77
|
toolChoice,
|
|
78
|
-
}:
|
|
79
|
-
const warnings:
|
|
78
|
+
}: LanguageModelV4CallOptions) {
|
|
79
|
+
const warnings: SharedV4Warning[] = [];
|
|
80
80
|
|
|
81
81
|
// parse xai-specific provider options
|
|
82
82
|
const options =
|
|
@@ -202,8 +202,8 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
async doGenerate(
|
|
205
|
-
options:
|
|
206
|
-
): Promise<
|
|
205
|
+
options: LanguageModelV4CallOptions,
|
|
206
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
207
207
|
const { args: body, warnings } = await this.getArgs(options);
|
|
208
208
|
|
|
209
209
|
const url = `${this.config.baseURL ?? 'https://api.x.ai/v1'}/chat/completions`;
|
|
@@ -237,7 +237,7 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
const choice = response.choices![0];
|
|
240
|
-
const content: Array<
|
|
240
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
241
241
|
|
|
242
242
|
// extract text content
|
|
243
243
|
if (choice.message.content != null && choice.message.content.length > 0) {
|
|
@@ -312,8 +312,8 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
async doStream(
|
|
315
|
-
options:
|
|
316
|
-
): Promise<
|
|
315
|
+
options: LanguageModelV4CallOptions,
|
|
316
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
317
317
|
const { args, warnings } = await this.getArgs(options);
|
|
318
318
|
const body = {
|
|
319
319
|
...args,
|
|
@@ -375,11 +375,11 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
375
375
|
fetch: this.config.fetch,
|
|
376
376
|
});
|
|
377
377
|
|
|
378
|
-
let finishReason:
|
|
378
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
379
379
|
unified: 'other',
|
|
380
380
|
raw: undefined,
|
|
381
381
|
};
|
|
382
|
-
let usage:
|
|
382
|
+
let usage: LanguageModelV4Usage | undefined = undefined;
|
|
383
383
|
let isFirstChunk = true;
|
|
384
384
|
const contentBlocks: Record<
|
|
385
385
|
string,
|
|
@@ -394,7 +394,7 @@ export class XaiChatLanguageModel implements LanguageModelV3 {
|
|
|
394
394
|
stream: response.pipeThrough(
|
|
395
395
|
new TransformStream<
|
|
396
396
|
ParseResult<z.infer<typeof xaiChatChunkSchema>>,
|
|
397
|
-
|
|
397
|
+
LanguageModelV4StreamPart
|
|
398
398
|
>({
|
|
399
399
|
start(controller) {
|
|
400
400
|
controller.enqueue({ type: 'stream-start', warnings });
|
package/src/xai-image-model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
combineHeaders,
|
|
4
4
|
convertImageModelFileToDataUri,
|
|
@@ -25,8 +25,8 @@ interface XaiImageModelConfig {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export class XaiImageModel implements
|
|
29
|
-
readonly specificationVersion = '
|
|
28
|
+
export class XaiImageModel implements ImageModelV4 {
|
|
29
|
+
readonly specificationVersion = 'v4';
|
|
30
30
|
readonly maxImagesPerCall = 3;
|
|
31
31
|
|
|
32
32
|
get provider(): string {
|
|
@@ -49,10 +49,10 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
49
49
|
abortSignal,
|
|
50
50
|
files,
|
|
51
51
|
mask,
|
|
52
|
-
}: Parameters<
|
|
53
|
-
Awaited<ReturnType<
|
|
52
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
53
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
54
54
|
> {
|
|
55
|
-
const warnings: Array<
|
|
55
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
56
56
|
|
|
57
57
|
if (size != null) {
|
|
58
58
|
warnings.push({
|
package/src/xai-prepare-tools.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { XaiToolChoice } from './xai-chat-prompt';
|
|
@@ -9,8 +9,8 @@ export function prepareTools({
|
|
|
9
9
|
tools,
|
|
10
10
|
toolChoice,
|
|
11
11
|
}: {
|
|
12
|
-
tools:
|
|
13
|
-
toolChoice?:
|
|
12
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
13
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
14
14
|
}): {
|
|
15
15
|
tools:
|
|
16
16
|
| Array<{
|
|
@@ -24,12 +24,12 @@ export function prepareTools({
|
|
|
24
24
|
}>
|
|
25
25
|
| undefined;
|
|
26
26
|
toolChoice: XaiToolChoice | undefined;
|
|
27
|
-
toolWarnings:
|
|
27
|
+
toolWarnings: SharedV4Warning[];
|
|
28
28
|
} {
|
|
29
29
|
// when the tools array is empty, change it to undefined to prevent errors
|
|
30
30
|
tools = tools?.length ? tools : undefined;
|
|
31
31
|
|
|
32
|
-
const toolWarnings:
|
|
32
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
33
33
|
|
|
34
34
|
if (tools == null) {
|
|
35
35
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
package/src/xai-provider.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type Experimental_VideoModelV4,
|
|
3
|
+
ImageModelV4,
|
|
4
|
+
LanguageModelV4,
|
|
5
5
|
NoSuchModelError,
|
|
6
|
-
|
|
6
|
+
ProviderV4,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
8
|
import {
|
|
9
9
|
FetchFunction,
|
|
@@ -23,43 +23,43 @@ import { VERSION } from './version';
|
|
|
23
23
|
import { XaiVideoModel } from './xai-video-model';
|
|
24
24
|
import { XaiVideoModelId } from './xai-video-settings';
|
|
25
25
|
|
|
26
|
-
export interface XaiProvider extends
|
|
27
|
-
(modelId: XaiResponsesModelId):
|
|
26
|
+
export interface XaiProvider extends ProviderV4 {
|
|
27
|
+
(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Creates an Xai language model for text generation.
|
|
31
31
|
*/
|
|
32
|
-
languageModel(modelId: XaiResponsesModelId):
|
|
32
|
+
languageModel(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Creates an Xai chat model for text generation.
|
|
36
36
|
*/
|
|
37
|
-
chat: (modelId: XaiChatModelId) =>
|
|
37
|
+
chat: (modelId: XaiChatModelId) => LanguageModelV4;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Creates an Xai responses model for text generation.
|
|
41
41
|
*/
|
|
42
|
-
responses: (modelId: XaiResponsesModelId) =>
|
|
42
|
+
responses: (modelId: XaiResponsesModelId) => LanguageModelV4;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Creates an Xai image model for image generation.
|
|
46
46
|
*/
|
|
47
|
-
image(modelId: XaiImageModelId):
|
|
47
|
+
image(modelId: XaiImageModelId): ImageModelV4;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Creates an Xai image model for image generation.
|
|
51
51
|
*/
|
|
52
|
-
imageModel(modelId: XaiImageModelId):
|
|
52
|
+
imageModel(modelId: XaiImageModelId): ImageModelV4;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Creates an Xai video model for video generation.
|
|
56
56
|
*/
|
|
57
|
-
video(modelId: XaiVideoModelId):
|
|
57
|
+
video(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Creates an Xai video model for video generation.
|
|
61
61
|
*/
|
|
62
|
-
videoModel(modelId: XaiVideoModelId):
|
|
62
|
+
videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Server-side agentic tools for use with the responses API.
|
|
@@ -153,7 +153,7 @@ export function createXai(options: XaiProviderSettings = {}): XaiProvider {
|
|
|
153
153
|
const provider = (modelId: XaiResponsesModelId) =>
|
|
154
154
|
createResponsesLanguageModel(modelId);
|
|
155
155
|
|
|
156
|
-
provider.specificationVersion = '
|
|
156
|
+
provider.specificationVersion = 'v4' as const;
|
|
157
157
|
provider.languageModel = createResponsesLanguageModel;
|
|
158
158
|
provider.chat = createChatLanguageModel;
|
|
159
159
|
provider.responses = createResponsesLanguageModel;
|
package/src/xai-video-model.ts
CHANGED
|
@@ -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,
|
|
@@ -37,8 +37,8 @@ const RESOLUTION_MAP: Record<string, string> = {
|
|
|
37
37
|
'640x480': '480p',
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export class XaiVideoModel implements
|
|
41
|
-
readonly specificationVersion = '
|
|
40
|
+
export class XaiVideoModel implements Experimental_VideoModelV4 {
|
|
41
|
+
readonly specificationVersion = 'v4';
|
|
42
42
|
readonly maxVideosPerCall = 1;
|
|
43
43
|
|
|
44
44
|
get provider(): string {
|
|
@@ -51,10 +51,10 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
|
|
|
51
51
|
) {}
|
|
52
52
|
|
|
53
53
|
async doGenerate(
|
|
54
|
-
options: Parameters<
|
|
55
|
-
): Promise<Awaited<ReturnType<
|
|
54
|
+
options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
|
|
55
|
+
): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
|
|
56
56
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
57
|
-
const warnings:
|
|
57
|
+
const warnings: SharedV4Warning[] = [];
|
|
58
58
|
|
|
59
59
|
const xaiOptions = (await parseProviderOptions({
|
|
60
60
|
provider: 'xai',
|