@ai-sdk/xai 5.0.14 → 5.0.16
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 +36 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -54
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +37 -18
- package/package.json +5 -5
- package/src/files/xai-files.ts +1 -1
- package/src/index.ts +4 -1
- package/src/responses/xai-responses-language-model.ts +1 -0
- 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 +71 -90
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 5.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 268225c: feat(provider): add a portable `max` reasoning level with native provider mappings, compatibility coercions, and budget-based fallback support.
|
|
8
|
+
|
|
9
|
+
Compatibility notes:
|
|
10
|
+
|
|
11
|
+
- **TypeScript source compatibility:** Adding `max` widens `LanguageModelV4CallOptions['reasoning']` and the derived `ReasoningLevel` type. Third-party providers and consumers with exhaustive switches or `Record<ReasoningLevel, ...>` mappings must handle `max` before upgrading. Ordinary calls using existing reasoning levels remain accepted.
|
|
12
|
+
- **Amazon Bedrock:** Existing Nova 2 calls using portable `reasoning: 'xhigh'` now send `maxReasoningEffort: 'high'` instead of the unsupported `'max'`, and return a compatibility warning. Anthropic and OpenAI Bedrock effort mappings retain their existing `xhigh` behavior. Partial Bedrock reasoning configurations continue to preserve explicit values and derive missing fields; explicit effort/budget overrides and disabled thinking no longer emit warnings for portable mappings that are not sent.
|
|
13
|
+
- **Fireworks:** Existing portable `minimal` and `xhigh` calls keep their request mappings to `low` and `high`, respectively, and now return compatibility warnings in generation and streaming results. Portable `max` maps to `high` with the same warning behavior.
|
|
14
|
+
|
|
15
|
+
**Release classification:** This remains a patch changeset under the repository's explicit release policy, which uses patch releases for both fixes and features. The TypeScript source-compatibility caveat for exhaustive consumers is disclosed above. Maintainers can override this classification with a `major` label if they decide to align the provider-spec addition with a future AI SDK major release.
|
|
16
|
+
|
|
17
|
+
- 0af2f7c: chore: upgrade to TypeScript 6
|
|
18
|
+
- 0c82824: fix(xai): preserve or report unavailable speaker diarization
|
|
19
|
+
- Updated dependencies [fc1e19e]
|
|
20
|
+
- Updated dependencies [5094ebd]
|
|
21
|
+
- Updated dependencies [268225c]
|
|
22
|
+
- Updated dependencies [0af2f7c]
|
|
23
|
+
- @ai-sdk/provider-utils@5.0.55
|
|
24
|
+
- @ai-sdk/provider@4.0.23
|
|
25
|
+
|
|
26
|
+
## 5.0.15
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 30f32bd: feat(xai): add grok-imagine-image-2.0 image model id
|
|
31
|
+
- 0a84440: feat(xai): add `auto` image quality option
|
|
32
|
+
- 08d7f0a: feat(xai): add `1.5k` image resolution provider option
|
|
33
|
+
- 7c41e41: feat(xai): support transcription model ids, `vadThreshold`, and `opus` audio format
|
|
34
|
+
- Updated dependencies [2959d35]
|
|
35
|
+
- Updated dependencies [59116e6]
|
|
36
|
+
- @ai-sdk/provider@4.0.22
|
|
37
|
+
- @ai-sdk/provider-utils@5.0.54
|
|
38
|
+
|
|
3
39
|
## 5.0.14
|
|
4
40
|
|
|
5
41
|
### 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,KAAA;KAEU,uBAAuB,EAAE,aAAa;;;KCXtC;;;cCIN,kBAAgB,EAAA;;;;;KAIjB,qBAAqB,EAAE,aAAa;cAEnC,gBAAc,EAAA;;;GAGlB,EAAA,KAAA;cAEI,sBAAoB,EAAA;;;;;;GAWxB,EAAA,KAAA;KAEU,mBAA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ACA;;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;
|
|
@@ -1417,7 +1427,8 @@ var XaiResponsesLanguageModel = class XaiResponsesLanguageModel {
|
|
|
1417
1427
|
low: "low",
|
|
1418
1428
|
medium: "medium",
|
|
1419
1429
|
high: "high",
|
|
1420
|
-
xhigh: modelId === "grok-4.6" ? "xhigh" : "high"
|
|
1430
|
+
xhigh: modelId === "grok-4.6" ? "xhigh" : "high",
|
|
1431
|
+
max: modelId === "grok-4.6" ? "xhigh" : "high"
|
|
1421
1432
|
},
|
|
1422
1433
|
warnings
|
|
1423
1434
|
});
|
|
@@ -3077,7 +3088,7 @@ const xaiTools = {
|
|
|
3077
3088
|
};
|
|
3078
3089
|
//#endregion
|
|
3079
3090
|
//#region src/version.ts
|
|
3080
|
-
const VERSION = "5.0.
|
|
3091
|
+
const VERSION = "5.0.16";
|
|
3081
3092
|
//#endregion
|
|
3082
3093
|
//#region src/files/xai-files-options.ts
|
|
3083
3094
|
const xaiFilesOptionsSchema = lazySchema(() => zodSchema(z.looseObject({
|
|
@@ -3930,12 +3941,16 @@ const xaiSpeechTimestampsResponseSchema = z.object({
|
|
|
3930
3941
|
//#region src/xai-transcription-model-options.ts
|
|
3931
3942
|
const xaiTranscriptionModelOptionsSchema = lazySchema(() => zodSchema(z.object({
|
|
3932
3943
|
/**
|
|
3933
|
-
*
|
|
3944
|
+
* Input audio encoding for raw, headerless audio: `pcm`, `mulaw`, or
|
|
3945
|
+
* `alaw`. Container formats such as Ogg/Opus are auto-detected, so do
|
|
3946
|
+
* not set this for them. `opus` is for streaming only, with one raw Opus
|
|
3947
|
+
* packet per chunk.
|
|
3934
3948
|
*/
|
|
3935
3949
|
audioFormat: z.enum([
|
|
3936
3950
|
"pcm",
|
|
3937
3951
|
"mulaw",
|
|
3938
|
-
"alaw"
|
|
3952
|
+
"alaw",
|
|
3953
|
+
"opus"
|
|
3939
3954
|
]).nullish(),
|
|
3940
3955
|
/**
|
|
3941
3956
|
* Sample rate of the input audio in Hz.
|
|
@@ -3977,6 +3992,11 @@ const xaiTranscriptionModelOptionsSchema = lazySchema(() => zodSchema(z.object({
|
|
|
3977
3992
|
*/
|
|
3978
3993
|
fillerWords: z.boolean().nullish(),
|
|
3979
3994
|
/**
|
|
3995
|
+
* Voice activity detection threshold between 0 and 1. Defaults to 0.5
|
|
3996
|
+
* for `transcribe` and 0.08 for streaming. 0 disables the filter.
|
|
3997
|
+
*/
|
|
3998
|
+
vadThreshold: z.number().min(0).max(1).optional(),
|
|
3999
|
+
/**
|
|
3980
4000
|
* Options for streaming speech-to-text over WebSocket.
|
|
3981
4001
|
*/
|
|
3982
4002
|
streaming: z.object({
|
|
@@ -4026,21 +4046,11 @@ var XaiTranscriptionModel = class XaiTranscriptionModel {
|
|
|
4026
4046
|
schema: xaiTranscriptionModelOptionsSchema
|
|
4027
4047
|
});
|
|
4028
4048
|
const formData = new FormData();
|
|
4029
|
-
|
|
4049
|
+
appendXaiSttParams(formData, {
|
|
4050
|
+
...getXaiSttParams(this.modelId, xaiOptions),
|
|
4030
4051
|
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
|
-
}
|
|
4052
|
+
format: xaiOptions?.format
|
|
4053
|
+
});
|
|
4044
4054
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
4045
4055
|
const fileExtension = mediaTypeToExtension(mediaType);
|
|
4046
4056
|
formData.append("file", new File([blob], "audio", { type: mediaType }), `audio.${fileExtension}`);
|
|
@@ -4076,7 +4086,8 @@ var XaiTranscriptionModel = class XaiTranscriptionModel {
|
|
|
4076
4086
|
modelId: this.modelId,
|
|
4077
4087
|
headers: responseHeaders,
|
|
4078
4088
|
body: rawResponse
|
|
4079
|
-
}
|
|
4089
|
+
},
|
|
4090
|
+
...response.words?.some((word) => word.speaker != null) && { providerMetadata: { xai: { words: response.words } } }
|
|
4080
4091
|
};
|
|
4081
4092
|
}
|
|
4082
4093
|
async doStream(options) {
|
|
@@ -4096,12 +4107,13 @@ var XaiTranscriptionModel = class XaiTranscriptionModel {
|
|
|
4096
4107
|
feature: "providerOptions.xai.format",
|
|
4097
4108
|
details: "xAI streaming transcription does not support format."
|
|
4098
4109
|
});
|
|
4099
|
-
if (xaiOptions?.audioFormat == null && !
|
|
4110
|
+
if (xaiOptions?.audioFormat == null && !inputAudioFormatEncodings.has(options.inputAudioFormat.type)) warnings.push({
|
|
4100
4111
|
type: "other",
|
|
4101
|
-
message: `Unrecognized inputAudioFormat.type "${options.inputAudioFormat.type}"; falling back to raw PCM encoding. Use
|
|
4112
|
+
message: `Unrecognized inputAudioFormat.type "${options.inputAudioFormat.type}"; falling back to raw PCM encoding. Use ${[...inputAudioFormatEncodings.keys()].join(", ")}, or set providerOptions.xai.audioFormat explicitly.`
|
|
4102
4113
|
});
|
|
4103
4114
|
const url = buildXaiStreamingTranscriptionUrl({
|
|
4104
4115
|
baseURL: this.config.baseURL ?? "https://api.x.ai/v1",
|
|
4116
|
+
modelId: this.modelId,
|
|
4105
4117
|
inputAudioFormat: options.inputAudioFormat,
|
|
4106
4118
|
providerOptions: xaiOptions
|
|
4107
4119
|
});
|
|
@@ -4262,38 +4274,42 @@ function createXaiStreamingTranscriptionStream({ webSocket, url, headers, warnin
|
|
|
4262
4274
|
}
|
|
4263
4275
|
});
|
|
4264
4276
|
}
|
|
4265
|
-
function buildXaiStreamingTranscriptionUrl({ baseURL, inputAudioFormat, providerOptions }) {
|
|
4277
|
+
function buildXaiStreamingTranscriptionUrl({ baseURL, modelId, inputAudioFormat, providerOptions }) {
|
|
4266
4278
|
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
|
-
}
|
|
4279
|
+
const params = getXaiSttParams(modelId, providerOptions);
|
|
4280
|
+
appendXaiSttParams(url.searchParams, {
|
|
4281
|
+
...params,
|
|
4282
|
+
sample_rate: params.sample_rate ?? inputAudioFormat.rate,
|
|
4283
|
+
encoding: providerOptions?.audioFormat ?? inputAudioFormatEncodings.get(inputAudioFormat.type) ?? "pcm",
|
|
4284
|
+
interim_results: providerOptions?.streaming?.interimResults,
|
|
4285
|
+
endpointing: providerOptions?.streaming?.endpointing,
|
|
4286
|
+
smart_turn: providerOptions?.streaming?.smartTurn,
|
|
4287
|
+
smart_turn_timeout: providerOptions?.streaming?.smartTurnTimeout
|
|
4288
|
+
});
|
|
4282
4289
|
return url;
|
|
4283
4290
|
}
|
|
4284
|
-
function
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4291
|
+
function getXaiSttParams(modelId, options) {
|
|
4292
|
+
return {
|
|
4293
|
+
model: modelId || void 0,
|
|
4294
|
+
sample_rate: options?.sampleRate,
|
|
4295
|
+
language: options?.language,
|
|
4296
|
+
multichannel: options?.multichannel,
|
|
4297
|
+
channels: options?.channels,
|
|
4298
|
+
diarize: options?.diarize,
|
|
4299
|
+
filler_words: options?.fillerWords,
|
|
4300
|
+
vad_threshold: options?.vadThreshold,
|
|
4301
|
+
keyterm: options?.keyterm
|
|
4302
|
+
};
|
|
4289
4303
|
}
|
|
4290
|
-
function
|
|
4291
|
-
|
|
4292
|
-
case "audio/pcmu": return "mulaw";
|
|
4293
|
-
case "audio/pcma": return "alaw";
|
|
4294
|
-
default: return "pcm";
|
|
4295
|
-
}
|
|
4304
|
+
function appendXaiSttParams(target, params) {
|
|
4305
|
+
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
4306
|
}
|
|
4307
|
+
const inputAudioFormatEncodings = /* @__PURE__ */ new Map([
|
|
4308
|
+
["audio/pcm", "pcm"],
|
|
4309
|
+
["audio/pcmu", "mulaw"],
|
|
4310
|
+
["audio/pcma", "alaw"],
|
|
4311
|
+
["audio/opus", "opus"]
|
|
4312
|
+
]);
|
|
4297
4313
|
function channelId(channelIndex) {
|
|
4298
4314
|
return channelIndex == null ? void 0 : `channel-${channelIndex}`;
|
|
4299
4315
|
}
|
|
@@ -4310,7 +4326,8 @@ const xaiTranscriptionResponseSchema = z.object({
|
|
|
4310
4326
|
words: z.array(z.object({
|
|
4311
4327
|
text: z.string(),
|
|
4312
4328
|
start: z.number(),
|
|
4313
|
-
end: z.number()
|
|
4329
|
+
end: z.number(),
|
|
4330
|
+
speaker: z.number().nullish()
|
|
4314
4331
|
})).nullish()
|
|
4315
4332
|
});
|
|
4316
4333
|
//#endregion
|
|
@@ -4366,8 +4383,8 @@ function createXai(options = {}) {
|
|
|
4366
4383
|
fetch: options.fetch
|
|
4367
4384
|
});
|
|
4368
4385
|
};
|
|
4369
|
-
const createTranscriptionModel = () => {
|
|
4370
|
-
return new XaiTranscriptionModel(
|
|
4386
|
+
const createTranscriptionModel = (modelId = "") => {
|
|
4387
|
+
return new XaiTranscriptionModel(modelId, {
|
|
4371
4388
|
provider: "xai.transcription",
|
|
4372
4389
|
baseURL,
|
|
4373
4390
|
headers: getHeaders,
|