@ai-sdk/xai 5.0.13 → 5.0.15
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 +22 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -51
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +37 -18
- package/package.json +3 -3
- package/src/index.ts +4 -1
- package/src/xai-image-model-options.ts +2 -2
- package/src/xai-image-model.ts +7 -4
- package/src/xai-image-settings.ts +1 -0
- package/src/xai-provider.ts +7 -4
- package/src/xai-transcription-model-options.ts +15 -2
- package/src/xai-transcription-model.ts +62 -89
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 5.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 30f32bd: feat(xai): add grok-imagine-image-2.0 image model id
|
|
8
|
+
- 0a84440: feat(xai): add `auto` image quality option
|
|
9
|
+
- 08d7f0a: feat(xai): add `1.5k` image resolution provider option
|
|
10
|
+
- 7c41e41: feat(xai): support transcription model ids, `vadThreshold`, and `opus` audio format
|
|
11
|
+
- Updated dependencies [2959d35]
|
|
12
|
+
- Updated dependencies [59116e6]
|
|
13
|
+
- @ai-sdk/provider@4.0.22
|
|
14
|
+
- @ai-sdk/provider-utils@5.0.54
|
|
15
|
+
|
|
16
|
+
## 5.0.14
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [8c65988]
|
|
21
|
+
- Updated dependencies [527a163]
|
|
22
|
+
- @ai-sdk/provider@4.0.21
|
|
23
|
+
- @ai-sdk/provider-utils@5.0.53
|
|
24
|
+
|
|
3
25
|
## 5.0.13
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -76,11 +76,13 @@ declare const xaiImageModelOptions: z.ZodObject<{
|
|
|
76
76
|
sync_mode: z.ZodOptional<z.ZodBoolean>;
|
|
77
77
|
resolution: z.ZodOptional<z.ZodEnum<{
|
|
78
78
|
"1k": "1k";
|
|
79
|
+
"1.5k": "1.5k";
|
|
79
80
|
"2k": "2k";
|
|
80
81
|
}>>;
|
|
81
82
|
quality: z.ZodOptional<z.ZodEnum<{
|
|
82
83
|
low: "low";
|
|
83
84
|
high: "high";
|
|
85
|
+
auto: "auto";
|
|
84
86
|
medium: "medium";
|
|
85
87
|
}>>;
|
|
86
88
|
user: z.ZodOptional<z.ZodString>;
|
|
@@ -206,8 +208,9 @@ declare const xaiSpeechModelOptionsSchema: import("@ai-sdk/provider-utils").Lazy
|
|
|
206
208
|
type XaiSpeechModelOptions = InferSchema<typeof xaiSpeechModelOptionsSchema>;
|
|
207
209
|
//#endregion
|
|
208
210
|
//#region src/xai-transcription-model-options.d.ts
|
|
211
|
+
type XaiTranscriptionModelId = 'grok-voice-transcribe-2.0' | (string & {});
|
|
209
212
|
declare const xaiTranscriptionModelOptionsSchema: import("@ai-sdk/provider-utils").LazySchema<{
|
|
210
|
-
audioFormat?: "pcm" | "mulaw" | "alaw" | null | undefined;
|
|
213
|
+
audioFormat?: "pcm" | "mulaw" | "alaw" | "opus" | null | undefined;
|
|
211
214
|
sampleRate?: 8000 | 16000 | 22050 | 24000 | 44100 | 48000 | null | undefined;
|
|
212
215
|
language?: string | null | undefined;
|
|
213
216
|
format?: boolean | null | undefined;
|
|
@@ -216,6 +219,7 @@ declare const xaiTranscriptionModelOptionsSchema: import("@ai-sdk/provider-utils
|
|
|
216
219
|
diarize?: boolean | null | undefined;
|
|
217
220
|
keyterm?: string | string[] | null | undefined;
|
|
218
221
|
fillerWords?: boolean | null | undefined;
|
|
222
|
+
vadThreshold?: number | undefined;
|
|
219
223
|
streaming?: {
|
|
220
224
|
interimResults?: boolean | undefined;
|
|
221
225
|
endpointing?: number | undefined;
|
|
@@ -235,7 +239,7 @@ declare const xaiFilesOptionsSchema: import("@ai-sdk/provider-utils").LazySchema
|
|
|
235
239
|
type XaiFilesOptions = InferSchema<typeof xaiFilesOptionsSchema>;
|
|
236
240
|
//#endregion
|
|
237
241
|
//#region src/xai-image-settings.d.ts
|
|
238
|
-
type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-pro' | (string & {});
|
|
242
|
+
type XaiImageModelId = 'grok-imagine-image' | 'grok-imagine-image-2.0' | 'grok-imagine-image-pro' | (string & {});
|
|
239
243
|
//#endregion
|
|
240
244
|
//#region src/tool/code-execution.d.ts
|
|
241
245
|
declare const codeExecutionToolFactory: import("@ai-sdk/provider-utils").ProviderExecutedToolFactory<Record<string, never>, {
|
|
@@ -570,12 +574,14 @@ interface XaiProvider extends ProviderV4 {
|
|
|
570
574
|
speechModel(): SpeechModelV4;
|
|
571
575
|
/**
|
|
572
576
|
* Creates an xAI model for speech-to-text transcription.
|
|
577
|
+
* When `modelId` is omitted, xAI's default transcription model is used.
|
|
573
578
|
*/
|
|
574
|
-
transcription(): TranscriptionModelV4;
|
|
579
|
+
transcription(modelId?: XaiTranscriptionModelId): TranscriptionModelV4;
|
|
575
580
|
/**
|
|
576
581
|
* Creates an xAI model for speech-to-text transcription.
|
|
582
|
+
* When `modelId` is omitted, xAI's default transcription model is used.
|
|
577
583
|
*/
|
|
578
|
-
transcriptionModel(): TranscriptionModelV4;
|
|
584
|
+
transcriptionModel(modelId?: XaiTranscriptionModelId): TranscriptionModelV4;
|
|
579
585
|
/**
|
|
580
586
|
* Returns the xAI files interface for uploading files.
|
|
581
587
|
*/
|
|
@@ -645,5 +651,5 @@ declare class XaiRealtimeModel implements Experimental_RealtimeModelV4 {
|
|
|
645
651
|
//#region src/version.d.ts
|
|
646
652
|
export declare const VERSION: string;
|
|
647
653
|
//#endregion
|
|
648
|
-
export { XaiRealtimeModel as Experimental_XaiRealtimeModel, type XaiRealtimeModelConfig as Experimental_XaiRealtimeModelConfig, type XaiErrorData, type XaiFilePartProviderOptions, type XaiFilesOptions, type XaiImageModelOptions, type XaiImageModelOptions as XaiImageProviderOptions, type XaiLanguageModelResponsesOptions, type XaiLanguageModelResponsesOptions as XaiResponsesProviderOptions, type XaiProvider, type XaiProviderSettings, type XaiSpeechModelOptions, type XaiTranscriptionModelOptions, type XaiVideoModelId, type XaiVideoModelOptions, type XaiVideoModelOptions as XaiVideoProviderOptions };
|
|
654
|
+
export { XaiRealtimeModel as Experimental_XaiRealtimeModel, type XaiRealtimeModelConfig as Experimental_XaiRealtimeModelConfig, type XaiErrorData, type XaiFilePartProviderOptions, type XaiFilesOptions, type XaiImageModelOptions, type XaiImageModelOptions as XaiImageProviderOptions, type XaiLanguageModelResponsesOptions, type XaiLanguageModelResponsesOptions as XaiResponsesProviderOptions, type XaiProvider, type XaiProviderSettings, type XaiSpeechModelOptions, type XaiTranscriptionModelId, type XaiTranscriptionModelOptions, type XaiVideoModelId, type XaiVideoModelOptions, type XaiVideoModelOptions as XaiVideoProviderOptions };
|
|
649
655
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["BatchV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4"],"sources":["../src/xai-error.ts","../src/xai-file-part-options.ts","../src/responses/xai-responses-language-model-options.ts","../src/xai-image-model-options.ts","../src/xai-video-settings.ts","../src/xai-video-model-options.ts","../src/xai-speech-model-options.ts","../src/xai-transcription-model-options.ts","../src/files/xai-files-options.ts","../src/xai-image-settings.ts","../src/tool/code-execution.ts","../src/tool/image-generation.ts","../src/tool/mcp-server.ts","../src/tool/view-image.ts","../src/tool/view-x-video.ts","../src/tool/web-search.ts","../src/tool/x-search.ts","../src/tool/index.ts","../src/xai-provider.ts","../src/realtime/xai-realtime-model.ts","../src/version.ts"],"mappings":";;;;cAsBa,oBAAkB,EAAA,mBAAA,EAAA;;;;;;;;;;;;GAI7B,EAAA,KAAA;KAEU,eAAe,EAAE,aAAa;;;cCzB7B,4BAA0B,EAAA;;;;;;GAarC,EAAA,KAAA;KAEU,6BAA6B,EAAE,aAClC;;;KCjBG;;;;cAaC,kCAAgC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2D3C,EAAA,KAAA;KAEU,mCAAmC,EAAE,aACxC;;;cC3EI,sBAAoB,EAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["BatchV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4"],"sources":["../src/xai-error.ts","../src/xai-file-part-options.ts","../src/responses/xai-responses-language-model-options.ts","../src/xai-image-model-options.ts","../src/xai-video-settings.ts","../src/xai-video-model-options.ts","../src/xai-speech-model-options.ts","../src/xai-transcription-model-options.ts","../src/files/xai-files-options.ts","../src/xai-image-settings.ts","../src/tool/code-execution.ts","../src/tool/image-generation.ts","../src/tool/mcp-server.ts","../src/tool/view-image.ts","../src/tool/view-x-video.ts","../src/tool/web-search.ts","../src/tool/x-search.ts","../src/tool/index.ts","../src/xai-provider.ts","../src/realtime/xai-realtime-model.ts","../src/version.ts"],"mappings":";;;;cAsBa,oBAAkB,EAAA,mBAAA,EAAA;;;;;;;;;;;;GAI7B,EAAA,KAAA;KAEU,eAAe,EAAE,aAAa;;;cCzB7B,4BAA0B,EAAA;;;;;;GAarC,EAAA,KAAA;KAEU,6BAA6B,EAAE,aAClC;;;KCjBG;;;;cAaC,kCAAgC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2D3C,EAAA,KAAA;KAEU,mCAAmC,EAAE,aACxC;;;cC3EI,sBAAoB,EAAA;;;;;;;;;;;;;;;;GAO/B,EAAA,KAA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D,KAAG;;;KC7QJ;EACV;EACA;EACA,eAAe;EACf,QAAQ;;cAGG,4BAA4BM;WAC9B;WACA;WACA;mBAEQ;EAEL,YAAA,iBAAiB,QAAQ;EAM/B,qBACJ,SAASL,kDACR,QAAQC;EAwCX,mBAAmB;IAAW;IAAe;;IAC3C;IACA;;EAQF,iBAAiB,eAAeC;EAIhC,qBAAqB,OAAOC;EAI5B,mBACE,QAAQC,4CACP;;;;qBC/FQ"}
|
package/dist/index.js
CHANGED
|
@@ -31,19 +31,29 @@ const xaiImageModelOptions = z.object({
|
|
|
31
31
|
aspect_ratio: z.string().optional(),
|
|
32
32
|
output_format: z.string().optional(),
|
|
33
33
|
sync_mode: z.boolean().optional(),
|
|
34
|
-
resolution: z.enum([
|
|
34
|
+
resolution: z.enum([
|
|
35
|
+
"1k",
|
|
36
|
+
"1.5k",
|
|
37
|
+
"2k"
|
|
38
|
+
]).optional(),
|
|
35
39
|
quality: z.enum([
|
|
36
40
|
"low",
|
|
37
41
|
"medium",
|
|
38
|
-
"high"
|
|
42
|
+
"high",
|
|
43
|
+
"auto"
|
|
39
44
|
]).optional(),
|
|
40
45
|
user: z.string().optional()
|
|
41
46
|
});
|
|
42
47
|
//#endregion
|
|
43
48
|
//#region src/xai-image-model.ts
|
|
49
|
+
const fileInputModelIds = /* @__PURE__ */ new Set([
|
|
50
|
+
"grok-imagine-image",
|
|
51
|
+
"grok-imagine-image-2.0",
|
|
52
|
+
"grok-imagine-image-pro"
|
|
53
|
+
]);
|
|
44
54
|
var XaiImageModel = class XaiImageModel {
|
|
45
55
|
get supportsFileInputs() {
|
|
46
|
-
return
|
|
56
|
+
return fileInputModelIds.has(this.modelId) ? true : void 0;
|
|
47
57
|
}
|
|
48
58
|
get supportsMaskInputs() {
|
|
49
59
|
return this.supportsFileInputs === true ? false : void 0;
|
|
@@ -3077,7 +3087,7 @@ const xaiTools = {
|
|
|
3077
3087
|
};
|
|
3078
3088
|
//#endregion
|
|
3079
3089
|
//#region src/version.ts
|
|
3080
|
-
const VERSION = "5.0.
|
|
3090
|
+
const VERSION = "5.0.15";
|
|
3081
3091
|
//#endregion
|
|
3082
3092
|
//#region src/files/xai-files-options.ts
|
|
3083
3093
|
const xaiFilesOptionsSchema = lazySchema(() => zodSchema(z.looseObject({
|
|
@@ -3930,12 +3940,16 @@ const xaiSpeechTimestampsResponseSchema = z.object({
|
|
|
3930
3940
|
//#region src/xai-transcription-model-options.ts
|
|
3931
3941
|
const xaiTranscriptionModelOptionsSchema = lazySchema(() => zodSchema(z.object({
|
|
3932
3942
|
/**
|
|
3933
|
-
*
|
|
3943
|
+
* Input audio encoding for raw, headerless audio: `pcm`, `mulaw`, or
|
|
3944
|
+
* `alaw`. Container formats such as Ogg/Opus are auto-detected, so do
|
|
3945
|
+
* not set this for them. `opus` is for streaming only, with one raw Opus
|
|
3946
|
+
* packet per chunk.
|
|
3934
3947
|
*/
|
|
3935
3948
|
audioFormat: z.enum([
|
|
3936
3949
|
"pcm",
|
|
3937
3950
|
"mulaw",
|
|
3938
|
-
"alaw"
|
|
3951
|
+
"alaw",
|
|
3952
|
+
"opus"
|
|
3939
3953
|
]).nullish(),
|
|
3940
3954
|
/**
|
|
3941
3955
|
* Sample rate of the input audio in Hz.
|
|
@@ -3977,6 +3991,11 @@ const xaiTranscriptionModelOptionsSchema = lazySchema(() => zodSchema(z.object({
|
|
|
3977
3991
|
*/
|
|
3978
3992
|
fillerWords: z.boolean().nullish(),
|
|
3979
3993
|
/**
|
|
3994
|
+
* Voice activity detection threshold between 0 and 1. Defaults to 0.5
|
|
3995
|
+
* for `transcribe` and 0.08 for streaming. 0 disables the filter.
|
|
3996
|
+
*/
|
|
3997
|
+
vadThreshold: z.number().min(0).max(1).optional(),
|
|
3998
|
+
/**
|
|
3980
3999
|
* Options for streaming speech-to-text over WebSocket.
|
|
3981
4000
|
*/
|
|
3982
4001
|
streaming: z.object({
|
|
@@ -4026,21 +4045,11 @@ var XaiTranscriptionModel = class XaiTranscriptionModel {
|
|
|
4026
4045
|
schema: xaiTranscriptionModelOptionsSchema
|
|
4027
4046
|
});
|
|
4028
4047
|
const formData = new FormData();
|
|
4029
|
-
|
|
4048
|
+
appendXaiSttParams(formData, {
|
|
4049
|
+
...getXaiSttParams(this.modelId, xaiOptions),
|
|
4030
4050
|
audio_format: xaiOptions?.audioFormat,
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
format: xaiOptions?.format,
|
|
4034
|
-
multichannel: xaiOptions?.multichannel,
|
|
4035
|
-
channels: xaiOptions?.channels,
|
|
4036
|
-
diarize: xaiOptions?.diarize,
|
|
4037
|
-
filler_words: xaiOptions?.fillerWords
|
|
4038
|
-
};
|
|
4039
|
-
for (const [key, value] of Object.entries(transcriptionOptions)) if (value != null) formData.append(key, String(value));
|
|
4040
|
-
if (xaiOptions?.keyterm != null) {
|
|
4041
|
-
const keyterms = Array.isArray(xaiOptions.keyterm) ? xaiOptions.keyterm : [xaiOptions.keyterm];
|
|
4042
|
-
for (const keyterm of keyterms) formData.append("keyterm", keyterm);
|
|
4043
|
-
}
|
|
4051
|
+
format: xaiOptions?.format
|
|
4052
|
+
});
|
|
4044
4053
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
4045
4054
|
const fileExtension = mediaTypeToExtension(mediaType);
|
|
4046
4055
|
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
@@ -4096,12 +4105,13 @@ var XaiTranscriptionModel = class XaiTranscriptionModel {
|
|
|
4096
4105
|
feature: "providerOptions.xai.format",
|
|
4097
4106
|
details: "xAI streaming transcription does not support format."
|
|
4098
4107
|
});
|
|
4099
|
-
if (xaiOptions?.audioFormat == null && !
|
|
4108
|
+
if (xaiOptions?.audioFormat == null && !inputAudioFormatEncodings.has(options.inputAudioFormat.type)) warnings.push({
|
|
4100
4109
|
type: "other",
|
|
4101
|
-
message: `Unrecognized inputAudioFormat.type "${options.inputAudioFormat.type}"; falling back to raw PCM encoding. Use
|
|
4110
|
+
message: `Unrecognized inputAudioFormat.type "${options.inputAudioFormat.type}"; falling back to raw PCM encoding. Use ${[...inputAudioFormatEncodings.keys()].join(", ")}, or set providerOptions.xai.audioFormat explicitly.`
|
|
4102
4111
|
});
|
|
4103
4112
|
const url = buildXaiStreamingTranscriptionUrl({
|
|
4104
4113
|
baseURL: this.config.baseURL ?? "https://api.x.ai/v1",
|
|
4114
|
+
modelId: this.modelId,
|
|
4105
4115
|
inputAudioFormat: options.inputAudioFormat,
|
|
4106
4116
|
providerOptions: xaiOptions
|
|
4107
4117
|
});
|
|
@@ -4262,38 +4272,42 @@ function createXaiStreamingTranscriptionStream({ webSocket, url, headers, warnin
|
|
|
4262
4272
|
}
|
|
4263
4273
|
});
|
|
4264
4274
|
}
|
|
4265
|
-
function buildXaiStreamingTranscriptionUrl({ baseURL, inputAudioFormat, providerOptions }) {
|
|
4275
|
+
function buildXaiStreamingTranscriptionUrl({ baseURL, modelId, inputAudioFormat, providerOptions }) {
|
|
4266
4276
|
const url = toWebSocketUrl(`${baseURL}/stt`);
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
appendSearchParam(url, "smart_turn_timeout", providerOptions?.streaming?.smartTurnTimeout);
|
|
4278
|
-
if (providerOptions?.keyterm != null) {
|
|
4279
|
-
const keyterms = Array.isArray(providerOptions.keyterm) ? providerOptions.keyterm : [providerOptions.keyterm];
|
|
4280
|
-
for (const keyterm of keyterms) url.searchParams.append("keyterm", keyterm);
|
|
4281
|
-
}
|
|
4277
|
+
const params = getXaiSttParams(modelId, providerOptions);
|
|
4278
|
+
appendXaiSttParams(url.searchParams, {
|
|
4279
|
+
...params,
|
|
4280
|
+
sample_rate: params.sample_rate ?? inputAudioFormat.rate,
|
|
4281
|
+
encoding: providerOptions?.audioFormat ?? inputAudioFormatEncodings.get(inputAudioFormat.type) ?? "pcm",
|
|
4282
|
+
interim_results: providerOptions?.streaming?.interimResults,
|
|
4283
|
+
endpointing: providerOptions?.streaming?.endpointing,
|
|
4284
|
+
smart_turn: providerOptions?.streaming?.smartTurn,
|
|
4285
|
+
smart_turn_timeout: providerOptions?.streaming?.smartTurnTimeout
|
|
4286
|
+
});
|
|
4282
4287
|
return url;
|
|
4283
4288
|
}
|
|
4284
|
-
function
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
+
function getXaiSttParams(modelId, options) {
|
|
4290
|
+
return {
|
|
4291
|
+
model: modelId || void 0,
|
|
4292
|
+
sample_rate: options?.sampleRate,
|
|
4293
|
+
language: options?.language,
|
|
4294
|
+
multichannel: options?.multichannel,
|
|
4295
|
+
channels: options?.channels,
|
|
4296
|
+
diarize: options?.diarize,
|
|
4297
|
+
filler_words: options?.fillerWords,
|
|
4298
|
+
vad_threshold: options?.vadThreshold,
|
|
4299
|
+
keyterm: options?.keyterm
|
|
4300
|
+
};
|
|
4289
4301
|
}
|
|
4290
|
-
function
|
|
4291
|
-
|
|
4292
|
-
case "audio/pcmu": return "mulaw";
|
|
4293
|
-
case "audio/pcma": return "alaw";
|
|
4294
|
-
default: return "pcm";
|
|
4295
|
-
}
|
|
4302
|
+
function appendXaiSttParams(target, params) {
|
|
4303
|
+
for (const [key, value] of Object.entries(params)) for (const item of Array.isArray(value) ? value : [value]) if (item != null) target.append(key, String(item));
|
|
4296
4304
|
}
|
|
4305
|
+
const inputAudioFormatEncodings = /* @__PURE__ */ new Map([
|
|
4306
|
+
["audio/pcm", "pcm"],
|
|
4307
|
+
["audio/pcmu", "mulaw"],
|
|
4308
|
+
["audio/pcma", "alaw"],
|
|
4309
|
+
["audio/opus", "opus"]
|
|
4310
|
+
]);
|
|
4297
4311
|
function channelId(channelIndex) {
|
|
4298
4312
|
return channelIndex == null ? void 0 : `channel-${channelIndex}`;
|
|
4299
4313
|
}
|
|
@@ -4366,8 +4380,8 @@ function createXai(options = {}) {
|
|
|
4366
4380
|
fetch: options.fetch
|
|
4367
4381
|
});
|
|
4368
4382
|
};
|
|
4369
|
-
const createTranscriptionModel = () => {
|
|
4370
|
-
return new XaiTranscriptionModel(
|
|
4383
|
+
const createTranscriptionModel = (modelId = "") => {
|
|
4384
|
+
return new XaiTranscriptionModel(modelId, {
|
|
4371
4385
|
provider: "xai.transcription",
|
|
4372
4386
|
baseURL,
|
|
4373
4387
|
headers: getHeaders,
|