@mistralai/mistralai 1.7.4 → 1.9.17
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/README.md +10 -0
- package/docs/sdks/accesses/README.md +2 -0
- package/docs/sdks/audio/README.md +6 -0
- package/docs/sdks/documents/README.md +2 -0
- package/docs/sdks/libraries/README.md +1 -1
- package/docs/sdks/transcriptions/README.md +167 -0
- package/examples/src/async_audio_transcription_stream.ts +17 -0
- package/funcs/audioTranscriptionsComplete.d.ts +13 -0
- package/funcs/audioTranscriptionsComplete.d.ts.map +1 -0
- package/funcs/audioTranscriptionsComplete.js +133 -0
- package/funcs/audioTranscriptionsComplete.js.map +1 -0
- package/funcs/audioTranscriptionsStream.d.ts +14 -0
- package/funcs/audioTranscriptionsStream.d.ts.map +1 -0
- package/funcs/audioTranscriptionsStream.js +143 -0
- package/funcs/audioTranscriptionsStream.js.map +1 -0
- package/funcs/batchJobsList.js +1 -0
- package/funcs/batchJobsList.js.map +1 -1
- package/jsr.json +1 -1
- package/lib/config.d.ts +2 -2
- package/lib/config.js +2 -2
- package/lib/config.js.map +1 -1
- package/models/components/audiochunk.d.ts +54 -0
- package/models/components/audiochunk.d.ts.map +1 -0
- package/models/components/audiochunk.js +88 -0
- package/models/components/audiochunk.js.map +1 -0
- package/models/components/audiotranscriptionrequest.d.ts +57 -0
- package/models/components/audiotranscriptionrequest.d.ts.map +1 -0
- package/models/components/audiotranscriptionrequest.js +91 -0
- package/models/components/audiotranscriptionrequest.js.map +1 -0
- package/models/components/audiotranscriptionrequeststream.d.ts +57 -0
- package/models/components/audiotranscriptionrequeststream.d.ts.map +1 -0
- package/models/components/audiotranscriptionrequeststream.js +91 -0
- package/models/components/audiotranscriptionrequeststream.js.map +1 -0
- package/models/components/basemodelcard.d.ts +7 -7
- package/models/components/basemodelcard.d.ts.map +1 -1
- package/models/components/basemodelcard.js +11 -11
- package/models/components/basemodelcard.js.map +1 -1
- package/models/components/batchjobin.d.ts +4 -2
- package/models/components/batchjobin.d.ts.map +1 -1
- package/models/components/batchjobin.js +6 -2
- package/models/components/batchjobin.js.map +1 -1
- package/models/components/batchjobout.d.ts +4 -2
- package/models/components/batchjobout.d.ts.map +1 -1
- package/models/components/batchjobout.js +6 -2
- package/models/components/batchjobout.js.map +1 -1
- package/models/components/classifierftmodelout.d.ts +4 -0
- package/models/components/classifierftmodelout.d.ts.map +1 -1
- package/models/components/classifierftmodelout.js +8 -0
- package/models/components/classifierftmodelout.js.map +1 -1
- package/models/components/completionargs.d.ts +2 -2
- package/models/components/completionargs.d.ts.map +1 -1
- package/models/components/completionargs.js +2 -2
- package/models/components/completionargs.js.map +1 -1
- package/models/components/completionftmodelout.d.ts +4 -0
- package/models/components/completionftmodelout.d.ts.map +1 -1
- package/models/components/completionftmodelout.js +8 -0
- package/models/components/completionftmodelout.js.map +1 -1
- package/models/components/contentchunk.d.ts +10 -0
- package/models/components/contentchunk.d.ts.map +1 -1
- package/models/components/contentchunk.js +14 -0
- package/models/components/contentchunk.js.map +1 -1
- package/models/components/fileschema.d.ts +4 -0
- package/models/components/fileschema.d.ts.map +1 -1
- package/models/components/fileschema.js +4 -0
- package/models/components/fileschema.js.map +1 -1
- package/models/components/index.d.ts +13 -0
- package/models/components/index.d.ts.map +1 -1
- package/models/components/index.js +13 -0
- package/models/components/index.js.map +1 -1
- package/models/components/messageoutputcontentchunks.d.ts +3 -2
- package/models/components/messageoutputcontentchunks.d.ts.map +1 -1
- package/models/components/messageoutputcontentchunks.js +3 -0
- package/models/components/messageoutputcontentchunks.js.map +1 -1
- package/models/components/outputcontentchunks.d.ts +3 -2
- package/models/components/outputcontentchunks.d.ts.map +1 -1
- package/models/components/outputcontentchunks.js +3 -0
- package/models/components/outputcontentchunks.js.map +1 -1
- package/models/components/retrievefileout.d.ts +4 -0
- package/models/components/retrievefileout.d.ts.map +1 -1
- package/models/components/retrievefileout.js +4 -0
- package/models/components/retrievefileout.js.map +1 -1
- package/models/components/thinkchunk.d.ts +82 -0
- package/models/components/thinkchunk.d.ts.map +1 -0
- package/models/components/thinkchunk.js +106 -0
- package/models/components/thinkchunk.js.map +1 -0
- package/models/components/timestampgranularity.d.ts +25 -0
- package/models/components/timestampgranularity.d.ts.map +1 -0
- package/models/components/timestampgranularity.js +49 -0
- package/models/components/timestampgranularity.js.map +1 -0
- package/models/components/transcriptionresponse.d.ts +43 -0
- package/models/components/transcriptionresponse.d.ts.map +1 -0
- package/models/components/transcriptionresponse.js +78 -0
- package/models/components/transcriptionresponse.js.map +1 -0
- package/models/components/transcriptionsegmentchunk.d.ts +62 -0
- package/models/components/transcriptionsegmentchunk.d.ts.map +1 -0
- package/models/components/transcriptionsegmentchunk.js +92 -0
- package/models/components/transcriptionsegmentchunk.js.map +1 -0
- package/models/components/transcriptionstreamdone.d.ts +68 -0
- package/models/components/transcriptionstreamdone.d.ts.map +1 -0
- package/models/components/transcriptionstreamdone.js +98 -0
- package/models/components/transcriptionstreamdone.js.map +1 -0
- package/models/components/transcriptionstreamevents.d.ts +89 -0
- package/models/components/transcriptionstreamevents.d.ts.map +1 -0
- package/models/components/transcriptionstreamevents.js +138 -0
- package/models/components/transcriptionstreamevents.js.map +1 -0
- package/models/components/transcriptionstreameventtypes.d.ts +34 -0
- package/models/components/transcriptionstreameventtypes.d.ts.map +1 -0
- package/models/components/transcriptionstreameventtypes.js +52 -0
- package/models/components/transcriptionstreameventtypes.js.map +1 -0
- package/models/components/transcriptionstreamlanguage.d.ts +58 -0
- package/models/components/transcriptionstreamlanguage.d.ts.map +1 -0
- package/models/components/transcriptionstreamlanguage.js +93 -0
- package/models/components/transcriptionstreamlanguage.js.map +1 -0
- package/models/components/transcriptionstreamsegmentdelta.d.ts +62 -0
- package/models/components/transcriptionstreamsegmentdelta.d.ts.map +1 -0
- package/models/components/transcriptionstreamsegmentdelta.js +92 -0
- package/models/components/transcriptionstreamsegmentdelta.js.map +1 -0
- package/models/components/transcriptionstreamtextdelta.d.ts +58 -0
- package/models/components/transcriptionstreamtextdelta.d.ts.map +1 -0
- package/models/components/transcriptionstreamtextdelta.js +88 -0
- package/models/components/transcriptionstreamtextdelta.js.map +1 -0
- package/models/components/uploadfileout.d.ts +4 -0
- package/models/components/uploadfileout.d.ts.map +1 -1
- package/models/components/uploadfileout.js +4 -0
- package/models/components/uploadfileout.js.map +1 -1
- package/models/components/usageinfo.d.ts +9 -3
- package/models/components/usageinfo.d.ts.map +1 -1
- package/models/components/usageinfo.js +22 -13
- package/models/components/usageinfo.js.map +1 -1
- package/models/operations/jobsapiroutesbatchgetbatchjobs.d.ts +2 -0
- package/models/operations/jobsapiroutesbatchgetbatchjobs.d.ts.map +1 -1
- package/models/operations/jobsapiroutesbatchgetbatchjobs.js +4 -0
- package/models/operations/jobsapiroutesbatchgetbatchjobs.js.map +1 -1
- package/package.json +1 -1
- package/sdk/audio.d.ts +7 -0
- package/sdk/audio.d.ts.map +1 -0
- package/sdk/audio.js +15 -0
- package/sdk/audio.js.map +1 -0
- package/sdk/sdk.d.ts +3 -0
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +4 -0
- package/sdk/sdk.js.map +1 -1
- package/sdk/transcriptions.d.ts +14 -0
- package/sdk/transcriptions.d.ts.map +1 -0
- package/sdk/transcriptions.js +26 -0
- package/sdk/transcriptions.js.map +1 -0
- package/src/funcs/audioTranscriptionsComplete.ts +193 -0
- package/src/funcs/audioTranscriptionsStream.ts +207 -0
- package/src/funcs/batchJobsList.ts +1 -0
- package/src/lib/config.ts +2 -2
- package/src/models/components/audiochunk.ts +102 -0
- package/src/models/components/audiotranscriptionrequest.ts +133 -0
- package/src/models/components/audiotranscriptionrequeststream.ts +135 -0
- package/src/models/components/basemodelcard.ts +13 -12
- package/src/models/components/batchjobin.ts +10 -4
- package/src/models/components/batchjobout.ts +10 -4
- package/src/models/components/classifierftmodelout.ts +12 -0
- package/src/models/components/completionargs.ts +4 -4
- package/src/models/components/completionftmodelout.ts +12 -0
- package/src/models/components/contentchunk.ts +38 -2
- package/src/models/components/fileschema.ts +8 -0
- package/src/models/components/index.ts +13 -0
- package/src/models/components/messageoutputcontentchunks.ts +10 -0
- package/src/models/components/outputcontentchunks.ts +10 -0
- package/src/models/components/retrievefileout.ts +8 -0
- package/src/models/components/thinkchunk.ts +162 -0
- package/src/models/components/timestampgranularity.ts +32 -0
- package/src/models/components/transcriptionresponse.ts +112 -0
- package/src/models/components/transcriptionsegmentchunk.ts +122 -0
- package/src/models/components/transcriptionstreamdone.ts +149 -0
- package/src/models/components/transcriptionstreamevents.ts +273 -0
- package/src/models/components/transcriptionstreameventtypes.ts +37 -0
- package/src/models/components/transcriptionstreamlanguage.ts +128 -0
- package/src/models/components/transcriptionstreamsegmentdelta.ts +133 -0
- package/src/models/components/transcriptionstreamtextdelta.ts +123 -0
- package/src/models/components/uploadfileout.ts +8 -0
- package/src/models/components/usageinfo.ts +37 -17
- package/src/models/operations/jobsapiroutesbatchgetbatchjobs.ts +6 -0
- package/src/sdk/audio.ts +13 -0
- package/src/sdk/sdk.ts +6 -0
- package/src/sdk/transcriptions.ts +40 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { MistralCore } from "../core.js";
|
|
6
|
+
import { appendForm } from "../lib/encodings.js";
|
|
7
|
+
import { readableStreamToArrayBuffer } from "../lib/files.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
13
|
+
import { pathToFunc } from "../lib/url.js";
|
|
14
|
+
import * as components from "../models/components/index.js";
|
|
15
|
+
import {
|
|
16
|
+
ConnectionError,
|
|
17
|
+
InvalidRequestError,
|
|
18
|
+
RequestAbortedError,
|
|
19
|
+
RequestTimeoutError,
|
|
20
|
+
UnexpectedClientError,
|
|
21
|
+
} from "../models/errors/httpclienterrors.js";
|
|
22
|
+
import { SDKError } from "../models/errors/sdkerror.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
24
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
25
|
+
import { isBlobLike } from "../types/blobs.js";
|
|
26
|
+
import { Result } from "../types/fp.js";
|
|
27
|
+
import { isReadableStream } from "../types/streams.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create Transcription
|
|
31
|
+
*/
|
|
32
|
+
export function audioTranscriptionsComplete(
|
|
33
|
+
client: MistralCore,
|
|
34
|
+
request: components.AudioTranscriptionRequest,
|
|
35
|
+
options?: RequestOptions,
|
|
36
|
+
): APIPromise<
|
|
37
|
+
Result<
|
|
38
|
+
components.TranscriptionResponse,
|
|
39
|
+
| SDKError
|
|
40
|
+
| SDKValidationError
|
|
41
|
+
| UnexpectedClientError
|
|
42
|
+
| InvalidRequestError
|
|
43
|
+
| RequestAbortedError
|
|
44
|
+
| RequestTimeoutError
|
|
45
|
+
| ConnectionError
|
|
46
|
+
>
|
|
47
|
+
> {
|
|
48
|
+
return new APIPromise($do(
|
|
49
|
+
client,
|
|
50
|
+
request,
|
|
51
|
+
options,
|
|
52
|
+
));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function $do(
|
|
56
|
+
client: MistralCore,
|
|
57
|
+
request: components.AudioTranscriptionRequest,
|
|
58
|
+
options?: RequestOptions,
|
|
59
|
+
): Promise<
|
|
60
|
+
[
|
|
61
|
+
Result<
|
|
62
|
+
components.TranscriptionResponse,
|
|
63
|
+
| SDKError
|
|
64
|
+
| SDKValidationError
|
|
65
|
+
| UnexpectedClientError
|
|
66
|
+
| InvalidRequestError
|
|
67
|
+
| RequestAbortedError
|
|
68
|
+
| RequestTimeoutError
|
|
69
|
+
| ConnectionError
|
|
70
|
+
>,
|
|
71
|
+
APICall,
|
|
72
|
+
]
|
|
73
|
+
> {
|
|
74
|
+
const parsed = safeParse(
|
|
75
|
+
request,
|
|
76
|
+
(value) => components.AudioTranscriptionRequest$outboundSchema.parse(value),
|
|
77
|
+
"Input validation failed",
|
|
78
|
+
);
|
|
79
|
+
if (!parsed.ok) {
|
|
80
|
+
return [parsed, { status: "invalid" }];
|
|
81
|
+
}
|
|
82
|
+
const payload = parsed.value;
|
|
83
|
+
const body = new FormData();
|
|
84
|
+
|
|
85
|
+
appendForm(body, "model", payload.model);
|
|
86
|
+
if (payload.file !== undefined) {
|
|
87
|
+
if (isBlobLike(payload.file)) {
|
|
88
|
+
appendForm(body, "file", payload.file);
|
|
89
|
+
} else if (isReadableStream(payload.file.content)) {
|
|
90
|
+
const buffer = await readableStreamToArrayBuffer(payload.file.content);
|
|
91
|
+
const blob = new Blob([buffer], { type: "application/octet-stream" });
|
|
92
|
+
appendForm(body, "file", blob);
|
|
93
|
+
} else {
|
|
94
|
+
appendForm(
|
|
95
|
+
body,
|
|
96
|
+
"file",
|
|
97
|
+
new Blob([payload.file.content], { type: "application/octet-stream" }),
|
|
98
|
+
payload.file.fileName,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (payload.file_id !== undefined) {
|
|
103
|
+
appendForm(body, "file_id", payload.file_id);
|
|
104
|
+
}
|
|
105
|
+
if (payload.file_url !== undefined) {
|
|
106
|
+
appendForm(body, "file_url", payload.file_url);
|
|
107
|
+
}
|
|
108
|
+
if (payload.language !== undefined) {
|
|
109
|
+
appendForm(body, "language", payload.language);
|
|
110
|
+
}
|
|
111
|
+
if (payload.stream !== undefined) {
|
|
112
|
+
appendForm(body, "stream", payload.stream);
|
|
113
|
+
}
|
|
114
|
+
if (payload.temperature !== undefined) {
|
|
115
|
+
appendForm(body, "temperature", payload.temperature);
|
|
116
|
+
}
|
|
117
|
+
if (payload.timestamp_granularities !== undefined) {
|
|
118
|
+
appendForm(
|
|
119
|
+
body,
|
|
120
|
+
"timestamp_granularities",
|
|
121
|
+
payload.timestamp_granularities,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const path = pathToFunc("/v1/audio/transcriptions")();
|
|
126
|
+
|
|
127
|
+
const headers = new Headers(compactMap({
|
|
128
|
+
Accept: "application/json",
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
132
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
133
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
134
|
+
|
|
135
|
+
const context = {
|
|
136
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
137
|
+
operationID: "audio_api_v1_transcriptions_post",
|
|
138
|
+
oAuth2Scopes: [],
|
|
139
|
+
|
|
140
|
+
resolvedSecurity: requestSecurity,
|
|
141
|
+
|
|
142
|
+
securitySource: client._options.apiKey,
|
|
143
|
+
retryConfig: options?.retries
|
|
144
|
+
|| client._options.retryConfig
|
|
145
|
+
|| { strategy: "none" },
|
|
146
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const requestRes = client._createRequest(context, {
|
|
150
|
+
security: requestSecurity,
|
|
151
|
+
method: "POST",
|
|
152
|
+
baseURL: options?.serverURL,
|
|
153
|
+
path: path,
|
|
154
|
+
headers: headers,
|
|
155
|
+
body: body,
|
|
156
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
157
|
+
}, options);
|
|
158
|
+
if (!requestRes.ok) {
|
|
159
|
+
return [requestRes, { status: "invalid" }];
|
|
160
|
+
}
|
|
161
|
+
const req = requestRes.value;
|
|
162
|
+
|
|
163
|
+
const doResult = await client._do(req, {
|
|
164
|
+
context,
|
|
165
|
+
errorCodes: ["4XX", "5XX"],
|
|
166
|
+
retryConfig: context.retryConfig,
|
|
167
|
+
retryCodes: context.retryCodes,
|
|
168
|
+
});
|
|
169
|
+
if (!doResult.ok) {
|
|
170
|
+
return [doResult, { status: "request-error", request: req }];
|
|
171
|
+
}
|
|
172
|
+
const response = doResult.value;
|
|
173
|
+
|
|
174
|
+
const [result] = await M.match<
|
|
175
|
+
components.TranscriptionResponse,
|
|
176
|
+
| SDKError
|
|
177
|
+
| SDKValidationError
|
|
178
|
+
| UnexpectedClientError
|
|
179
|
+
| InvalidRequestError
|
|
180
|
+
| RequestAbortedError
|
|
181
|
+
| RequestTimeoutError
|
|
182
|
+
| ConnectionError
|
|
183
|
+
>(
|
|
184
|
+
M.json(200, components.TranscriptionResponse$inboundSchema),
|
|
185
|
+
M.fail("4XX"),
|
|
186
|
+
M.fail("5XX"),
|
|
187
|
+
)(response);
|
|
188
|
+
if (!result.ok) {
|
|
189
|
+
return [result, { status: "complete", request: req, response }];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return [result, { status: "complete", request: req, response }];
|
|
193
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { MistralCore } from "../core.js";
|
|
7
|
+
import { appendForm } from "../lib/encodings.js";
|
|
8
|
+
import { EventStream } from "../lib/event-streams.js";
|
|
9
|
+
import { readableStreamToArrayBuffer } from "../lib/files.js";
|
|
10
|
+
import * as M from "../lib/matchers.js";
|
|
11
|
+
import { compactMap } from "../lib/primitives.js";
|
|
12
|
+
import { safeParse } from "../lib/schemas.js";
|
|
13
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
14
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
15
|
+
import { pathToFunc } from "../lib/url.js";
|
|
16
|
+
import * as components from "../models/components/index.js";
|
|
17
|
+
import {
|
|
18
|
+
ConnectionError,
|
|
19
|
+
InvalidRequestError,
|
|
20
|
+
RequestAbortedError,
|
|
21
|
+
RequestTimeoutError,
|
|
22
|
+
UnexpectedClientError,
|
|
23
|
+
} from "../models/errors/httpclienterrors.js";
|
|
24
|
+
import { SDKError } from "../models/errors/sdkerror.js";
|
|
25
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { isBlobLike } from "../types/blobs.js";
|
|
28
|
+
import { Result } from "../types/fp.js";
|
|
29
|
+
import { isReadableStream } from "../types/streams.js";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create streaming transcription (SSE)
|
|
33
|
+
*/
|
|
34
|
+
export function audioTranscriptionsStream(
|
|
35
|
+
client: MistralCore,
|
|
36
|
+
request: components.AudioTranscriptionRequestStream,
|
|
37
|
+
options?: RequestOptions,
|
|
38
|
+
): APIPromise<
|
|
39
|
+
Result<
|
|
40
|
+
EventStream<components.TranscriptionStreamEvents>,
|
|
41
|
+
| SDKError
|
|
42
|
+
| SDKValidationError
|
|
43
|
+
| UnexpectedClientError
|
|
44
|
+
| InvalidRequestError
|
|
45
|
+
| RequestAbortedError
|
|
46
|
+
| RequestTimeoutError
|
|
47
|
+
| ConnectionError
|
|
48
|
+
>
|
|
49
|
+
> {
|
|
50
|
+
return new APIPromise($do(
|
|
51
|
+
client,
|
|
52
|
+
request,
|
|
53
|
+
options,
|
|
54
|
+
));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function $do(
|
|
58
|
+
client: MistralCore,
|
|
59
|
+
request: components.AudioTranscriptionRequestStream,
|
|
60
|
+
options?: RequestOptions,
|
|
61
|
+
): Promise<
|
|
62
|
+
[
|
|
63
|
+
Result<
|
|
64
|
+
EventStream<components.TranscriptionStreamEvents>,
|
|
65
|
+
| SDKError
|
|
66
|
+
| SDKValidationError
|
|
67
|
+
| UnexpectedClientError
|
|
68
|
+
| InvalidRequestError
|
|
69
|
+
| RequestAbortedError
|
|
70
|
+
| RequestTimeoutError
|
|
71
|
+
| ConnectionError
|
|
72
|
+
>,
|
|
73
|
+
APICall,
|
|
74
|
+
]
|
|
75
|
+
> {
|
|
76
|
+
const parsed = safeParse(
|
|
77
|
+
request,
|
|
78
|
+
(value) =>
|
|
79
|
+
components.AudioTranscriptionRequestStream$outboundSchema.parse(value),
|
|
80
|
+
"Input validation failed",
|
|
81
|
+
);
|
|
82
|
+
if (!parsed.ok) {
|
|
83
|
+
return [parsed, { status: "invalid" }];
|
|
84
|
+
}
|
|
85
|
+
const payload = parsed.value;
|
|
86
|
+
const body = new FormData();
|
|
87
|
+
|
|
88
|
+
appendForm(body, "model", payload.model);
|
|
89
|
+
if (payload.file !== undefined) {
|
|
90
|
+
if (isBlobLike(payload.file)) {
|
|
91
|
+
appendForm(body, "file", payload.file);
|
|
92
|
+
} else if (isReadableStream(payload.file.content)) {
|
|
93
|
+
const buffer = await readableStreamToArrayBuffer(payload.file.content);
|
|
94
|
+
const blob = new Blob([buffer], { type: "application/octet-stream" });
|
|
95
|
+
appendForm(body, "file", blob);
|
|
96
|
+
} else {
|
|
97
|
+
appendForm(
|
|
98
|
+
body,
|
|
99
|
+
"file",
|
|
100
|
+
new Blob([payload.file.content], { type: "application/octet-stream" }),
|
|
101
|
+
payload.file.fileName,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (payload.file_id !== undefined) {
|
|
106
|
+
appendForm(body, "file_id", payload.file_id);
|
|
107
|
+
}
|
|
108
|
+
if (payload.file_url !== undefined) {
|
|
109
|
+
appendForm(body, "file_url", payload.file_url);
|
|
110
|
+
}
|
|
111
|
+
if (payload.language !== undefined) {
|
|
112
|
+
appendForm(body, "language", payload.language);
|
|
113
|
+
}
|
|
114
|
+
if (payload.stream !== undefined) {
|
|
115
|
+
appendForm(body, "stream", payload.stream);
|
|
116
|
+
}
|
|
117
|
+
if (payload.temperature !== undefined) {
|
|
118
|
+
appendForm(body, "temperature", payload.temperature);
|
|
119
|
+
}
|
|
120
|
+
if (payload.timestamp_granularities !== undefined) {
|
|
121
|
+
appendForm(
|
|
122
|
+
body,
|
|
123
|
+
"timestamp_granularities",
|
|
124
|
+
payload.timestamp_granularities,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const path = pathToFunc("/v1/audio/transcriptions#stream")();
|
|
129
|
+
|
|
130
|
+
const headers = new Headers(compactMap({
|
|
131
|
+
Accept: "text/event-stream",
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
135
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
136
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
137
|
+
|
|
138
|
+
const context = {
|
|
139
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
140
|
+
operationID: "audio_api_v1_transcriptions_post_stream",
|
|
141
|
+
oAuth2Scopes: [],
|
|
142
|
+
|
|
143
|
+
resolvedSecurity: requestSecurity,
|
|
144
|
+
|
|
145
|
+
securitySource: client._options.apiKey,
|
|
146
|
+
retryConfig: options?.retries
|
|
147
|
+
|| client._options.retryConfig
|
|
148
|
+
|| { strategy: "none" },
|
|
149
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const requestRes = client._createRequest(context, {
|
|
153
|
+
security: requestSecurity,
|
|
154
|
+
method: "POST",
|
|
155
|
+
baseURL: options?.serverURL,
|
|
156
|
+
path: path,
|
|
157
|
+
headers: headers,
|
|
158
|
+
body: body,
|
|
159
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
160
|
+
}, options);
|
|
161
|
+
if (!requestRes.ok) {
|
|
162
|
+
return [requestRes, { status: "invalid" }];
|
|
163
|
+
}
|
|
164
|
+
const req = requestRes.value;
|
|
165
|
+
|
|
166
|
+
const doResult = await client._do(req, {
|
|
167
|
+
context,
|
|
168
|
+
errorCodes: ["4XX", "5XX"],
|
|
169
|
+
retryConfig: context.retryConfig,
|
|
170
|
+
retryCodes: context.retryCodes,
|
|
171
|
+
});
|
|
172
|
+
if (!doResult.ok) {
|
|
173
|
+
return [doResult, { status: "request-error", request: req }];
|
|
174
|
+
}
|
|
175
|
+
const response = doResult.value;
|
|
176
|
+
|
|
177
|
+
const [result] = await M.match<
|
|
178
|
+
EventStream<components.TranscriptionStreamEvents>,
|
|
179
|
+
| SDKError
|
|
180
|
+
| SDKValidationError
|
|
181
|
+
| UnexpectedClientError
|
|
182
|
+
| InvalidRequestError
|
|
183
|
+
| RequestAbortedError
|
|
184
|
+
| RequestTimeoutError
|
|
185
|
+
| ConnectionError
|
|
186
|
+
>(
|
|
187
|
+
M.sse(
|
|
188
|
+
200,
|
|
189
|
+
z.instanceof(ReadableStream<Uint8Array>).transform(stream => {
|
|
190
|
+
return new EventStream({
|
|
191
|
+
stream,
|
|
192
|
+
decoder(rawEvent) {
|
|
193
|
+
const schema = components.TranscriptionStreamEvents$inboundSchema;
|
|
194
|
+
return schema.parse(rawEvent);
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
M.fail("4XX"),
|
|
200
|
+
M.fail("5XX"),
|
|
201
|
+
)(response);
|
|
202
|
+
if (!result.ok) {
|
|
203
|
+
return [result, { status: "complete", request: req, response }];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return [result, { status: "complete", request: req, response }];
|
|
207
|
+
}
|
package/src/lib/config.ts
CHANGED
|
@@ -55,8 +55,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
55
55
|
export const SDK_METADATA = {
|
|
56
56
|
language: "typescript",
|
|
57
57
|
openapiDocVersion: "1.0.0",
|
|
58
|
-
sdkVersion: "1.
|
|
58
|
+
sdkVersion: "1.9.17",
|
|
59
59
|
genVersion: "2.548.6",
|
|
60
60
|
userAgent:
|
|
61
|
-
"speakeasy-sdk/typescript 1.
|
|
61
|
+
"speakeasy-sdk/typescript 1.9.17 2.548.6 1.0.0 @mistralai/mistralai",
|
|
62
62
|
} as const;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { ClosedEnum } from "../../types/enums.js";
|
|
9
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
10
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
11
|
+
|
|
12
|
+
export const AudioChunkType = {
|
|
13
|
+
InputAudio: "input_audio",
|
|
14
|
+
} as const;
|
|
15
|
+
export type AudioChunkType = ClosedEnum<typeof AudioChunkType>;
|
|
16
|
+
|
|
17
|
+
export type AudioChunk = {
|
|
18
|
+
inputAudio: string;
|
|
19
|
+
type?: AudioChunkType | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const AudioChunkType$inboundSchema: z.ZodNativeEnum<
|
|
24
|
+
typeof AudioChunkType
|
|
25
|
+
> = z.nativeEnum(AudioChunkType);
|
|
26
|
+
|
|
27
|
+
/** @internal */
|
|
28
|
+
export const AudioChunkType$outboundSchema: z.ZodNativeEnum<
|
|
29
|
+
typeof AudioChunkType
|
|
30
|
+
> = AudioChunkType$inboundSchema;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
|
|
35
|
+
*/
|
|
36
|
+
export namespace AudioChunkType$ {
|
|
37
|
+
/** @deprecated use `AudioChunkType$inboundSchema` instead. */
|
|
38
|
+
export const inboundSchema = AudioChunkType$inboundSchema;
|
|
39
|
+
/** @deprecated use `AudioChunkType$outboundSchema` instead. */
|
|
40
|
+
export const outboundSchema = AudioChunkType$outboundSchema;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
export const AudioChunk$inboundSchema: z.ZodType<
|
|
45
|
+
AudioChunk,
|
|
46
|
+
z.ZodTypeDef,
|
|
47
|
+
unknown
|
|
48
|
+
> = z.object({
|
|
49
|
+
input_audio: z.string(),
|
|
50
|
+
type: AudioChunkType$inboundSchema.default("input_audio"),
|
|
51
|
+
}).transform((v) => {
|
|
52
|
+
return remap$(v, {
|
|
53
|
+
"input_audio": "inputAudio",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** @internal */
|
|
58
|
+
export type AudioChunk$Outbound = {
|
|
59
|
+
input_audio: string;
|
|
60
|
+
type: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** @internal */
|
|
64
|
+
export const AudioChunk$outboundSchema: z.ZodType<
|
|
65
|
+
AudioChunk$Outbound,
|
|
66
|
+
z.ZodTypeDef,
|
|
67
|
+
AudioChunk
|
|
68
|
+
> = z.object({
|
|
69
|
+
inputAudio: z.string(),
|
|
70
|
+
type: AudioChunkType$outboundSchema.default("input_audio"),
|
|
71
|
+
}).transform((v) => {
|
|
72
|
+
return remap$(v, {
|
|
73
|
+
inputAudio: "input_audio",
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @internal
|
|
79
|
+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
|
|
80
|
+
*/
|
|
81
|
+
export namespace AudioChunk$ {
|
|
82
|
+
/** @deprecated use `AudioChunk$inboundSchema` instead. */
|
|
83
|
+
export const inboundSchema = AudioChunk$inboundSchema;
|
|
84
|
+
/** @deprecated use `AudioChunk$outboundSchema` instead. */
|
|
85
|
+
export const outboundSchema = AudioChunk$outboundSchema;
|
|
86
|
+
/** @deprecated use `AudioChunk$Outbound` instead. */
|
|
87
|
+
export type Outbound = AudioChunk$Outbound;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function audioChunkToJSON(audioChunk: AudioChunk): string {
|
|
91
|
+
return JSON.stringify(AudioChunk$outboundSchema.parse(audioChunk));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function audioChunkFromJSON(
|
|
95
|
+
jsonString: string,
|
|
96
|
+
): SafeParseResult<AudioChunk, SDKValidationError> {
|
|
97
|
+
return safeParse(
|
|
98
|
+
jsonString,
|
|
99
|
+
(x) => AudioChunk$inboundSchema.parse(JSON.parse(x)),
|
|
100
|
+
`Failed to parse 'AudioChunk' from JSON`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { remap as remap$ } from "../../lib/primitives.js";
|
|
7
|
+
import { safeParse } from "../../lib/schemas.js";
|
|
8
|
+
import { blobLikeSchema } from "../../types/blobs.js";
|
|
9
|
+
import { Result as SafeParseResult } from "../../types/fp.js";
|
|
10
|
+
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
|
|
11
|
+
import {
|
|
12
|
+
FileT,
|
|
13
|
+
FileT$inboundSchema,
|
|
14
|
+
FileT$Outbound,
|
|
15
|
+
FileT$outboundSchema,
|
|
16
|
+
} from "./file.js";
|
|
17
|
+
import {
|
|
18
|
+
TimestampGranularity,
|
|
19
|
+
TimestampGranularity$inboundSchema,
|
|
20
|
+
TimestampGranularity$outboundSchema,
|
|
21
|
+
} from "./timestampgranularity.js";
|
|
22
|
+
|
|
23
|
+
export type AudioTranscriptionRequest = {
|
|
24
|
+
model: string;
|
|
25
|
+
file?: FileT | Blob | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* ID of a file uploaded to /v1/files
|
|
28
|
+
*/
|
|
29
|
+
fileId?: string | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Url of a file to be transcribed
|
|
32
|
+
*/
|
|
33
|
+
fileUrl?: string | null | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Language of the audio, e.g. 'en'. Providing the language can boost accuracy.
|
|
36
|
+
*/
|
|
37
|
+
language?: string | null | undefined;
|
|
38
|
+
stream?: false | undefined;
|
|
39
|
+
temperature?: number | null | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Granularities of timestamps to include in the response.
|
|
42
|
+
*/
|
|
43
|
+
timestampGranularities?: Array<TimestampGranularity> | undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** @internal */
|
|
47
|
+
export const AudioTranscriptionRequest$inboundSchema: z.ZodType<
|
|
48
|
+
AudioTranscriptionRequest,
|
|
49
|
+
z.ZodTypeDef,
|
|
50
|
+
unknown
|
|
51
|
+
> = z.object({
|
|
52
|
+
model: z.string(),
|
|
53
|
+
file: FileT$inboundSchema.optional(),
|
|
54
|
+
file_id: z.nullable(z.string()).optional(),
|
|
55
|
+
file_url: z.nullable(z.string()).optional(),
|
|
56
|
+
language: z.nullable(z.string()).optional(),
|
|
57
|
+
stream: z.literal(false).default(false),
|
|
58
|
+
temperature: z.nullable(z.number()).optional(),
|
|
59
|
+
timestamp_granularities: z.array(TimestampGranularity$inboundSchema)
|
|
60
|
+
.optional(),
|
|
61
|
+
}).transform((v) => {
|
|
62
|
+
return remap$(v, {
|
|
63
|
+
"file_id": "fileId",
|
|
64
|
+
"file_url": "fileUrl",
|
|
65
|
+
"timestamp_granularities": "timestampGranularities",
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/** @internal */
|
|
70
|
+
export type AudioTranscriptionRequest$Outbound = {
|
|
71
|
+
model: string;
|
|
72
|
+
file?: FileT$Outbound | Blob | undefined;
|
|
73
|
+
file_id?: string | null | undefined;
|
|
74
|
+
file_url?: string | null | undefined;
|
|
75
|
+
language?: string | null | undefined;
|
|
76
|
+
stream: false;
|
|
77
|
+
temperature?: number | null | undefined;
|
|
78
|
+
timestamp_granularities?: Array<string> | undefined;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** @internal */
|
|
82
|
+
export const AudioTranscriptionRequest$outboundSchema: z.ZodType<
|
|
83
|
+
AudioTranscriptionRequest$Outbound,
|
|
84
|
+
z.ZodTypeDef,
|
|
85
|
+
AudioTranscriptionRequest
|
|
86
|
+
> = z.object({
|
|
87
|
+
model: z.string(),
|
|
88
|
+
file: FileT$outboundSchema.or(blobLikeSchema).optional(),
|
|
89
|
+
fileId: z.nullable(z.string()).optional(),
|
|
90
|
+
fileUrl: z.nullable(z.string()).optional(),
|
|
91
|
+
language: z.nullable(z.string()).optional(),
|
|
92
|
+
stream: z.literal(false).default(false as const),
|
|
93
|
+
temperature: z.nullable(z.number()).optional(),
|
|
94
|
+
timestampGranularities: z.array(TimestampGranularity$outboundSchema)
|
|
95
|
+
.optional(),
|
|
96
|
+
}).transform((v) => {
|
|
97
|
+
return remap$(v, {
|
|
98
|
+
fileId: "file_id",
|
|
99
|
+
fileUrl: "file_url",
|
|
100
|
+
timestampGranularities: "timestamp_granularities",
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
|
|
107
|
+
*/
|
|
108
|
+
export namespace AudioTranscriptionRequest$ {
|
|
109
|
+
/** @deprecated use `AudioTranscriptionRequest$inboundSchema` instead. */
|
|
110
|
+
export const inboundSchema = AudioTranscriptionRequest$inboundSchema;
|
|
111
|
+
/** @deprecated use `AudioTranscriptionRequest$outboundSchema` instead. */
|
|
112
|
+
export const outboundSchema = AudioTranscriptionRequest$outboundSchema;
|
|
113
|
+
/** @deprecated use `AudioTranscriptionRequest$Outbound` instead. */
|
|
114
|
+
export type Outbound = AudioTranscriptionRequest$Outbound;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function audioTranscriptionRequestToJSON(
|
|
118
|
+
audioTranscriptionRequest: AudioTranscriptionRequest,
|
|
119
|
+
): string {
|
|
120
|
+
return JSON.stringify(
|
|
121
|
+
AudioTranscriptionRequest$outboundSchema.parse(audioTranscriptionRequest),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function audioTranscriptionRequestFromJSON(
|
|
126
|
+
jsonString: string,
|
|
127
|
+
): SafeParseResult<AudioTranscriptionRequest, SDKValidationError> {
|
|
128
|
+
return safeParse(
|
|
129
|
+
jsonString,
|
|
130
|
+
(x) => AudioTranscriptionRequest$inboundSchema.parse(JSON.parse(x)),
|
|
131
|
+
`Failed to parse 'AudioTranscriptionRequest' from JSON`,
|
|
132
|
+
);
|
|
133
|
+
}
|