@ai-sdk/xai 3.0.67 → 3.0.69
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 +14 -0
- package/dist/index.js +7 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -14
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +22 -1
- package/package.json +4 -4
- package/src/xai-image-model.ts +8 -16
package/docs/01-xai.mdx
CHANGED
|
@@ -840,6 +840,27 @@ const { images } = await generateImage({
|
|
|
840
840
|
});
|
|
841
841
|
```
|
|
842
842
|
|
|
843
|
+
#### Multi-Image Editing
|
|
844
|
+
|
|
845
|
+
Combine or reference multiple input images (up to 3) in the prompt:
|
|
846
|
+
|
|
847
|
+
```ts
|
|
848
|
+
import { xai } from '@ai-sdk/xai';
|
|
849
|
+
import { generateImage } from 'ai';
|
|
850
|
+
import { readFileSync } from 'fs';
|
|
851
|
+
|
|
852
|
+
const cat = readFileSync('./cat.png');
|
|
853
|
+
const dog = readFileSync('./dog.png');
|
|
854
|
+
|
|
855
|
+
const { images } = await generateImage({
|
|
856
|
+
model: xai.image('grok-imagine-image'),
|
|
857
|
+
prompt: {
|
|
858
|
+
text: 'Combine these two animals into a group photo',
|
|
859
|
+
images: [cat, dog],
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
```
|
|
863
|
+
|
|
843
864
|
#### Style Transfer
|
|
844
865
|
|
|
845
866
|
Apply artistic styles to an image:
|
|
@@ -859,7 +880,7 @@ const { images } = await generateImage({
|
|
|
859
880
|
|
|
860
881
|
<Note>
|
|
861
882
|
Input images can be provided as `Buffer`, `ArrayBuffer`, `Uint8Array`, or
|
|
862
|
-
base64-encoded strings.
|
|
883
|
+
base64-encoded strings. Up to 3 input images are supported per request.
|
|
863
884
|
</Note>
|
|
864
885
|
|
|
865
886
|
### Model-specific options
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.69",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/
|
|
33
|
-
"@ai-sdk/
|
|
34
|
-
"@ai-sdk/provider": "
|
|
32
|
+
"@ai-sdk/provider": "3.0.8",
|
|
33
|
+
"@ai-sdk/openai-compatible": "2.0.36",
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
package/src/xai-image-model.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface XaiImageModelConfig {
|
|
|
27
27
|
|
|
28
28
|
export class XaiImageModel implements ImageModelV3 {
|
|
29
29
|
readonly specificationVersion = 'v3';
|
|
30
|
-
readonly maxImagesPerCall =
|
|
30
|
+
readonly maxImagesPerCall = 3;
|
|
31
31
|
|
|
32
32
|
get provider(): string {
|
|
33
33
|
return this.config.provider;
|
|
@@ -84,19 +84,9 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
const hasFiles = files != null && files.length > 0;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
imageUrl = convertImageModelFileToDataUri(files[0]);
|
|
91
|
-
|
|
92
|
-
if (files.length > 1) {
|
|
93
|
-
warnings.push({
|
|
94
|
-
type: 'other',
|
|
95
|
-
message:
|
|
96
|
-
'xAI only supports a single input image. Additional images are ignored.',
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
87
|
+
const imageUrls = hasFiles
|
|
88
|
+
? files.map(file => convertImageModelFileToDataUri(file))
|
|
89
|
+
: [];
|
|
100
90
|
|
|
101
91
|
const endpoint = hasFiles ? '/images/edits' : '/images/generations';
|
|
102
92
|
|
|
@@ -127,8 +117,10 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
127
117
|
body.resolution = xaiOptions.resolution;
|
|
128
118
|
}
|
|
129
119
|
|
|
130
|
-
if (
|
|
131
|
-
body.image = { url:
|
|
120
|
+
if (imageUrls.length === 1) {
|
|
121
|
+
body.image = { url: imageUrls[0], type: 'image_url' };
|
|
122
|
+
} else if (imageUrls.length > 1) {
|
|
123
|
+
body.images = imageUrls.map(url => ({ url, type: 'image_url' }));
|
|
132
124
|
}
|
|
133
125
|
|
|
134
126
|
const baseURL = this.config.baseURL ?? 'https://api.x.ai/v1';
|