@azure-rest/ai-translation-document 1.0.0-alpha.20250609.1 → 1.0.0-alpha.20250610.1
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 +23 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ With the value of the `KeyCredential` you can create the `DocumentTranslationCli
|
|
|
75
75
|
```ts snippet:ReadmeSampleCreateClient
|
|
76
76
|
import DocumentTranslationClient from "@azure-rest/ai-translation-document";
|
|
77
77
|
|
|
78
|
-
const endpoint = "https://<translator-instance
|
|
78
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
79
79
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
80
80
|
const credential = {
|
|
81
81
|
key,
|
|
@@ -94,11 +94,11 @@ Used to synchronously translate a single document. The method doesn't require an
|
|
|
94
94
|
```ts snippet:ReadmeSampleSynchronousDocumentTranslation
|
|
95
95
|
import DocumentTranslationClient, {
|
|
96
96
|
DocumentTranslateParameters,
|
|
97
|
-
isUnexpected,
|
|
98
97
|
} from "@azure-rest/ai-translation-document";
|
|
99
|
-
import {
|
|
98
|
+
import { ErrorResponse } from "@azure-rest/core-client";
|
|
99
|
+
import { writeFile } from "node:fs/promises";
|
|
100
100
|
|
|
101
|
-
const endpoint = "https://<translator-instance
|
|
101
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
102
102
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
103
103
|
const credential = {
|
|
104
104
|
key,
|
|
@@ -120,13 +120,20 @@ const options: DocumentTranslateParameters = {
|
|
|
120
120
|
],
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
const response = await client.path("/document:translate").post(options);
|
|
124
|
-
if (
|
|
125
|
-
throw response
|
|
123
|
+
const response = await client.path("/document:translate").post(options).asNodeStream();
|
|
124
|
+
if (!response.body) {
|
|
125
|
+
throw new Error("No response body received");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (response.status !== "200") {
|
|
129
|
+
const errorResponse: ErrorResponse = JSON.parse(response.body.read().toString());
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Translation failed with status: ${response.status}, error: ${errorResponse.error.message}`,
|
|
132
|
+
);
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
// Write the
|
|
129
|
-
|
|
135
|
+
// Write the buffer to a file
|
|
136
|
+
await writeFile("test-output.txt", response.body);
|
|
130
137
|
```
|
|
131
138
|
|
|
132
139
|
### Batch Document Translation
|
|
@@ -137,7 +144,7 @@ Used to execute an asynchronous batch translation request. The method requires a
|
|
|
137
144
|
import DocumentTranslationClient from "@azure-rest/ai-translation-document";
|
|
138
145
|
import { BlobServiceClient, ContainerSASPermissions } from "@azure/storage-blob";
|
|
139
146
|
|
|
140
|
-
const endpoint = "https://<translator-instance
|
|
147
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
141
148
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
142
149
|
const credential = {
|
|
143
150
|
key,
|
|
@@ -196,7 +203,7 @@ This cancels a translation job that is currently processing or queued (pending)
|
|
|
196
203
|
```ts snippet:ReadmeSampleCancelDocumentTranslation
|
|
197
204
|
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
198
205
|
|
|
199
|
-
const endpoint = "https://<translator-instance
|
|
206
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
200
207
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
201
208
|
const credential = {
|
|
202
209
|
key,
|
|
@@ -223,7 +230,7 @@ import DocumentTranslationClient, {
|
|
|
223
230
|
paginate,
|
|
224
231
|
} from "@azure-rest/ai-translation-document";
|
|
225
232
|
|
|
226
|
-
const endpoint = "https://<translator-instance
|
|
233
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
227
234
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
228
235
|
const credential = {
|
|
229
236
|
key,
|
|
@@ -253,7 +260,7 @@ import DocumentTranslationClient, {
|
|
|
253
260
|
paginate,
|
|
254
261
|
} from "@azure-rest/ai-translation-document";
|
|
255
262
|
|
|
256
|
-
const endpoint = "https://<translator-instance
|
|
263
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
257
264
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
258
265
|
const credential = {
|
|
259
266
|
key,
|
|
@@ -298,7 +305,7 @@ import DocumentTranslationClient, {
|
|
|
298
305
|
paginate,
|
|
299
306
|
} from "@azure-rest/ai-translation-document";
|
|
300
307
|
|
|
301
|
-
const endpoint = "https://<translator-instance
|
|
308
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
302
309
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
303
310
|
const credential = {
|
|
304
311
|
key,
|
|
@@ -335,7 +342,7 @@ Used to request the status of a specific translation job. The response includes
|
|
|
335
342
|
```ts snippet:ReadmeSampleGetTranslationStatus
|
|
336
343
|
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
337
344
|
|
|
338
|
-
const endpoint = "https://<translator-instance
|
|
345
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
339
346
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
340
347
|
const credential = {
|
|
341
348
|
key,
|
|
@@ -365,7 +372,7 @@ This returns a list of document or glossary formats supported by the Document Tr
|
|
|
365
372
|
```ts snippet:ReadmeSampleGetSupportedFormats
|
|
366
373
|
import DocumentTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-document";
|
|
367
374
|
|
|
368
|
-
const endpoint = "https://<translator-instance
|
|
375
|
+
const endpoint = "https://<translator-instance>.cognitiveservices.azure.com";
|
|
369
376
|
const key = "YOUR_SUBSCRIPTION_KEY";
|
|
370
377
|
const credential = {
|
|
371
378
|
key,
|
package/package.json
CHANGED