@ai-sdk/xai 4.0.59 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +5 -61
- package/dist/index.js +908 -1790
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +2 -12
- package/package.json +1 -1
- package/src/index.ts +0 -5
- package/src/xai-batch.ts +86 -12
- package/src/xai-error.ts +2 -2
- package/src/xai-provider.ts +0 -18
- package/src/convert-to-xai-chat-messages.ts +0 -181
- package/src/convert-xai-chat-usage.ts +0 -29
- package/src/xai-chat-language-model-options.ts +0 -141
- package/src/xai-chat-language-model.ts +0 -778
- package/src/xai-chat-prompt.ts +0 -48
- package/src/xai-prepare-tools.ts +0 -98
package/src/xai-chat-prompt.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type XaiChatPrompt = Array<XaiChatMessage>;
|
|
2
|
-
|
|
3
|
-
export type XaiChatMessage =
|
|
4
|
-
| XaiSystemMessage
|
|
5
|
-
| XaiUserMessage
|
|
6
|
-
| XaiAssistantMessage
|
|
7
|
-
| XaiToolMessage;
|
|
8
|
-
|
|
9
|
-
export interface XaiSystemMessage {
|
|
10
|
-
role: 'system';
|
|
11
|
-
content: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface XaiUserMessage {
|
|
15
|
-
role: 'user';
|
|
16
|
-
content: string | Array<XaiUserMessageContent>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type XaiUserMessageContent =
|
|
20
|
-
| { type: 'text'; text: string }
|
|
21
|
-
| {
|
|
22
|
-
type: 'image_url';
|
|
23
|
-
image_url: { url: string; detail?: 'low' | 'high' | 'auto' };
|
|
24
|
-
}
|
|
25
|
-
| { type: 'file'; file: { file_id: string } };
|
|
26
|
-
|
|
27
|
-
export interface XaiAssistantMessage {
|
|
28
|
-
role: 'assistant';
|
|
29
|
-
content: string;
|
|
30
|
-
tool_calls?: Array<{
|
|
31
|
-
id: string;
|
|
32
|
-
type: 'function';
|
|
33
|
-
function: { name: string; arguments: string };
|
|
34
|
-
}>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface XaiToolMessage {
|
|
38
|
-
role: 'tool';
|
|
39
|
-
tool_call_id: string;
|
|
40
|
-
content: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// xai tool choice
|
|
44
|
-
export type XaiToolChoice =
|
|
45
|
-
| 'auto'
|
|
46
|
-
| 'none'
|
|
47
|
-
| 'required'
|
|
48
|
-
| { type: 'function'; function: { name: string } };
|
package/src/xai-prepare-tools.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UnsupportedFunctionalityError,
|
|
3
|
-
type LanguageModelV4CallOptions,
|
|
4
|
-
type SharedV4Warning,
|
|
5
|
-
} from '@ai-sdk/provider';
|
|
6
|
-
import type { XaiToolChoice } from './xai-chat-prompt';
|
|
7
|
-
|
|
8
|
-
export function prepareTools({
|
|
9
|
-
tools,
|
|
10
|
-
toolChoice,
|
|
11
|
-
}: {
|
|
12
|
-
tools: LanguageModelV4CallOptions['tools'];
|
|
13
|
-
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
14
|
-
}): {
|
|
15
|
-
tools:
|
|
16
|
-
| Array<{
|
|
17
|
-
type: 'function';
|
|
18
|
-
function: {
|
|
19
|
-
name: string;
|
|
20
|
-
description: string | undefined;
|
|
21
|
-
parameters: unknown;
|
|
22
|
-
strict?: boolean;
|
|
23
|
-
};
|
|
24
|
-
}>
|
|
25
|
-
| undefined;
|
|
26
|
-
toolChoice: XaiToolChoice | undefined;
|
|
27
|
-
toolWarnings: SharedV4Warning[];
|
|
28
|
-
} {
|
|
29
|
-
// when the tools array is empty, change it to undefined to prevent errors
|
|
30
|
-
tools = tools?.length ? tools : undefined;
|
|
31
|
-
|
|
32
|
-
const toolWarnings: SharedV4Warning[] = [];
|
|
33
|
-
|
|
34
|
-
if (tools == null) {
|
|
35
|
-
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// convert ai sdk tools to xai format
|
|
39
|
-
const xaiTools: Array<{
|
|
40
|
-
type: 'function';
|
|
41
|
-
function: {
|
|
42
|
-
name: string;
|
|
43
|
-
description: string | undefined;
|
|
44
|
-
parameters: unknown;
|
|
45
|
-
strict?: boolean;
|
|
46
|
-
};
|
|
47
|
-
}> = [];
|
|
48
|
-
|
|
49
|
-
for (const tool of tools) {
|
|
50
|
-
if (tool.type === 'provider') {
|
|
51
|
-
toolWarnings.push({
|
|
52
|
-
type: 'unsupported',
|
|
53
|
-
feature: `provider-defined tool ${tool.name}`,
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
xaiTools.push({
|
|
57
|
-
type: 'function',
|
|
58
|
-
function: {
|
|
59
|
-
name: tool.name,
|
|
60
|
-
description: tool.description,
|
|
61
|
-
parameters: tool.inputSchema,
|
|
62
|
-
...(tool.strict != null ? { strict: tool.strict } : {}),
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (toolChoice == null) {
|
|
69
|
-
return { tools: xaiTools, toolChoice: undefined, toolWarnings };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const type = toolChoice.type;
|
|
73
|
-
|
|
74
|
-
switch (type) {
|
|
75
|
-
case 'auto':
|
|
76
|
-
case 'none':
|
|
77
|
-
return { tools: xaiTools, toolChoice: type, toolWarnings };
|
|
78
|
-
case 'required':
|
|
79
|
-
// xai supports 'required' directly
|
|
80
|
-
return { tools: xaiTools, toolChoice: 'required', toolWarnings };
|
|
81
|
-
case 'tool':
|
|
82
|
-
// xai supports specific tool selection
|
|
83
|
-
return {
|
|
84
|
-
tools: xaiTools,
|
|
85
|
-
toolChoice: {
|
|
86
|
-
type: 'function',
|
|
87
|
-
function: { name: toolChoice.toolName },
|
|
88
|
-
},
|
|
89
|
-
toolWarnings,
|
|
90
|
-
};
|
|
91
|
-
default: {
|
|
92
|
-
const _exhaustiveCheck: never = type;
|
|
93
|
-
throw new UnsupportedFunctionalityError({
|
|
94
|
-
functionality: `tool choice type: ${_exhaustiveCheck}`,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|