diff --git a/sdk/translation/ai-translation-text-rest/CHANGELOG.md b/sdk/translation/ai-translation-text-rest/CHANGELOG.md deleted file mode 100644 index c9b5bd652fdc..000000000000 --- a/sdk/translation/ai-translation-text-rest/CHANGELOG.md +++ /dev/null @@ -1,27 +0,0 @@ -# Release History - -## 1.0.1 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -### Other Changes - -## 1.0.0 (2024-05-21) - -### Features Added -- Added support for AAD authentication. - -## 1.0.0-beta.1 (2023-04-18) -Initial release - -### Features Added -- Added support for Text Translation - [Translate API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-translate) -- Added support for Text Transliteration - [Transliterate API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-transliterate) -- Added support for Finding Sentence Boundaries - [FindSentenceBoundaries API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-break-sentence) -- Added support for Getting the Supported Languages - [GetLanguages API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-languages) -- Added support for Looking up the Dictionary Entries - [LookupDictionaryEntries API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-lookup) -- Added support for Looking up the Dictionary Examples - [LookupDictionaryExamples API](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-examples) diff --git a/sdk/translation/ai-translation-text-rest/README.md b/sdk/translation/ai-translation-text-rest/README.md deleted file mode 100644 index 335e193f1dbe..000000000000 --- a/sdk/translation/ai-translation-text-rest/README.md +++ /dev/null @@ -1,313 +0,0 @@ -# Azure TextTranslation REST client library for JavaScript - -Text translation is a cloud-based REST API feature of the Translator service that uses neural -machine translation technology to enable quick and accurate source-to-target text translation -in real time across all supported languages. - -The following methods are supported by the Text Translation feature: - -Languages. Returns a list of languages supported by Translate, Transliterate, and Dictionary Lookup operations. - -Translate. Renders single source-language text to multiple target-language texts with a single request. - -Transliterate. Converts characters or letters of a source language to the corresponding characters or letters of a target language. - -Detect. Returns the source code language code and a boolean variable denoting whether the detected language is supported for text translation and transliteration. - -Dictionary lookup. Returns equivalent words for the source term in the target language. - -Dictionary example Returns grammatical structure and context examples for the source term and target term pair. - -**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library** - -Key links: - -- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-translation-text) -- [API reference documentation](https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference) -- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/samples) - -## Getting started - -### Currently supported environments - -- LTS versions of Node.js -- Latest versions of Edge, Chrome, Safar and Firefox - -### Prerequisites - -- An existing Translator service or Cognitive Services resource. - -### Install the `@azure-rest/ai-translation-text` package - -Install the Azure Text Translation REST client library for JavaScript with `npm`: - -```bash -npm install @azure-rest/ai-translation-text -``` - -#### Create a Translator service resource - -You can create Translator resource following [Create a Translator resource][translator_resource_create]. - -### Browser support - -#### JavaScript Bundle - -To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling). - -### Authenticate the client - -Interaction with the service using the client library begins with creating an instance of the [TextTranslationClient][translator_client_class] class. You will need an **API key** or `TokenCredential` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Translator Service][translator_auth]. - -#### Get an API key - -You can get the `endpoint`, `API key` and `Region` from the Cognitive Services resource or Translator service resource information in the [Azure Portal][azure_portal]. - -Alternatively, use the [Azure CLI][azure_cli] snippet below to get the API key from the Translator service resource. - -```PowerShell -az cognitiveservices account keys list --resource-group --name -``` - -### Create a `TextTranslationClient` using an API key and Region credential - -Once you have the value for the API key and Region, create an `TranslatorCredential`. - -With the value of the `TranslatorCredential` you can create the [TextTranslationClient][translator_client_class]: - -```javascript -const translateCedential = new TranslatorCredential(apiKey, region); -const translationClient = TextTranslationClient(endpoint, translateCedential); -``` - -## Examples - -The following section provides several code snippets using the `client` [created above](#create-a-texttranslationclient-using-an-api-key-and-region-credential), and covers the main features present in this client library. - -### Get Supported Languages - -Gets the set of languages currently supported by other operations of the Translator. - -```javascript -const langResponse = await translationClient.path("/languages").get(); - -if (isUnexpected(langResponse)) { - throw langResponse.body; -} - -const languages = langResponse.body; - -if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log(`${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`); - } -} - -if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})` - ); - } -} - -if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}` - ); - } -} -``` - -Please refer to the service documentation for a conceptual discussion of [languages][languages_doc]. - -### Translate - -Renders single source-language text to multiple target-language texts with a single request. - -```javascript -const inputText = [{ text: "This is a test." }]; -const parameters = { - to: "cs", - from: "en", -}; -const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: parameters, -}); - -if (isUnexpected(translateResponse)) { - throw translateResponse.body; -} - -const translations = translateResponse.body; -for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.` - ); -} -``` - -Please refer to the service documentation for a conceptual discussion of [translate][translate_doc]. - -### Transliterate - -Converts characters or letters of a source language to the corresponding characters or letters of a target language. - -```javascript -const inputText = [{ text: "这是个测试。" }]; -const parameters = { - language: "zh-Hans", - fromScript: "Hans", - toScript: "Latn", -}; -const transliterateResponse = await translationClient.path("/transliterate").post({ - body: inputText, - queryParameters: parameters, -}); - -if (isUnexpected(transliterateResponse)) { - throw transliterateResponse.body; -} - -const translations = transliterateResponse.body; -for (const transliteration of translations) { - console.log( - `Input text was transliterated to '${transliteration?.script}' script. Transliterated text: '${transliteration?.text}'.` - ); -} -``` - -Please refer to the service documentation for a conceptual discussion of [transliterate][transliterate_doc]. - -### Break Sentence - -Identifies the positioning of sentence boundaries in a piece of text. - -```javascript -const inputText = [{ text: "zhè shì gè cè shì。" }]; -const parameters = { - language: "zh-Hans", - script: "Latn", -}; -const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - queryParameters: parameters, -}); - -if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body; -} - -const breakSentences = breakSentenceResponse.body; -for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); -} -``` - -Please refer to the service documentation for a conceptual discussion of [break sentence][breaksentence_doc]. - -### Dictionary Lookup - -Returns equivalent words for the source term in the target language. - -```javascript -const inputText = [{ text: "fly" }]; -const parameters = { - to: "es", - from: "en", -}; -const dictionaryResponse = await translationClient.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: parameters, -}); - -if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body; -} - -const dictionaryEntries = dictionaryResponse.body; -for (const dictionaryEntry of dictionaryEntries) { - console.log( - `For the given input ${dictionaryEntry?.translations?.length} entries were found in the dictionary.` - ); - console.log( - `First entry: '${dictionaryEntry?.translations[0]?.displayTarget}', confidence: ${dictionaryEntry?.translations[0]?.confidence}.` - ); -} -``` - -Please refer to the service documentation for a conceptual discussion of [dictionary lookup][dictionarylookup_doc]. - -### Dictionary Examples - -Returns grammatical structure and context examples for the source term and target term pair. - -```javascript -const inputText = [{ text: "fly", translation: "volar" }]; -const parameters = { - to: "es", - from: "en", -}; -const dictionaryResponse = await translationClient.path("/dictionary/examples").post({ - body: inputText, - queryParameters: parameters, -}); - -if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body; -} - -const dictionaryExamples = dictionaryResponse.body; -for (const dictionaryExample of dictionaryExamples) { - console.log( - `For the given input ${dictionaryExample?.examples?.length} examples were found in the dictionary.` - ); - const firstExample = dictionaryExample?.examples[0]; - console.log( - `Example: '${firstExample.targetPrefix + firstExample.targetTerm + firstExample.targetSuffix}'.` - ); -} -``` - -Please refer to the service documentation for a conceptual discussion of [dictionary examples][dictionaryexamples_doc]. - -## Troubleshooting - -When you interact with the Translator Service using the TextTranslator client library, errors returned by the Translator service correspond to the same HTTP status codes returned for REST API requests. - -For example, if you submit a translation request without a target translate language, a `400` error is returned, indicating "Bad Request". - -You can find the different error codes returned by the service in the [Service Documentation][service_errors]. - -### Logging - -Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: - -```javascript -const { setLogLevel } = require("@azure/logger"); - -setLogLevel("info"); -``` - -For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). - -[azure_cli]: https://docs.microsoft.com/cli/azure -[azure_portal]: https://portal.azure.com -[translator_resource_create]: https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource -[translator_auth]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#authentication -[service_errors]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#errors -[translator_client_class]: https://learn.microsoft.com/javascript/api/@azure-rest/ai-translation-text/texttranslationclient -[languages_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-languages -[translate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-translate -[transliterate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-transliterate -[breaksentence_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-break-sentence -[dictionarylookup_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-lookup -[dictionaryexamples_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-examples diff --git a/sdk/translation/ai-translation-text-rest/api-extractor.json b/sdk/translation/ai-translation-text-rest/api-extractor.json deleted file mode 100644 index ebfd2ff45058..000000000000 --- a/sdk/translation/ai-translation-text-rest/api-extractor.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "./types/src/index.d.ts", - "docModel": { - "enabled": true - }, - "apiReport": { - "enabled": true, - "reportFolder": "./review" - }, - "dtsRollup": { - "enabled": true, - "untrimmedFilePath": "", - "publicTrimmedFilePath": "./types/ai-translation-text.d.ts" - }, - "messages": { - "tsdocMessageReporting": { - "default": { - "logLevel": "none" - } - }, - "extractorMessageReporting": { - "ae-missing-release-tag": { - "logLevel": "none" - }, - "ae-unresolved-link": { - "logLevel": "none" - } - } - } -} diff --git a/sdk/translation/ai-translation-text-rest/assets.json b/sdk/translation/ai-translation-text-rest/assets.json deleted file mode 100644 index e71b87341665..000000000000 --- a/sdk/translation/ai-translation-text-rest/assets.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "js", - "TagPrefix": "js/translation/ai-translation-text-rest", - "Tag": "js/translation/ai-translation-text-rest_34ef4ea36f" -} diff --git a/sdk/translation/ai-translation-text-rest/eslint.config.mjs b/sdk/translation/ai-translation-text-rest/eslint.config.mjs deleted file mode 100644 index e559ed8cb5bd..000000000000 --- a/sdk/translation/ai-translation-text-rest/eslint.config.mjs +++ /dev/null @@ -1,14 +0,0 @@ -import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; - -export default [ - ...azsdkEslint.configs.recommended, - { - rules: { - "@azure/azure-sdk/ts-modules-only-named": "warn", - "@azure/azure-sdk/ts-apiextractor-json-types": "warn", - "@azure/azure-sdk/ts-package-json-types": "warn", - "@azure/azure-sdk/ts-package-json-engine-is-present": "warn", - "tsdoc/syntax": "warn", - }, - }, -]; diff --git a/sdk/translation/ai-translation-text-rest/karma.conf.js b/sdk/translation/ai-translation-text-rest/karma.conf.js deleted file mode 100644 index 5e421fa3be28..000000000000 --- a/sdk/translation/ai-translation-text-rest/karma.conf.js +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// https://github.com/karma-runner/karma-chrome-launcher -process.env.CHROME_BIN = require("puppeteer").executablePath(); -require("dotenv").config(); -const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); -process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); - -module.exports = function (config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: "./", - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ["source-map-support", "mocha"], - - plugins: [ - "karma-mocha", - "karma-mocha-reporter", - "karma-chrome-launcher", - "karma-firefox-launcher", - "karma-env-preprocessor", - "karma-coverage", - "karma-sourcemap-loader", - "karma-junit-reporter", - "karma-source-map-support", - ], - - // list of files / patterns to load in the browser - files: [ - "dist-test/index.browser.js", - { - pattern: "dist-test/index.browser.js.map", - type: "html", - included: false, - served: true, - }, - ], - - // list of files / patterns to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - "**/*.js": ["sourcemap", "env"], - // IMPORTANT: COMMENT following line if you want to debug in your browsers!! - // Preprocess source file to calculate code coverage, however this will make source file unreadable - // "dist-test/index.js": ["coverage"] - }, - - envPreprocessor: [ - "TEST_MODE", - "TEXT_TRANSLATION_TENANT_ID", - "TEXT_TRANSLATION_CLIENT_ID", - "TEXT_TRANSLATION_CLIENT_SECRET", - "TEXT_TRANSLATION_ENDPOINT", - "TEXT_TRANSLATION_CUSTOM_ENDPOINT", - "TEXT_TRANSLATION_API_KEY", - "TEXT_TRANSLATION_REGION", - "RECORDINGS_RELATIVE_PATH", - "TEXT_TRANSLATION_AAD_REGION", - "TEXT_TRANSLATION_RESOURCE_ID", - ], - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ["mocha", "coverage", "junit"], - - coverageReporter: { - // specify a common output directory - dir: "coverage-browser/", - reporters: [ - { type: "json", subdir: ".", file: "coverage.json" }, - { type: "lcovonly", subdir: ".", file: "lcov.info" }, - { type: "html", subdir: "html" }, - { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }, - ], - }, - - junitReporter: { - outputDir: "", // results will be saved as $outputDir/$browserName.xml - outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile - suite: "", // suite will become the package name attribute in xml testsuite element - useBrowserName: false, // add browser name to report and classes names - nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element - classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element - properties: {}, // key value pair of properties to add to the section of the report - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // --no-sandbox allows our tests to run in Linux without having to change the system. - // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex. - browsers: ["ChromeHeadlessNoSandbox"], - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: "ChromeHeadless", - flags: ["--no-sandbox", "--disable-web-security"], - }, - }, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: 1, - - browserNoActivityTimeout: 60000000, - browserDisconnectTimeout: 10000, - browserDisconnectTolerance: 3, - - client: { - mocha: { - // change Karma's debug.html to the mocha web reporter - reporter: "html", - timeout: "600000", - }, - }, - }); -}; diff --git a/sdk/translation/ai-translation-text-rest/package.json b/sdk/translation/ai-translation-text-rest/package.json deleted file mode 100644 index bf324250f202..000000000000 --- a/sdk/translation/ai-translation-text-rest/package.json +++ /dev/null @@ -1,126 +0,0 @@ -{ - "name": "@azure-rest/ai-translation-text", - "sdk-type": "client", - "author": "Microsoft Corporation", - "version": "1.0.1", - "description": "An isomorphic client library for the Azure Cognitive Translator Service", - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/README.md", - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic", - "translate", - "translation" - ], - "license": "MIT", - "main": "dist/index.js", - "module": "./dist-esm/src/index.js", - "types": "./types/ai-translation-text.d.ts", - "repository": "github:Azure/azure-sdk-for-js", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "files": [ - "dist/", - "dist-esm/src/", - "types/ai-translation-text.d.ts", - "README.md", - "CHANGELOG.md", - "LICENSE" - ], - "engines": { - "node": ">=18.0.0" - }, - "//sampleConfiguration": { - "productName": "Azure Text Translation Service", - "productSlugs": [ - "azure", - "azure-cognitive-services", - "azure-translator" - ], - "requiredResources": { - "Translator resource instance": "https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource" - } - }, - "scripts": { - "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", - "build": "npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && dev-tool run extract-api", - "build:browser": "tsc -p . && dev-tool run bundle", - "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api", - "build:node": "tsc -p . && dev-tool run bundle --browser-test false", - "build:samples": "echo Obsolete.", - "build:test": "tsc -p . && dev-tool run bundle", - "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", - "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", - "execute:samples": "dev-tool samples run samples-dev", - "extract-api": "rimraf review && mkdirp ./review && dev-tool run extract-api", - "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", - "generate:client": "echo skipped", - "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:browser": "dev-tool run test:browser", - "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'", - "lint": "eslint package.json api-extractor.json src test", - "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", - "pack": "npm pack 2>&1", - "test": "npm run clean && npm run build:test && npm run unit-test", - "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", - "test:node": "npm run clean && npm run build:test && npm run unit-test:node", - "unit-test": "npm run unit-test:node && npm run unit-test:browser", - "unit-test:browser": "dev-tool run test:browser", - "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", - "update-snippets": "echo skipped" - }, - "sideEffects": false, - "autoPublish": false, - "dependencies": { - "@azure-rest/core-client": "^1.1.0", - "@azure/core-auth": "^1.3.0", - "@azure/core-rest-pipeline": "^1.8.0", - "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" - }, - "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.0.0", - "@azure/dev-tool": "^1.0.0", - "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@azure/identity": "^4.0.1", - "@microsoft/api-extractor": "^7.31.1", - "@types/chai": "^4.2.8", - "@types/mocha": "^10.0.0", - "@types/node": "^18.0.0", - "autorest": "latest", - "chai": "^4.2.0", - "cross-env": "^7.0.2", - "dotenv": "^16.0.0", - "eslint": "^9.9.0", - "karma": "^6.2.0", - "karma-chrome-launcher": "^3.0.0", - "karma-coverage": "^2.0.0", - "karma-env-preprocessor": "^0.1.1", - "karma-firefox-launcher": "^1.1.0", - "karma-junit-reporter": "^2.0.1", - "karma-mocha": "^2.0.1", - "karma-mocha-reporter": "^2.2.5", - "karma-source-map-support": "~1.4.0", - "karma-sourcemap-loader": "^0.3.8", - "mkdirp": "^3.0.1", - "mocha": "^10.0.0", - "nyc": "^17.0.0", - "rimraf": "^5.0.5", - "source-map-support": "^0.5.9", - "ts-node": "^10.0.0", - "typescript": "~5.6.2" - }, - "//metadata": { - "constantPaths": [ - { - "path": "src/customClient.ts", - "prefix": "userAgentInfo" - } - ] - } -} diff --git a/sdk/translation/ai-translation-text-rest/review/ai-translation-text.api.md b/sdk/translation/ai-translation-text-rest/review/ai-translation-text.api.md deleted file mode 100644 index 2d84f2e689fd..000000000000 --- a/sdk/translation/ai-translation-text-rest/review/ai-translation-text.api.md +++ /dev/null @@ -1,664 +0,0 @@ -## API Report File for "@azure-rest/ai-translation-text" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import { Client } from '@azure-rest/core-client'; -import { ClientOptions } from '@azure-rest/core-client'; -import { HttpResponse } from '@azure-rest/core-client'; -import { KeyCredential } from '@azure/core-auth'; -import { RawHttpHeaders } from '@azure/core-rest-pipeline'; -import { RawHttpHeadersInput } from '@azure/core-rest-pipeline'; -import { RequestParameters } from '@azure-rest/core-client'; -import { StreamableMethod } from '@azure-rest/core-client'; -import { TokenCredential } from '@azure/core-auth'; - -// @public -export interface BackTranslationOutput { - displayText: string; - frequencyCount: number; - normalizedText: string; - numExamples: number; -} - -// @public -export interface BreakSentenceItemOutput { - detectedLanguage?: DetectedLanguageOutput; - sentLen: number[]; -} - -// @public (undocumented) -export function buildMultiCollection(items: string[], parameterName: string): string; - -// @public -function createClient(credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient; - -// @public -function createClient(endpoint: string, options?: ClientOptions): TextTranslationClient; - -// @public -function createClient(endpoint: string, credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient; -export default createClient; - -// @public -export interface DetectedLanguageOutput { - language: string; - score: number; -} - -// @public -export interface DictionaryExampleItemOutput { - examples: Array; - normalizedSource: string; - normalizedTarget: string; -} - -// @public -export interface DictionaryExampleOutput { - sourcePrefix: string; - sourceSuffix: string; - sourceTerm: string; - targetPrefix: string; - targetSuffix: string; - targetTerm: string; -} - -// @public -export interface DictionaryExampleTextItem extends InputTextItem { - translation: string; -} - -// @public -export interface DictionaryLookupItemOutput { - displaySource: string; - normalizedSource: string; - translations: Array; -} - -// @public -export interface DictionaryTranslationOutput { - backTranslations: Array; - confidence: number; - displayTarget: string; - normalizedTarget: string; - posTag: string; - prefixWord: string; -} - -// @public -export interface ErrorDetailsOutput { - code: number; - message: string; -} - -// @public -export interface ErrorResponseOutput { - error: ErrorDetailsOutput; -} - -// @public (undocumented) -export interface FindSentenceBoundaries { - post(options: FindSentenceBoundariesParameters): StreamableMethod; -} - -// @public (undocumented) -export interface FindSentenceBoundaries200Headers { - "x-requestid": string; -} - -// @public -export interface FindSentenceBoundaries200Response extends HttpResponse { - // (undocumented) - body: Array; - // (undocumented) - headers: RawHttpHeaders & FindSentenceBoundaries200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface FindSentenceBoundariesBodyParam { - body: Array; -} - -// @public (undocumented) -export interface FindSentenceBoundariesDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface FindSentenceBoundariesDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & FindSentenceBoundariesDefaultHeaders; - // (undocumented) - status: string; -} - -// @public (undocumented) -export interface FindSentenceBoundariesHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & FindSentenceBoundariesHeaders; -} - -// @public (undocumented) -export interface FindSentenceBoundariesHeaders { - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type FindSentenceBoundariesParameters = FindSentenceBoundariesQueryParam & FindSentenceBoundariesHeaderParam & FindSentenceBoundariesBodyParam & RequestParameters; - -// @public (undocumented) -export interface FindSentenceBoundariesQueryParam { - // (undocumented) - queryParameters?: FindSentenceBoundariesQueryParamProperties; -} - -// @public (undocumented) -export interface FindSentenceBoundariesQueryParamProperties { - language?: string; - script?: string; -} - -// @public (undocumented) -export interface GetSupportedLanguages { - get(options?: GetSupportedLanguagesParameters): StreamableMethod; -} - -// @public (undocumented) -export interface GetSupportedLanguages200Headers { - "x-requestid": string; - etag: string; -} - -// @public -export interface GetSupportedLanguages200Response extends HttpResponse { - // (undocumented) - body: GetSupportedLanguagesResultOutput; - // (undocumented) - headers: RawHttpHeaders & GetSupportedLanguages200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface GetSupportedLanguagesDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface GetSupportedLanguagesDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & GetSupportedLanguagesDefaultHeaders; - // (undocumented) - status: string; -} - -// @public (undocumented) -export interface GetSupportedLanguagesHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & GetSupportedLanguagesHeaders; -} - -// @public (undocumented) -export interface GetSupportedLanguagesHeaders { - "Accept-Language"?: string; - "If-None-Match"?: string; - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type GetSupportedLanguagesParameters = GetSupportedLanguagesQueryParam & GetSupportedLanguagesHeaderParam & RequestParameters; - -// @public (undocumented) -export interface GetSupportedLanguagesQueryParam { - // (undocumented) - queryParameters?: GetSupportedLanguagesQueryParamProperties; -} - -// @public (undocumented) -export interface GetSupportedLanguagesQueryParamProperties { - scope?: string; -} - -// @public -export interface GetSupportedLanguagesResultOutput { - dictionary?: Record; - translation?: Record; - transliteration?: Record; -} - -// @public -export interface InputTextItem { - text: string; -} - -// @public (undocumented) -export function isUnexpected(response: GetSupportedLanguages200Response | GetSupportedLanguagesDefaultResponse): response is GetSupportedLanguagesDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: Translate200Response | TranslateDefaultResponse): response is TranslateDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: Transliterate200Response | TransliterateDefaultResponse): response is TransliterateDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: FindSentenceBoundaries200Response | FindSentenceBoundariesDefaultResponse): response is FindSentenceBoundariesDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: LookupDictionaryEntries200Response | LookupDictionaryEntriesDefaultResponse): response is LookupDictionaryEntriesDefaultResponse; - -// @public (undocumented) -export function isUnexpected(response: LookupDictionaryExamples200Response | LookupDictionaryExamplesDefaultResponse): response is LookupDictionaryExamplesDefaultResponse; - -// @public -export type LanguageDirectionalityOutput = "ltr" | "rtl"; - -// @public -export interface LanguageScriptOutput { - code: string; - dir: LanguageDirectionalityOutput; - name: string; - nativeName: string; -} - -// @public (undocumented) -export interface LookupDictionaryEntries { - post(options: LookupDictionaryEntriesParameters): StreamableMethod; -} - -// @public (undocumented) -export interface LookupDictionaryEntries200Headers { - "x-requestid": string; -} - -// @public -export interface LookupDictionaryEntries200Response extends HttpResponse { - // (undocumented) - body: Array; - // (undocumented) - headers: RawHttpHeaders & LookupDictionaryEntries200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesBodyParam { - body: Array; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & LookupDictionaryEntriesDefaultHeaders; - // (undocumented) - status: string; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & LookupDictionaryEntriesHeaders; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesHeaders { - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type LookupDictionaryEntriesParameters = LookupDictionaryEntriesQueryParam & LookupDictionaryEntriesHeaderParam & LookupDictionaryEntriesBodyParam & RequestParameters; - -// @public (undocumented) -export interface LookupDictionaryEntriesQueryParam { - // (undocumented) - queryParameters: LookupDictionaryEntriesQueryParamProperties; -} - -// @public (undocumented) -export interface LookupDictionaryEntriesQueryParamProperties { - from: string; - to: string; -} - -// @public (undocumented) -export interface LookupDictionaryExamples { - post(options: LookupDictionaryExamplesParameters): StreamableMethod; -} - -// @public (undocumented) -export interface LookupDictionaryExamples200Headers { - "x-requestid": string; -} - -// @public -export interface LookupDictionaryExamples200Response extends HttpResponse { - // (undocumented) - body: Array; - // (undocumented) - headers: RawHttpHeaders & LookupDictionaryExamples200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesBodyParam { - body: Array; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & LookupDictionaryExamplesDefaultHeaders; - // (undocumented) - status: string; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & LookupDictionaryExamplesHeaders; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesHeaders { - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type LookupDictionaryExamplesParameters = LookupDictionaryExamplesQueryParam & LookupDictionaryExamplesHeaderParam & LookupDictionaryExamplesBodyParam & RequestParameters; - -// @public (undocumented) -export interface LookupDictionaryExamplesQueryParam { - // (undocumented) - queryParameters: LookupDictionaryExamplesQueryParamProperties; -} - -// @public (undocumented) -export interface LookupDictionaryExamplesQueryParamProperties { - from: string; - to: string; -} - -// @public -export type ProfanityAction = "NoAction" | "Marked" | "Deleted"; - -// @public -export type ProfanityMarker = "Asterisk" | "Tag"; - -// @public (undocumented) -export interface Routes { - (path: "/languages"): GetSupportedLanguages; - (path: "/translate"): Translate; - (path: "/transliterate"): Transliterate; - (path: "/breaksentence"): FindSentenceBoundaries; - (path: "/dictionary/lookup"): LookupDictionaryEntries; - (path: "/dictionary/examples"): LookupDictionaryExamples; -} - -// @public -export interface SentenceBoundariesOutput { - srcSentLen: number[]; - transSentLen: number[]; -} - -// @public -export interface SourceDictionaryLanguageOutput { - dir: LanguageDirectionalityOutput; - name: string; - nativeName: string; - translations: Array; -} - -// @public -export interface SourceTextOutput { - text: string; -} - -// @public -export interface TargetDictionaryLanguageOutput { - code: string; - dir: LanguageDirectionalityOutput; - name: string; - nativeName: string; -} - -// @public (undocumented) -export type TextTranslationClient = Client & { - path: Routes; -}; - -// @public -export type TextType = string | "Plain" | "Html"; - -// @public (undocumented) -export interface Translate { - post(options: TranslateParameters): StreamableMethod; -} - -// @public (undocumented) -export interface Translate200Headers { - "x-metered-usage": number; - "x-mt-system": string; - "x-requestid": string; -} - -// @public -export interface Translate200Response extends HttpResponse { - // (undocumented) - body: Array; - // (undocumented) - headers: RawHttpHeaders & Translate200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface TranslateBodyParam { - body: Array; -} - -// @public (undocumented) -export interface TranslateDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface TranslateDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & TranslateDefaultHeaders; - // (undocumented) - status: string; -} - -// @public -export interface TranslatedTextAlignmentOutput { - proj: string; -} - -// @public -export interface TranslatedTextItemOutput { - detectedLanguage?: DetectedLanguageOutput; - sourceText?: SourceTextOutput; - translations: Array; -} - -// @public (undocumented) -export interface TranslateHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & TranslateHeaders; -} - -// @public (undocumented) -export interface TranslateHeaders { - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type TranslateParameters = TranslateQueryParam & TranslateHeaderParam & TranslateBodyParam & RequestParameters; - -// @public (undocumented) -export interface TranslateQueryParam { - // (undocumented) - queryParameters: TranslateQueryParamProperties; -} - -// @public (undocumented) -export interface TranslateQueryParamProperties { - allowFallback?: boolean; - category?: string; - from?: string; - fromScript?: string; - includeAlignment?: boolean; - includeSentenceLength?: boolean; - profanityAction?: ProfanityAction; - profanityMarker?: ProfanityMarker; - suggestedFrom?: string; - textType?: TextType; - to: string; - toScript?: string; -} - -// @public -export interface TranslationLanguageOutput { - dir: LanguageDirectionalityOutput; - name: string; - nativeName: string; -} - -// @public -export interface TranslationTextOutput { - alignment?: TranslatedTextAlignmentOutput; - sentLen?: SentenceBoundariesOutput; - text: string; - to: string; - transliteration?: TransliteratedTextOutput; -} - -// @public (undocumented) -export interface TranslatorCredential { - // (undocumented) - key: string; - // (undocumented) - region: string; -} - -// @public (undocumented) -export interface TranslatorTokenCredential { - // (undocumented) - azureResourceId: string; - // (undocumented) - region: string; - // (undocumented) - tokenCredential: TokenCredential; -} - -// @public -export interface TransliterableScriptOutput extends LanguageScriptOutput { - toScripts: Array; -} - -// @public (undocumented) -export interface Transliterate { - post(options: TransliterateParameters): StreamableMethod; -} - -// @public (undocumented) -export interface Transliterate200Headers { - "x-requestid": string; -} - -// @public -export interface Transliterate200Response extends HttpResponse { - // (undocumented) - body: Array; - // (undocumented) - headers: RawHttpHeaders & Transliterate200Headers; - // (undocumented) - status: "200"; -} - -// @public (undocumented) -export interface TransliterateBodyParam { - body: Array; -} - -// @public (undocumented) -export interface TransliterateDefaultHeaders { - "x-requestid": string; -} - -// @public (undocumented) -export interface TransliterateDefaultResponse extends HttpResponse { - // (undocumented) - body: ErrorResponseOutput; - // (undocumented) - headers: RawHttpHeaders & TransliterateDefaultHeaders; - // (undocumented) - status: string; -} - -// @public -export interface TransliteratedTextOutput { - script: string; - text: string; -} - -// @public (undocumented) -export interface TransliterateHeaderParam { - // (undocumented) - headers?: RawHttpHeadersInput & TransliterateHeaders; -} - -// @public (undocumented) -export interface TransliterateHeaders { - "X-ClientTraceId"?: string; -} - -// @public (undocumented) -export type TransliterateParameters = TransliterateQueryParam & TransliterateHeaderParam & TransliterateBodyParam & RequestParameters; - -// @public (undocumented) -export interface TransliterateQueryParam { - // (undocumented) - queryParameters: TransliterateQueryParamProperties; -} - -// @public (undocumented) -export interface TransliterateQueryParamProperties { - fromScript: string; - language: string; - toScript: string; -} - -// @public -export interface TransliterationLanguageOutput { - name: string; - nativeName: string; - scripts: Array; -} - -// (No @packageDocumentation comment for this package) - -``` diff --git a/sdk/translation/ai-translation-text-rest/sample.env b/sdk/translation/ai-translation-text-rest/sample.env deleted file mode 100644 index bbdd64c0b36b..000000000000 --- a/sdk/translation/ai-translation-text-rest/sample.env +++ /dev/null @@ -1,6 +0,0 @@ -# Used in most samples. -# Get the key and region - https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource - -ENDPOINT="https://api.cognitive.microsofttranslator.com" -TEXT_TRANSLATOR_API_KEY="" -TEXT_TRANSLATOR_REGION="" diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts deleted file mode 100644 index 25bf03b92b0e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Get Sentence Boundaries sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "zhè shì gè cè shì。" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - script: "Latn", - }, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts deleted file mode 100644 index 9489d2b0cca9..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Sentence Boundaries with auto-detection sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "How are you? I am fine. What did you do today?" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - console.log( - `Detected languages of the input text: ${breakSentence?.detectedLanguage?.language} with score: ${breakSentence?.detectedLanguage?.score}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts deleted file mode 100644 index 6915fa3eadf6..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. - */ -import TextTranslationClient, { - TranslatorCredential, - DictionaryExampleTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Dictionary Examples sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: DictionaryExampleTextItem[] = [{ text: "fly", translation: "volar" }]; - const dictionaryResponse = await translationClient.path("/dictionary/examples").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryExamples = dictionaryResponse.body; - for (const dictionaryExample of dictionaryExamples) { - console.log( - `For the given input ${dictionaryExample?.examples?.length} examples were found in the dictionary.`, - ); - const firstExample = dictionaryExample?.examples[0]; - console.log( - `Example: '${ - firstExample.targetPrefix + firstExample.targetTerm + firstExample.targetSuffix - }'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts deleted file mode 100644 index 744810e487fb..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Dictionary Lookup sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "fly" }]; - const dictionaryResponse = await translationClient.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryEntries = dictionaryResponse.body; - for (const dictionaryEntry of dictionaryEntries) { - console.log( - `For the given input ${dictionaryEntry?.translations?.length} entries were found in the dictionary.`, - ); - console.log( - `First entry: '${dictionaryEntry?.translations[0]?.displayTarget}', confidence: ${dictionaryEntry?.translations[0]?.confidence}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts deleted file mode 100644 index 78f67211e3c3..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages - */ -import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== List supported languages sample =="); - - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts deleted file mode 100644 index 0b2ce50e715b..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select the language to use for user interface strings. - * Some of the fields in the response are names of languages or names of regions. - * Use this parameter to define the language in which these names are returned. - * The language is specified by providing a well-formed BCP 47 language tag. - * For instance, use the value `fr` to request names in French or use the value `zh-Hant` - * to request names in Chinese Traditional. - * - * Names are provided in the English language when a target language is not specified - * or when localization is not available. - */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== List supported localized languages sample =="); - - const parameters: GetSupportedLanguagesParameters = { - headers: { - "Accept-Language": "cs", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts deleted file mode 100644 index adedf0e2895d..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get a list of supported languages for a selected scope - */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== Scoped list supported languages sample =="); - - const parameters: GetSupportedLanguagesParameters = { - queryParameters: { - scope: "translation", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts deleted file mode 100644 index 2435f494285e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a text which language is know to a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Simple translate sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts deleted file mode 100644 index 9baf6597850e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can ask translation service to include alignment - * projection from source text to translated text. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with alignments sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "The answer lies in machine translation." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeAlignment: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log(`Alignments: ${translation?.translations[0]?.alignment?.proj}`); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts deleted file mode 100644 index 83159f47a366..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how You can get translations from a customized system built with - * Custom Translator (https://learn.microsoft.com/azure/cognitive-services/translator/customization). Add the Category ID from your Custom Translator [project details](https://learn.microsoft.com/azure/cognitive-services/translator/custom-translator/how-to-create-project#view-project-details) - * to this parameter to use your deployed customized system. - * - * It is possible to set `allowFalback` paramter. It specifies that the service is allowed to - * fall back to a general system when a custom system doesn't exist. Possible values are: - * `true` (default) or `false`. - * - * `allowFallback=false` specifies that the translation should only use systems trained for - * the category specified by the request. If a translation for language X to language Y requires - * chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) - * will need to be custom and have the same category. If no system is found with the specific - * category, the request will return a 400 status code. `allowFallback=true` specifies that - * the service is allowed to fall back to a general system when a custom system doesn't exist. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Custom translator sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - category: "<>", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts deleted file mode 100644 index cf5c1a188366..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation without specifying the source language to a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translate sample with auto-detection =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts deleted file mode 100644 index 23eb715449dc..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to keep words if you already know the translation you want - * to apply to a word or a phrase, you can supply it as markup within the request. - * The dynamic dictionary is safe only for compound nouns like proper names and product names. - * - * Note You must include the From parameter in your API translation request instead of using the autodetect feature. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - TranslatedTextItemOutput, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with Dictionary sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { - text: 'The word wordomatic is a dictionary entry.', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body as TranslatedTextItemOutput[]; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts deleted file mode 100644 index ffb5a49f6f7e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a multiple text fields and each input text - * is in different language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Multiple input texts =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { text: "This is a test." }, - { text: "Esto es una prueba." }, - { text: "Dies ist ein Test." }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts deleted file mode 100644 index 20c00ed4e0ee..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can provide multiple target languages which results - * to each input element be translated to all target languages. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Multiple target languages translation =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs,es,de", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - for (const textKey in translation.translations) { - console.log( - `Text was translated to: '${translation?.translations[textKey]?.to}' and the result is: '${translation?.translations[textKey]?.text}'.`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts deleted file mode 100644 index d505a78ba34d..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how it's sometimes useful to exclude specific content from translation. - * You can use the attribute class=notranslate to specify content that should remain - * in its original language. In the following example, the content inside the first div - * element won't be translated, while the content in the second div element will be translated. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Marking text input with notranslate div sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { - text: '
This will not be translated.
This will be translated.
', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts deleted file mode 100644 index aa126e6baf74..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to change the profanity handling during translate call. - * Normally the Translator service will retain profanity that is present in the source - * in the translation. The degree of profanity and the context that makes words profane - * differ between cultures, and as a result the degree of profanity in the target language - * may be amplified or reduced. - * - * If you want to avoid getting profanity in the translation, regardless of the presence - * of profanity in the source text, you can use the profanity filtering option. The option - * allows you to choose whether you want to see profanity deleted, whether you want to mark - * profanities with appropriate tags (giving you the option to add your own post-processing), - * or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` - * and `NoAction` (default). - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Profanity handling sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is ***." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - profanityAction: "Marked", - profanityMarker: "Asterisk", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts deleted file mode 100644 index 972f4358725a..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to you can ask translator service to include sentence boundaries - * for the input text and the translated text. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with sentence boundaries sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { text: "The answer lies in machine translation. This is a test." }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeSentenceLength: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Source Sentece length: ${translation?.translations[0]?.sentLen?.srcSentLen.join(", ")}`, - ); - console.log( - `Translated Sentece length: ${translation?.translations[0]?.sentLen?.transSentLen.join( - ", ", - )}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts deleted file mode 100644 index 51609a958959..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select whether the translated text is plain text or HTML text. - * Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== HTML translation sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts deleted file mode 100644 index c3f0471edec4..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary You can combine both Translation and Transliteration in one Translate call. - * Your source Text can be in non-standard Script of a language as well as you - * can ask for non-standard Script of a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translate with transliteration sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "hudha akhtabar." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "zh-Hans", - toScript: "Latn", - from: "ar", - fromScript: "Latn", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log(`Source Text: ${translation.sourceText?.text}`); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Transliterated text (${translation?.translations[0]?.transliteration?.script}): ${translation?.translations[0]?.transliteration?.text}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts deleted file mode 100644 index 555211ce1ed0..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to convert characters or letters of a source language to the corresponding - * characters or letters of a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Simple transliterate sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "这是个测试。" }]; - const transliterateResponse = await translationClient.path("/transliterate").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - fromScript: "Hans", - toScript: "Latn", - }, - }); - - if (isUnexpected(transliterateResponse)) { - throw transliterateResponse.body.error; - } - - const translations = transliterateResponse.body; - for (const transliteration of translations) { - console.log( - `Input text was transliterated to '${transliteration?.script}' script. Transliterated text: '${transliteration?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/README.md b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/README.md deleted file mode 100644 index 6985545c46a5..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/README.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -page_type: sample -languages: - - javascript -products: - - azure - - azure-cognitive-services - - azure-translator -urlFragment: ai-translation-text-javascript-beta ---- - -# Azure Text Translation Service client library samples for JavaScript (Beta) - -These sample programs show how to use the JavaScript client libraries for Azure Text Translation Service in some common scenarios. - -| **File Name** | **Description** | -| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [breakSentence.js][breaksentence] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. | -| [breakSentenceWithAutoDetection.js][breaksentencewithautodetection] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. | -| [dictionaryExamples.js][dictionaryexamples] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. | -| [dictionaryLookup.js][dictionarylookup] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. | -| [getLanguages.js][getlanguages] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages | -| [getLanguagesAcceptLanguage.js][getlanguagesacceptlanguage] | This sample demonstrates how you can select the language to use for user interface strings. Some of the fields in the response are names of languages or names of regions. Use this parameter to define the language in which these names are returned. The language is specified by providing a well-formed BCP 47 language tag. For instance, use the value `fr` to request names in French or use the value `zh-Hant` to request names in Chinese Traditional. Names are provided in the English language when a target language is not specified or when localization is not available. | -| [getLanguagesScope.js][getlanguagesscope] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages for a selected scope | -| [translate.js][translate] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation for a text which language is know to a target language. | -| [translateAlignments.js][translatealignments] | This sample demonstrates how you can ask translation service to include alignment projection from source text to translated text. | -| [translateCustom.js][translatecustom] | This sample demonstrates how You can get translations from a customized system built with Custom Translator (https://learn.microsoft.com/azure/cognitive-services/translator/customization). Add the Category ID from your Custom Translator [project details](https://learn.microsoft.com/azure/cognitive-services/translator/custom-translator/how-to-create-project#view-project-details) to this parameter to use your deployed customized system. It is possible to set `allowFalback` paramter. It specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. Possible values are: `true` (default) or `false`. `allowFallback=false` specifies that the translation should only use systems trained for the category specified by the request. If a translation for language X to language Y requires chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. If no system is found with the specific category, the request will return a 400 status code. `allowFallback=true` specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. | -| [translateDetection.js][translatedetection] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation without specifying the source language to a target language. | -| [translateDictionary.js][translatedictionary] | This sample demonstrates how to keep words if you already know the translation you want to apply to a word or a phrase, you can supply it as markup within the request. The dynamic dictionary is safe only for compound nouns like proper names and product names. Note You must include the From parameter in your API translation request instead of using the autodetect feature. | -| [translateMultipleSources.js][translatemultiplesources] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation for a multiple text fields and each input text is in different language. | -| [translateMultipleTargets.js][translatemultipletargets] | This sample demonstrates how you can provide multiple target languages which results to each input element be translated to all target languages. | -| [translateNoTranslate.js][translatenotranslate] | This sample demonstrates how it's sometimes useful to exclude specific content from translation. You can use the attribute class=notranslate to specify content that should remain in its original language. In the following example, the content inside the first div element won't be translated, while the content in the second div element will be translated. | -| [translateProfanity.js][translateprofanity] | This sample demonstrates how to change the profanity handling during translate call. Normally the Translator service will retain profanity that is present in the source in the translation. The degree of profanity and the context that makes words profane differ between cultures, and as a result the degree of profanity in the target language may be amplified or reduced. If you want to avoid getting profanity in the translation, regardless of the presence of profanity in the source text, you can use the profanity filtering option. The option allows you to choose whether you want to see profanity deleted, whether you want to mark profanities with appropriate tags (giving you the option to add your own post-processing), or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` and `NoAction` (default). | -| [translateSenteceLength.js][translatesentecelength] | This sample demonstrates how to you can ask translator service to include sentence boundaries for the input text and the translated text. | -| [translateTextType.js][translatetexttype] | This sample demonstrates how you can select whether the translated text is plain text or HTML text. Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. | -| [translateWithTransliteration.js][translatewithtransliteration] | You can combine both Translation and Transliteration in one Translate call. Your source Text can be in non-standard Script of a language as well as you can ask for non-standard Script of a target language. | -| [transliterate.js][transliterate] | This sample demonstrates how to make a simple call to the Azure Text Translator service to convert characters or letters of a source language to the corresponding characters or letters of a target language. | - -## Prerequisites - -The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). - -You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: - -- [Translator resource instance][createinstance_translatorresourceinstance] - -Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. - -Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. - -## Setup - -To run the samples using the published version of the package: - -1. Install the dependencies using `npm`: - -```bash -npm install -``` - -2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. - -3. Run whichever samples you like (note that some samples may require additional setup, see the table above): - -```bash -node breakSentence.js -``` - -Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): - -```bash -npx cross-env ENDPOINT="" TEXT_TRANSLATOR_API_KEY="" TEXT_TRANSLATOR_REGION="" node breakSentence.js -``` - -## Next Steps - -Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. - -[breaksentence]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentence.js -[breaksentencewithautodetection]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentenceWithAutoDetection.js -[dictionaryexamples]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryExamples.js -[dictionarylookup]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryLookup.js -[getlanguages]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguages.js -[getlanguagesacceptlanguage]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesAcceptLanguage.js -[getlanguagesscope]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesScope.js -[translate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translate.js -[translatealignments]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateAlignments.js -[translatecustom]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateCustom.js -[translatedetection]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDetection.js -[translatedictionary]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDictionary.js -[translatemultiplesources]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleSources.js -[translatemultipletargets]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleTargets.js -[translatenotranslate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateNoTranslate.js -[translateprofanity]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateProfanity.js -[translatesentecelength]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateSenteceLength.js -[translatetexttype]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateTextType.js -[translatewithtransliteration]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateWithTransliteration.js -[transliterate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/transliterate.js -[apiref]: https://learn.microsoft.com/azure/ai-services/translator/reference/v3-0-reference -[freesub]: https://azure.microsoft.com/free/ -[createinstance_translatorresourceinstance]: https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource -[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/README.md diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentence.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentence.js deleted file mode 100644 index 0fdf418a4e09..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentence.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Get Sentence Boundaries sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "zhè shì gè cè shì。" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - script: "Latn", - }, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentenceWithAutoDetection.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentenceWithAutoDetection.js deleted file mode 100644 index b06897d7da54..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/breakSentenceWithAutoDetection.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Sentence Boundaries with auto-detection sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "How are you? I am fine. What did you do today?" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - console.log( - `Detected languages of the input text: ${breakSentence?.detectedLanguage?.language} with score: ${breakSentence?.detectedLanguage?.score}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryExamples.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryExamples.js deleted file mode 100644 index 5cd57af7c965..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryExamples.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Dictionary Examples sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "fly", translation: "volar" }]; - const dictionaryResponse = await translationClient.path("/dictionary/examples").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryExamples = dictionaryResponse.body; - for (const dictionaryExample of dictionaryExamples) { - console.log( - `For the given input ${dictionaryExample?.examples?.length} examples were found in the dictionary.`, - ); - const firstExample = dictionaryExample?.examples[0]; - console.log( - `Example: '${firstExample.targetPrefix + firstExample.targetTerm + firstExample.targetSuffix}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryLookup.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryLookup.js deleted file mode 100644 index 40811b622510..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/dictionaryLookup.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Dictionary Lookup sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "fly" }]; - const dictionaryResponse = await translationClient.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryEntries = dictionaryResponse.body; - for (const dictionaryEntry of dictionaryEntries) { - console.log( - `For the given input ${dictionaryEntry?.translations?.length} entries were found in the dictionary.`, - ); - console.log( - `First entry: '${dictionaryEntry?.translations[0]?.displayTarget}', confidence: ${dictionaryEntry?.translations[0]?.confidence}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguages.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguages.js deleted file mode 100644 index 20f9c3984767..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguages.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -async function main() { - console.log("== List supported languages sample =="); - - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesAcceptLanguage.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesAcceptLanguage.js deleted file mode 100644 index 39d79c51efc6..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesAcceptLanguage.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select the language to use for user interface strings. - * Some of the fields in the response are names of languages or names of regions. - * Use this parameter to define the language in which these names are returned. - * The language is specified by providing a well-formed BCP 47 language tag. - * For instance, use the value `fr` to request names in French or use the value `zh-Hant` - * to request names in Chinese Traditional. - * - * Names are provided in the English language when a target language is not specified - * or when localization is not available. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -async function main() { - console.log("== List supported localized languages sample =="); - - const parameters = { - headers: { - "Accept-Language": "cs", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesScope.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesScope.js deleted file mode 100644 index 678dc6967543..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/getLanguagesScope.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get a list of supported languages for a selected scope - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -async function main() { - console.log("== Scoped list supported languages sample =="); - - const parameters = { - queryParameters: { - scope: "translation", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/package.json b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/package.json deleted file mode 100644 index 098fe4457ed4..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "@azure-samples/ai-translation-text-js-beta", - "private": true, - "version": "1.0.0", - "description": "Azure Text Translation Service client library samples for JavaScript (Beta)", - "engines": { - "node": ">=18.0.0" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-sdk-for-js.git", - "directory": "sdk/translation/ai-translation-text-rest" - }, - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic", - "translate", - "translation" - ], - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest", - "dependencies": { - "@azure-rest/ai-translation-text": "next", - "dotenv": "latest" - } -} diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/sample.env b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/sample.env deleted file mode 100644 index bbdd64c0b36b..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/sample.env +++ /dev/null @@ -1,6 +0,0 @@ -# Used in most samples. -# Get the key and region - https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource - -ENDPOINT="https://api.cognitive.microsofttranslator.com" -TEXT_TRANSLATOR_API_KEY="" -TEXT_TRANSLATOR_REGION="" diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translate.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translate.js deleted file mode 100644 index 9dde5c9aa941..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translate.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a text which language is know to a target language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Simple translate sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateAlignments.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateAlignments.js deleted file mode 100644 index 687536226751..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateAlignments.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can ask translation service to include alignment - * projection from source text to translated text. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Translation with alignments sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "The answer lies in machine translation." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeAlignment: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log(`Alignments: ${translation?.translations[0]?.alignment?.proj}`); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateCustom.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateCustom.js deleted file mode 100644 index a19eaf1b4bbc..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateCustom.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how You can get translations from a customized system built with - * Custom Translator (https://learn.microsoft.com/azure/cognitive-services/translator/customization). Add the Category ID from your Custom Translator [project details](https://learn.microsoft.com/azure/cognitive-services/translator/custom-translator/how-to-create-project#view-project-details) - * to this parameter to use your deployed customized system. - * - * It is possible to set `allowFalback` paramter. It specifies that the service is allowed to - * fall back to a general system when a custom system doesn't exist. Possible values are: - * `true` (default) or `false`. - * - * `allowFallback=false` specifies that the translation should only use systems trained for - * the category specified by the request. If a translation for language X to language Y requires - * chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) - * will need to be custom and have the same category. If no system is found with the specific - * category, the request will return a 400 status code. `allowFallback=true` specifies that - * the service is allowed to fall back to a general system when a custom system doesn't exist. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Custom translator sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - category: "<>", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDetection.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDetection.js deleted file mode 100644 index a1302d4fd07f..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDetection.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation without specifying the source language to a target language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Translate sample with auto-detection =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDictionary.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDictionary.js deleted file mode 100644 index 07f8cd687e9b..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateDictionary.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to keep words if you already know the translation you want - * to apply to a word or a phrase, you can supply it as markup within the request. - * The dynamic dictionary is safe only for compound nouns like proper names and product names. - * - * Note You must include the From parameter in your API translation request instead of using the autodetect feature. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Translation with Dictionary sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [ - { - text: 'The word wordomatic is a dictionary entry.', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleSources.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleSources.js deleted file mode 100644 index 199facefa7ce..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleSources.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a multiple text fields and each input text - * is in different language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Multiple input texts =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [ - { text: "This is a test." }, - { text: "Esto es una prueba." }, - { text: "Dies ist ein Test." }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleTargets.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleTargets.js deleted file mode 100644 index b6733480b83f..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateMultipleTargets.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can provide multiple target languages which results - * to each input element be translated to all target languages. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Multiple target languages translation =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs,es,de", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - for (const textKey in translation.translations) { - console.log( - `Text was translated to: '${translation?.translations[textKey]?.to}' and the result is: '${translation?.translations[textKey]?.text}'.`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateNoTranslate.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateNoTranslate.js deleted file mode 100644 index d36566396d8c..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateNoTranslate.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how it's sometimes useful to exclude specific content from translation. - * You can use the attribute class=notranslate to specify content that should remain - * in its original language. In the following example, the content inside the first div - * element won't be translated, while the content in the second div element will be translated. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Marking text input with notranslate div sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [ - { - text: '
This will not be translated.
This will be translated.
', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateProfanity.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateProfanity.js deleted file mode 100644 index 4620abd91a80..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateProfanity.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to change the profanity handling during translate call. - * Normally the Translator service will retain profanity that is present in the source - * in the translation. The degree of profanity and the context that makes words profane - * differ between cultures, and as a result the degree of profanity in the target language - * may be amplified or reduced. - * - * If you want to avoid getting profanity in the translation, regardless of the presence - * of profanity in the source text, you can use the profanity filtering option. The option - * allows you to choose whether you want to see profanity deleted, whether you want to mark - * profanities with appropriate tags (giving you the option to add your own post-processing), - * or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` - * and `NoAction` (default). - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Profanity handling sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is ***." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - profanityAction: "Marked", - profanityMarker: "Asterisk", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateSenteceLength.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateSenteceLength.js deleted file mode 100644 index 7f590d4f26c2..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateSenteceLength.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to you can ask translator service to include sentence boundaries - * for the input text and the translated text. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Translation with sentence boundaries sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "The answer lies in machine translation. This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeSentenceLength: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Source Sentece length: ${translation?.translations[0]?.sentLen?.srcSentLen.join(", ")}`, - ); - console.log( - `Translated Sentece length: ${translation?.translations[0]?.sentLen?.transSentLen.join(", ")}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateTextType.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateTextType.js deleted file mode 100644 index a68474efca45..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateTextType.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select whether the translated text is plain text or HTML text. - * Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== HTML translation sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateWithTransliteration.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateWithTransliteration.js deleted file mode 100644 index 038eb04ab1b5..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/translateWithTransliteration.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary You can combine both Translation and Transliteration in one Translate call. - * Your source Text can be in non-standard Script of a language as well as you - * can ask for non-standard Script of a target language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Translate with transliteration sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "hudha akhtabar." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "zh-Hans", - toScript: "Latn", - from: "ar", - fromScript: "Latn", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log(`Source Text: ${translation.sourceText?.text}`); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Transliterated text (${translation?.translations[0]?.transliteration?.script}): ${translation?.translations[0]?.transliteration?.text}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/transliterate.js b/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/transliterate.js deleted file mode 100644 index 01da4d585235..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/javascript/transliterate.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to convert characters or letters of a source language to the corresponding - * characters or letters of a target language. - */ -const TextTranslationClient = require("@azure-rest/ai-translation-text").default, - { isUnexpected } = require("@azure-rest/ai-translation-text"); - -require("dotenv").config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -async function main() { - console.log("== Simple transliterate sample =="); - - const translateCedential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText = [{ text: "这是个测试。" }]; - const transliterateResponse = await translationClient.path("/transliterate").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - fromScript: "Hans", - toScript: "Latn", - }, - }); - - if (isUnexpected(transliterateResponse)) { - throw transliterateResponse.body.error; - } - - const translations = transliterateResponse.body; - for (const transliteration of translations) { - console.log( - `Input text was transliterated to '${transliteration?.script}' script. Transliterated text: '${transliteration?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); - -module.exports = { main }; diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/README.md b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/README.md deleted file mode 100644 index 631996894401..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/README.md +++ /dev/null @@ -1,115 +0,0 @@ ---- -page_type: sample -languages: - - typescript -products: - - azure - - azure-cognitive-services - - azure-translator -urlFragment: ai-translation-text-typescript-beta ---- - -# Azure Text Translation Service client library samples for TypeScript (Beta) - -These sample programs show how to use the TypeScript client libraries for Azure Text Translation Service in some common scenarios. - -| **File Name** | **Description** | -| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [breakSentence.ts][breaksentence] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. | -| [breakSentenceWithAutoDetection.ts][breaksentencewithautodetection] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. | -| [dictionaryExamples.ts][dictionaryexamples] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. | -| [dictionaryLookup.ts][dictionarylookup] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. | -| [getLanguages.ts][getlanguages] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages | -| [getLanguagesAcceptLanguage.ts][getlanguagesacceptlanguage] | This sample demonstrates how you can select the language to use for user interface strings. Some of the fields in the response are names of languages or names of regions. Use this parameter to define the language in which these names are returned. The language is specified by providing a well-formed BCP 47 language tag. For instance, use the value `fr` to request names in French or use the value `zh-Hant` to request names in Chinese Traditional. Names are provided in the English language when a target language is not specified or when localization is not available. | -| [getLanguagesScope.ts][getlanguagesscope] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages for a selected scope | -| [translate.ts][translate] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation for a text which language is know to a target language. | -| [translateAlignments.ts][translatealignments] | This sample demonstrates how you can ask translation service to include alignment projection from source text to translated text. | -| [translateCustom.ts][translatecustom] | This sample demonstrates how You can get translations from a customized system built with Custom Translator (https://learn.microsoft.com/azure/cognitive-services/translator/customization). Add the Category ID from your Custom Translator [project details](https://learn.microsoft.com/azure/cognitive-services/translator/custom-translator/how-to-create-project#view-project-details) to this parameter to use your deployed customized system. It is possible to set `allowFalback` paramter. It specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. Possible values are: `true` (default) or `false`. `allowFallback=false` specifies that the translation should only use systems trained for the category specified by the request. If a translation for language X to language Y requires chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. If no system is found with the specific category, the request will return a 400 status code. `allowFallback=true` specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. | -| [translateDetection.ts][translatedetection] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation without specifying the source language to a target language. | -| [translateDictionary.ts][translatedictionary] | This sample demonstrates how to keep words if you already know the translation you want to apply to a word or a phrase, you can supply it as markup within the request. The dynamic dictionary is safe only for compound nouns like proper names and product names. Note You must include the From parameter in your API translation request instead of using the autodetect feature. | -| [translateMultipleSources.ts][translatemultiplesources] | This sample demonstrates how to make a simple call to the Azure Text Translator service to get translation for a multiple text fields and each input text is in different language. | -| [translateMultipleTargets.ts][translatemultipletargets] | This sample demonstrates how you can provide multiple target languages which results to each input element be translated to all target languages. | -| [translateNoTranslate.ts][translatenotranslate] | This sample demonstrates how it's sometimes useful to exclude specific content from translation. You can use the attribute class=notranslate to specify content that should remain in its original language. In the following example, the content inside the first div element won't be translated, while the content in the second div element will be translated. | -| [translateProfanity.ts][translateprofanity] | This sample demonstrates how to change the profanity handling during translate call. Normally the Translator service will retain profanity that is present in the source in the translation. The degree of profanity and the context that makes words profane differ between cultures, and as a result the degree of profanity in the target language may be amplified or reduced. If you want to avoid getting profanity in the translation, regardless of the presence of profanity in the source text, you can use the profanity filtering option. The option allows you to choose whether you want to see profanity deleted, whether you want to mark profanities with appropriate tags (giving you the option to add your own post-processing), or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` and `NoAction` (default). | -| [translateSenteceLength.ts][translatesentecelength] | This sample demonstrates how to you can ask translator service to include sentence boundaries for the input text and the translated text. | -| [translateTextType.ts][translatetexttype] | This sample demonstrates how you can select whether the translated text is plain text or HTML text. Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. | -| [translateWithTransliteration.ts][translatewithtransliteration] | You can combine both Translation and Transliteration in one Translate call. Your source Text can be in non-standard Script of a language as well as you can ask for non-standard Script of a target language. | -| [transliterate.ts][transliterate] | This sample demonstrates how to make a simple call to the Azure Text Translator service to convert characters or letters of a source language to the corresponding characters or letters of a target language. | - -## Prerequisites - -The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). - -Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using: - -```bash -npm install -g typescript -``` - -You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: - -- [Translator resource instance][createinstance_translatorresourceinstance] - -Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. - -Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. - -## Setup - -To run the samples using the published version of the package: - -1. Install the dependencies using `npm`: - -```bash -npm install -``` - -2. Compile the samples: - -```bash -npm run build -``` - -3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. - -4. Run whichever samples you like (note that some samples may require additional setup, see the table above): - -```bash -node dist/breakSentence.js -``` - -Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): - -```bash -npx cross-env ENDPOINT="" TEXT_TRANSLATOR_API_KEY="" TEXT_TRANSLATOR_REGION="" node dist/breakSentence.js -``` - -## Next Steps - -Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. - -[breaksentence]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentence.ts -[breaksentencewithautodetection]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentenceWithAutoDetection.ts -[dictionaryexamples]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryExamples.ts -[dictionarylookup]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryLookup.ts -[getlanguages]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguages.ts -[getlanguagesacceptlanguage]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesAcceptLanguage.ts -[getlanguagesscope]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesScope.ts -[translate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translate.ts -[translatealignments]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateAlignments.ts -[translatecustom]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateCustom.ts -[translatedetection]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDetection.ts -[translatedictionary]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDictionary.ts -[translatemultiplesources]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleSources.ts -[translatemultipletargets]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleTargets.ts -[translatenotranslate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateNoTranslate.ts -[translateprofanity]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateProfanity.ts -[translatesentecelength]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateSenteceLength.ts -[translatetexttype]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateTextType.ts -[translatewithtransliteration]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateWithTransliteration.ts -[transliterate]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/transliterate.ts -[apiref]: https://learn.microsoft.com/azure/ai-services/translator/reference/v3-0-reference -[freesub]: https://azure.microsoft.com/free/ -[createinstance_translatorresourceinstance]: https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource -[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/README.md -[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/package.json b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/package.json deleted file mode 100644 index dfd37950f266..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/package.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "@azure-samples/ai-translation-text-ts-beta", - "private": true, - "version": "1.0.0", - "description": "Azure Text Translation Service client library samples for TypeScript (Beta)", - "engines": { - "node": ">=18.0.0" - }, - "scripts": { - "build": "tsc", - "prebuild": "rimraf dist/" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Azure/azure-sdk-for-js.git", - "directory": "sdk/translation/ai-translation-text-rest" - }, - "keywords": [ - "node", - "azure", - "cloud", - "typescript", - "browser", - "isomorphic", - "translate", - "translation" - ], - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/Azure/azure-sdk-for-js/issues" - }, - "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest", - "dependencies": { - "@azure-rest/ai-translation-text": "next", - "dotenv": "latest" - }, - "devDependencies": { - "@types/node": "^18.0.0", - "typescript": "~5.6.2", - "rimraf": "latest" - } -} diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/sample.env b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/sample.env deleted file mode 100644 index bbdd64c0b36b..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/sample.env +++ /dev/null @@ -1,6 +0,0 @@ -# Used in most samples. -# Get the key and region - https://learn.microsoft.com/azure/cognitive-services/Translator/create-translator-resource - -ENDPOINT="https://api.cognitive.microsofttranslator.com" -TEXT_TRANSLATOR_API_KEY="" -TEXT_TRANSLATOR_REGION="" diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentence.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentence.ts deleted file mode 100644 index 25bf03b92b0e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentence.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Get Sentence Boundaries sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "zhè shì gè cè shì。" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - script: "Latn", - }, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentenceWithAutoDetection.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentenceWithAutoDetection.ts deleted file mode 100644 index 9489d2b0cca9..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/breakSentenceWithAutoDetection.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Sentence Boundaries with auto-detection sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "How are you? I am fine. What did you do today?" }]; - const breakSentenceResponse = await translationClient.path("/breaksentence").post({ - body: inputText, - }); - - if (isUnexpected(breakSentenceResponse)) { - throw breakSentenceResponse.body.error; - } - - const breakSentences = breakSentenceResponse.body; - for (const breakSentence of breakSentences) { - console.log(`The detected sentece boundaries: '${breakSentence?.sentLen.join(", ")}'.`); - console.log( - `Detected languages of the input text: ${breakSentence?.detectedLanguage?.language} with score: ${breakSentence?.detectedLanguage?.score}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryExamples.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryExamples.ts deleted file mode 100644 index 6915fa3eadf6..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryExamples.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. - */ -import TextTranslationClient, { - TranslatorCredential, - DictionaryExampleTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Dictionary Examples sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: DictionaryExampleTextItem[] = [{ text: "fly", translation: "volar" }]; - const dictionaryResponse = await translationClient.path("/dictionary/examples").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryExamples = dictionaryResponse.body; - for (const dictionaryExample of dictionaryExamples) { - console.log( - `For the given input ${dictionaryExample?.examples?.length} examples were found in the dictionary.`, - ); - const firstExample = dictionaryExample?.examples[0]; - console.log( - `Example: '${ - firstExample.targetPrefix + firstExample.targetTerm + firstExample.targetSuffix - }'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryLookup.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryLookup.ts deleted file mode 100644 index 744810e487fb..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/dictionaryLookup.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Dictionary Lookup sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "fly" }]; - const dictionaryResponse = await translationClient.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: { - to: "es", - from: "en", - }, - }); - - if (isUnexpected(dictionaryResponse)) { - throw dictionaryResponse.body.error; - } - - const dictionaryEntries = dictionaryResponse.body; - for (const dictionaryEntry of dictionaryEntries) { - console.log( - `For the given input ${dictionaryEntry?.translations?.length} entries were found in the dictionary.`, - ); - console.log( - `First entry: '${dictionaryEntry?.translations[0]?.displayTarget}', confidence: ${dictionaryEntry?.translations[0]?.confidence}.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguages.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguages.ts deleted file mode 100644 index 78f67211e3c3..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguages.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages - */ -import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== List supported languages sample =="); - - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesAcceptLanguage.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesAcceptLanguage.ts deleted file mode 100644 index 0b2ce50e715b..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesAcceptLanguage.ts +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select the language to use for user interface strings. - * Some of the fields in the response are names of languages or names of regions. - * Use this parameter to define the language in which these names are returned. - * The language is specified by providing a well-formed BCP 47 language tag. - * For instance, use the value `fr` to request names in French or use the value `zh-Hant` - * to request names in Chinese Traditional. - * - * Names are provided in the English language when a target language is not specified - * or when localization is not available. - */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== List supported localized languages sample =="); - - const parameters: GetSupportedLanguagesParameters = { - headers: { - "Accept-Language": "cs", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesScope.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesScope.ts deleted file mode 100644 index adedf0e2895d..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/getLanguagesScope.ts +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get a list of supported languages for a selected scope - */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; - -export async function main() { - console.log("== Scoped list supported languages sample =="); - - const parameters: GetSupportedLanguagesParameters = { - queryParameters: { - scope: "translation", - }, - }; - const translationClient = TextTranslationClient(endpoint); - const langResponse = await translationClient.path("/languages").get(parameters); - - if (isUnexpected(langResponse)) { - throw langResponse.body.error; - } - - const languages = langResponse.body; - - if (languages.translation) { - console.log("Translated languages:"); - for (const key in languages.translation) { - const translationLanguage = languages.translation[key]; - console.log( - `${key} -- name: ${translationLanguage.name} (${translationLanguage.nativeName})`, - ); - } - } - - if (languages.transliteration) { - console.log("Transliteration languages:"); - for (const key in languages.transliteration) { - const transliterationLanguage = languages.transliteration[key]; - console.log( - `${key} -- name: ${transliterationLanguage.name} (${transliterationLanguage.nativeName})`, - ); - } - } - - if (languages.dictionary) { - console.log("Dictionary languages:"); - for (const key in languages.dictionary) { - const dictionaryLanguage = languages.dictionary[key]; - console.log( - `${key} -- name: ${dictionaryLanguage.name} (${dictionaryLanguage.nativeName}), supported target languages count: ${dictionaryLanguage.translations.length}`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translate.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translate.ts deleted file mode 100644 index 2435f494285e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translate.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a text which language is know to a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Simple translate sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateAlignments.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateAlignments.ts deleted file mode 100644 index 9baf6597850e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateAlignments.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can ask translation service to include alignment - * projection from source text to translated text. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with alignments sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "The answer lies in machine translation." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeAlignment: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log(`Alignments: ${translation?.translations[0]?.alignment?.proj}`); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateCustom.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateCustom.ts deleted file mode 100644 index 83159f47a366..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateCustom.ts +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how You can get translations from a customized system built with - * Custom Translator (https://learn.microsoft.com/azure/cognitive-services/translator/customization). Add the Category ID from your Custom Translator [project details](https://learn.microsoft.com/azure/cognitive-services/translator/custom-translator/how-to-create-project#view-project-details) - * to this parameter to use your deployed customized system. - * - * It is possible to set `allowFalback` paramter. It specifies that the service is allowed to - * fall back to a general system when a custom system doesn't exist. Possible values are: - * `true` (default) or `false`. - * - * `allowFallback=false` specifies that the translation should only use systems trained for - * the category specified by the request. If a translation for language X to language Y requires - * chaining through a pivot language E, then all the systems in the chain (X → E and E → Y) - * will need to be custom and have the same category. If no system is found with the specific - * category, the request will return a 400 status code. `allowFallback=true` specifies that - * the service is allowed to fall back to a general system when a custom system doesn't exist. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Custom translator sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - category: "<>", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDetection.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDetection.ts deleted file mode 100644 index cf5c1a188366..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDetection.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation without specifying the source language to a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translate sample with auto-detection =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDictionary.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDictionary.ts deleted file mode 100644 index 23eb715449dc..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateDictionary.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to keep words if you already know the translation you want - * to apply to a word or a phrase, you can supply it as markup within the request. - * The dynamic dictionary is safe only for compound nouns like proper names and product names. - * - * Note You must include the From parameter in your API translation request instead of using the autodetect feature. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - TranslatedTextItemOutput, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with Dictionary sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { - text: 'The word wordomatic is a dictionary entry.', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body as TranslatedTextItemOutput[]; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleSources.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleSources.ts deleted file mode 100644 index ffb5a49f6f7e..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleSources.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to get translation for a multiple text fields and each input text - * is in different language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Multiple input texts =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { text: "This is a test." }, - { text: "Esto es una prueba." }, - { text: "Dies ist ein Test." }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Detected languages of the input text: ${translation?.detectedLanguage?.language} with score: ${translation?.detectedLanguage?.score}.`, - ); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleTargets.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleTargets.ts deleted file mode 100644 index 20c00ed4e0ee..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateMultipleTargets.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can provide multiple target languages which results - * to each input element be translated to all target languages. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Multiple target languages translation =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs,es,de", - from: "en", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - for (const textKey in translation.translations) { - console.log( - `Text was translated to: '${translation?.translations[textKey]?.to}' and the result is: '${translation?.translations[textKey]?.text}'.`, - ); - } - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateNoTranslate.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateNoTranslate.ts deleted file mode 100644 index d505a78ba34d..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateNoTranslate.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how it's sometimes useful to exclude specific content from translation. - * You can use the attribute class=notranslate to specify content that should remain - * in its original language. In the following example, the content inside the first div - * element won't be translated, while the content in the second div element will be translated. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Marking text input with notranslate div sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { - text: '
This will not be translated.
This will be translated.
', - }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateProfanity.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateProfanity.ts deleted file mode 100644 index aa126e6baf74..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateProfanity.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to change the profanity handling during translate call. - * Normally the Translator service will retain profanity that is present in the source - * in the translation. The degree of profanity and the context that makes words profane - * differ between cultures, and as a result the degree of profanity in the target language - * may be amplified or reduced. - * - * If you want to avoid getting profanity in the translation, regardless of the presence - * of profanity in the source text, you can use the profanity filtering option. The option - * allows you to choose whether you want to see profanity deleted, whether you want to mark - * profanities with appropriate tags (giving you the option to add your own post-processing), - * or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` - * and `NoAction` (default). - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Profanity handling sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is ***." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - profanityAction: "Marked", - profanityMarker: "Asterisk", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateSenteceLength.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateSenteceLength.ts deleted file mode 100644 index 972f4358725a..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateSenteceLength.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to you can ask translator service to include sentence boundaries - * for the input text and the translated text. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translation with sentence boundaries sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [ - { text: "The answer lies in machine translation. This is a test." }, - ]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - - includeSentenceLength: true, - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Source Sentece length: ${translation?.translations[0]?.sentLen?.srcSentLen.join(", ")}`, - ); - console.log( - `Translated Sentece length: ${translation?.translations[0]?.sentLen?.transSentLen.join( - ", ", - )}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateTextType.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateTextType.ts deleted file mode 100644 index 51609a958959..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateTextType.ts +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how you can select whether the translated text is plain text or HTML text. - * Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== HTML translation sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "This is a test." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "cs", - from: "en", - textType: "html", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateWithTransliteration.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateWithTransliteration.ts deleted file mode 100644 index c3f0471edec4..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/translateWithTransliteration.ts +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary You can combine both Translation and Transliteration in one Translate call. - * Your source Text can be in non-standard Script of a language as well as you - * can ask for non-standard Script of a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Translate with transliteration sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "hudha akhtabar." }]; - const translateResponse = await translationClient.path("/translate").post({ - body: inputText, - queryParameters: { - to: "zh-Hans", - toScript: "Latn", - from: "ar", - fromScript: "Latn", - }, - }); - - if (isUnexpected(translateResponse)) { - throw translateResponse.body.error; - } - - const translations = translateResponse.body; - for (const translation of translations) { - console.log(`Source Text: ${translation.sourceText?.text}`); - console.log( - `Text was translated to: '${translation?.translations[0]?.to}' and the result is: '${translation?.translations[0]?.text}'.`, - ); - console.log( - `Transliterated text (${translation?.translations[0]?.transliteration?.script}): ${translation?.translations[0]?.transliteration?.text}`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/transliterate.ts b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/transliterate.ts deleted file mode 100644 index 555211ce1ed0..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/src/transliterate.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @summary This sample demonstrates how to make a simple call to the Azure Text Translator - * service to convert characters or letters of a source language to the corresponding - * characters or letters of a target language. - */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); - -const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; -const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; - -export async function main() { - console.log("== Simple transliterate sample =="); - - const translateCedential: TranslatorCredential = { - key: apiKey, - region, - }; - const translationClient = TextTranslationClient(endpoint, translateCedential); - - const inputText: InputTextItem[] = [{ text: "这是个测试。" }]; - const transliterateResponse = await translationClient.path("/transliterate").post({ - body: inputText, - queryParameters: { - language: "zh-Hans", - fromScript: "Hans", - toScript: "Latn", - }, - }); - - if (isUnexpected(transliterateResponse)) { - throw transliterateResponse.body.error; - } - - const translations = transliterateResponse.body; - for (const transliteration of translations) { - console.log( - `Input text was transliterated to '${transliteration?.script}' script. Transliterated text: '${transliteration?.text}'.`, - ); - } -} - -main().catch((err) => { - console.error(err); -}); diff --git a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/tsconfig.json b/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/tsconfig.json deleted file mode 100644 index 984eed535aa8..000000000000 --- a/sdk/translation/ai-translation-text-rest/samples/v1-beta/typescript/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "module": "commonjs", - "moduleResolution": "node", - "resolveJsonModule": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "alwaysStrict": true, - "outDir": "dist", - "rootDir": "src" - }, - "include": [ - "src/**/*.ts" - ] -} diff --git a/sdk/translation/ai-translation-text-rest/src/authentication.ts b/sdk/translation/ai-translation-text-rest/src/authentication.ts deleted file mode 100644 index a2f5c682982d..000000000000 --- a/sdk/translation/ai-translation-text-rest/src/authentication.ts +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { AzureKeyCredential, TokenCredential } from "@azure/core-auth"; -import { - PipelinePolicy, - PipelineRequest, - PipelineResponse, - SendRequest, -} from "@azure/core-rest-pipeline"; - -const APIM_KEY_HEADER_NAME = "Ocp-Apim-Subscription-Key"; -const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region"; -const APIM_RESOURCE_ID = "Ocp-Apim-ResourceId"; -export const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default"; - -export interface TranslatorCredential { - key: string; - region: string; -} - -export interface TranslatorTokenCredential { - tokenCredential: TokenCredential; - region: string; - azureResourceId: string; -} - -export class TranslatorAuthenticationPolicy implements PipelinePolicy { - name: string = "TranslatorAuthenticationPolicy"; - credential: TranslatorCredential; - - constructor(credential: TranslatorCredential) { - this.credential = credential; - } - - sendRequest(request: PipelineRequest, next: SendRequest): Promise { - request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key); - request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region); - - return next(request); - } -} - -export class TranslatorAzureKeyAuthenticationPolicy implements PipelinePolicy { - name: string = "TranslatorAzureKeyAuthenticationPolicy"; - credential: AzureKeyCredential; - - constructor(credential: AzureKeyCredential) { - this.credential = credential; - } - - sendRequest(request: PipelineRequest, next: SendRequest): Promise { - request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key); - - return next(request); - } -} - -export class TranslatorTokenCredentialAuthenticationPolicy implements PipelinePolicy { - name: string = "TranslatorTokenCredentialAuthenticationPolicy"; - credential: TranslatorTokenCredential; - - constructor(credential: TranslatorTokenCredential) { - this.credential = credential; - } - - sendRequest(request: PipelineRequest, next: SendRequest): Promise { - request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region); - request.headers.set(APIM_RESOURCE_ID, this.credential.azureResourceId); - - return next(request); - } -} diff --git a/sdk/translation/ai-translation-text-rest/src/generated/clientDefinitions.ts b/sdk/translation/ai-translation-text-rest/src/clientDefinitions.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/clientDefinitions.ts rename to sdk/translation/ai-translation-text-rest/src/clientDefinitions.ts diff --git a/sdk/translation/ai-translation-text-rest/src/customClient.ts b/sdk/translation/ai-translation-text-rest/src/customClient.ts deleted file mode 100644 index 7d9c07d0f236..000000000000 --- a/sdk/translation/ai-translation-text-rest/src/customClient.ts +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { getClient, ClientOptions } from "@azure-rest/core-client"; -import { logger } from "./generated/logger"; -import * as coreRestPipeline from "@azure/core-rest-pipeline"; -import { TextTranslationClient } from "./generated/clientDefinitions"; -import { - DEFAULT_SCOPE, - TranslatorCredential, - TranslatorTokenCredential, - TranslatorAuthenticationPolicy, - TranslatorAzureKeyAuthenticationPolicy, - TranslatorTokenCredentialAuthenticationPolicy, -} from "./authentication"; -import { AzureKeyCredential, KeyCredential, TokenCredential } from "@azure/core-auth"; - -const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com"; -const PLATFORM_HOST = "cognitiveservices"; -const PLATFORM_PATH = "/translator/text/v3.0"; - -function isKeyCredential(credential: any): credential is KeyCredential { - return (credential as KeyCredential)?.key !== undefined; -} - -function isTranslatorKeyCredential(credential: any): credential is TranslatorCredential { - return (credential as TranslatorCredential)?.key !== undefined; -} - -function isTokenCredential(credential: any): credential is TokenCredential { - return (credential as TokenCredential)?.getToken !== undefined; -} - -function isTranslatorTokenCredential(credential: any): credential is TranslatorTokenCredential { - return ( - (credential as TranslatorTokenCredential)?.tokenCredential !== undefined && - (credential as TranslatorTokenCredential)?.azureResourceId !== undefined - ); -} - -function isCredentials(credential: any): boolean { - return ( - isKeyCredential(credential) || - isTranslatorKeyCredential(credential) || - isTokenCredential(credential) || - isTranslatorTokenCredential(credential) - ); -} - -/** - * Initialize a new instance of `TextTranslationClient` - * @param credential type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials - * used to authenticate the service with. - * @param options type: ClientOptions, the parameter for all optional parameters - */ -export default function createClient( - credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, - options?: ClientOptions, -): TextTranslationClient; - -/** - * Initialize a new instance of `TextTranslationClient` - * @param endpoint type: string, Supported Text Translation endpoints (protocol and hostname, for example: - * https://api.cognitive.microsofttranslator.com). - * @param options type: ClientOptions, the parameter for all optional parameters - */ -export default function createClient( - endpoint: string, - options?: ClientOptions, -): TextTranslationClient; - -/** - * Initialize a new instance of `TextTranslationClient` - * @param endpoint type: string, Supported Text Translation endpoints (protocol and hostname, for example: - * https://api.cognitive.microsofttranslator.com). - * @param credential type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials - * used to authenticate the service with. - * @param options type: ClientOptions, the parameter for all optional parameters - */ -export default function createClient( - endpoint: string, - credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, - options?: ClientOptions, -): TextTranslationClient; - -// Implementation -export default function createClient( - arg1?: - | string - | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential), - arg2?: - | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential) - | ClientOptions, - arg3?: ClientOptions, -): TextTranslationClient { - let serviceEndpoint: string; - - let endpoint: string | undefined; - let options: ClientOptions | undefined; - let credential: - | TranslatorCredential - | TranslatorTokenCredential - | KeyCredential - | TokenCredential - | undefined; - - if (typeof arg1 === "string") { - endpoint = arg1; - } - - if (typeof arg1 !== "string" && isCredentials(arg1)) { - credential = arg1; - options = arg2 as ClientOptions; - } else if (isCredentials(arg2)) { - credential = arg2 as - | TranslatorCredential - | TranslatorTokenCredential - | KeyCredential - | TokenCredential; - options = arg3; - } - - if (!options) { - options = {}; - } - - options.apiVersion = options.apiVersion ?? "3.0"; - - if (!endpoint) { - serviceEndpoint = DEFAULT_ENPOINT; - } else if (endpoint.toLowerCase().indexOf(PLATFORM_HOST) !== -1) { - serviceEndpoint = `${endpoint}${PLATFORM_PATH}`; - } else { - serviceEndpoint = endpoint; - } - - const baseUrl = options.baseUrl ?? `${serviceEndpoint}`; - - const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.1`; - const userAgentPrefix = - options.userAgentOptions && options.userAgentOptions.userAgentPrefix - ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` - : `${userAgentInfo}`; - options = { - ...options, - userAgentOptions: { - userAgentPrefix, - }, - loggingOptions: { - logger: options.loggingOptions?.logger ?? logger.info, - }, - }; - - const client = getClient(baseUrl, options) as TextTranslationClient; - - if (isTranslatorKeyCredential(credential)) { - const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy( - credential as TranslatorCredential, - ); - client.pipeline.addPolicy(mtAuthneticationPolicy); - } else if (isKeyCredential(credential)) { - const mtKeyAuthenticationPolicy = new TranslatorAzureKeyAuthenticationPolicy( - credential as AzureKeyCredential, - ); - client.pipeline.addPolicy(mtKeyAuthenticationPolicy); - } else if (isTokenCredential(credential)) { - client.pipeline.addPolicy( - coreRestPipeline.bearerTokenAuthenticationPolicy({ - credential: credential as TokenCredential, - scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE, - }), - ); - } else if (isTranslatorTokenCredential(credential)) { - client.pipeline.addPolicy( - coreRestPipeline.bearerTokenAuthenticationPolicy({ - credential: (credential as TranslatorTokenCredential).tokenCredential, - scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE, - }), - ); - client.pipeline.addPolicy( - new TranslatorTokenCredentialAuthenticationPolicy(credential as TranslatorTokenCredential), - ); - } - - return client; -} diff --git a/sdk/translation/ai-translation-text-rest/src/index.ts b/sdk/translation/ai-translation-text-rest/src/index.ts index 668e25ec2b7d..6de7383875e4 100644 --- a/sdk/translation/ai-translation-text-rest/src/index.ts +++ b/sdk/translation/ai-translation-text-rest/src/index.ts @@ -1,16 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import TextTranslationClient from "./customClient"; +import TextTranslationClient from "./textTranslationClient.js"; -export * from "./customClient"; -export * from "./generated/parameters"; -export * from "./generated/responses"; -export * from "./generated/clientDefinitions"; -export * from "./generated/isUnexpected"; -export * from "./generated/models"; -export * from "./generated/outputModels"; -export * from "./generated/serializeHelper"; -export { TranslatorCredential, TranslatorTokenCredential } from "./authentication"; +export * from "./textTranslationClient.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./serializeHelper.js"; export default TextTranslationClient; diff --git a/sdk/translation/ai-translation-text-rest/src/generated/isUnexpected.ts b/sdk/translation/ai-translation-text-rest/src/isUnexpected.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/isUnexpected.ts rename to sdk/translation/ai-translation-text-rest/src/isUnexpected.ts diff --git a/sdk/translation/ai-translation-text-rest/src/generated/logger.ts b/sdk/translation/ai-translation-text-rest/src/logger.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/logger.ts rename to sdk/translation/ai-translation-text-rest/src/logger.ts diff --git a/sdk/translation/ai-translation-text-rest/src/generated/models.ts b/sdk/translation/ai-translation-text-rest/src/models.ts similarity index 94% rename from sdk/translation/ai-translation-text-rest/src/generated/models.ts rename to sdk/translation/ai-translation-text-rest/src/models.ts index 725e8ddd1306..1596d852b98b 100644 --- a/sdk/translation/ai-translation-text-rest/src/generated/models.ts +++ b/sdk/translation/ai-translation-text-rest/src/models.ts @@ -18,7 +18,7 @@ export interface DictionaryExampleTextItem extends InputTextItem { } /** Alias for TextType */ -export type TextType = string | "Plain" | "Html"; +export type TextType = string; /** Translator profanity actions */ export type ProfanityAction = "NoAction" | "Marked" | "Deleted"; /** Translator profanity markers */ diff --git a/sdk/translation/ai-translation-text-rest/src/generated/outputModels.ts b/sdk/translation/ai-translation-text-rest/src/outputModels.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/outputModels.ts rename to sdk/translation/ai-translation-text-rest/src/outputModels.ts diff --git a/sdk/translation/ai-translation-text-rest/src/generated/parameters.ts b/sdk/translation/ai-translation-text-rest/src/parameters.ts similarity index 99% rename from sdk/translation/ai-translation-text-rest/src/generated/parameters.ts rename to sdk/translation/ai-translation-text-rest/src/parameters.ts index e0adc1680033..1593c50a2b36 100644 --- a/sdk/translation/ai-translation-text-rest/src/generated/parameters.ts +++ b/sdk/translation/ai-translation-text-rest/src/parameters.ts @@ -83,6 +83,8 @@ export interface TranslateQueryParamProperties { /** * Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, * complete element. Possible values are: plain (default) or html. + * + * Possible values: "Plain", "Html" */ textType?: TextType; /** diff --git a/sdk/translation/ai-translation-text-rest/src/generated/responses.ts b/sdk/translation/ai-translation-text-rest/src/responses.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/responses.ts rename to sdk/translation/ai-translation-text-rest/src/responses.ts diff --git a/sdk/translation/ai-translation-text-rest/src/generated/serializeHelper.ts b/sdk/translation/ai-translation-text-rest/src/serializeHelper.ts similarity index 100% rename from sdk/translation/ai-translation-text-rest/src/generated/serializeHelper.ts rename to sdk/translation/ai-translation-text-rest/src/serializeHelper.ts diff --git a/sdk/translation/ai-translation-text-rest/src/generated/textTranslationClient.ts b/sdk/translation/ai-translation-text-rest/src/textTranslationClient.ts similarity index 59% rename from sdk/translation/ai-translation-text-rest/src/generated/textTranslationClient.ts rename to sdk/translation/ai-translation-text-rest/src/textTranslationClient.ts index 6ab4169b8d8b..7ef23f9a434e 100644 --- a/sdk/translation/ai-translation-text-rest/src/generated/textTranslationClient.ts +++ b/sdk/translation/ai-translation-text-rest/src/textTranslationClient.ts @@ -5,6 +5,12 @@ import { getClient, ClientOptions } from "@azure-rest/core-client"; import { logger } from "./logger.js"; import { TextTranslationClient } from "./clientDefinitions.js"; +/** The optional parameters for the client */ +export interface TextTranslationClientOptions extends ClientOptions { + /** The api version option of the client */ + apiVersion?: string; +} + /** * Initialize a new instance of `TextTranslationClient` * @param endpointParam - Supported Text Translation endpoints (protocol and hostname, for example: @@ -13,10 +19,9 @@ import { TextTranslationClient } from "./clientDefinitions.js"; */ export default function createClient( endpointParam: string, - options: ClientOptions = {}, + { apiVersion = "3.0", ...options }: TextTranslationClientOptions = {}, ): TextTranslationClient { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; - options.apiVersion = options.apiVersion ?? "3.0"; const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.0-beta.1`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix @@ -31,8 +36,24 @@ export default function createClient( logger: options.loggingOptions?.logger ?? logger.info, }, }; - const client = getClient(endpointUrl, options) as TextTranslationClient; + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + client.pipeline.addPolicy({ + name: "ClientApiVersionPolicy", + sendRequest: (req, next) => { + // Use the apiVersion defined in request url directly + // Append one if there is no apiVersion and we have one at client options + const url = new URL(req.url); + if (!url.searchParams.get("api-version") && apiVersion) { + req.url = `${req.url}${ + Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" + }api-version=${apiVersion}`; + } + + return next(req); + }, + }); + return client; } diff --git a/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts deleted file mode 100644 index bd2eacc3a21e..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import { Context } from "mocha"; - -describe("BreakSentence tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("auto detect", async () => { - const inputText = [{ text: "hello world" }]; - const response = await client.path("/breaksentence").post({ - body: inputText, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const breakSentences = response.body; - assert.isTrue(breakSentences[0].detectedLanguage?.language === "en"); - assert.isTrue(breakSentences[0].detectedLanguage?.score === 0.98); - assert.isTrue(breakSentences[0].sentLen[0] === 11); - }); - - it("with language", async () => { - const inputText = [ - { - text: "รวบรวมแผ่นคำตอบ ระยะเวลาของโครงการ วิธีเลือกชายในฝัน หมายเลขซีเรียลของระเบียน วันที่สิ้นสุดของโครงการเมื่อเสร็จสมบูรณ์ ปีที่มีการรวบรวม ทุกคนมีวัฒนธรรมและวิธีคิดเหมือนกัน ได้รับโทษจำคุกตลอดชีวิตใน ฉันลดได้ถึง 55 ปอนด์ได้อย่างไร ฉันคิดว่าใครๆ ก็ต้องการกำหนดเมนูอาหารส่วนบุคคล", - }, - ]; - const parameters = { - language: "th", - }; - const response = await client.path("/breaksentence").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const breakSentences = response.body; - - const expectedLengths = [78, 41, 110, 46]; - for (let i = 0; i < expectedLengths.length; i++) { - assert.equal(expectedLengths[i], breakSentences[0].sentLen[i]); - } - }); - - it("with language and script", async () => { - const inputText = [{ text: "zhè shì gè cè shì。" }]; - const parameters = { - language: "zh-Hans", - script: "Latn", - }; - const response = await client.path("/breaksentence").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const breakSentences = response.body; - assert.equal(breakSentences[0].sentLen[0], 18); - }); - - it("with multiple languages", async () => { - const inputText = [{ text: "hello world" }, { text: "العالم هو مكان مثير جدا للاهتمام" }]; - const response = await client.path("/breaksentence").post({ - body: inputText, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const breakSentences = response.body; - assert.equal(breakSentences[0].detectedLanguage?.language, "en"); - assert.equal(breakSentences[1].detectedLanguage?.language, "ar"); - assert.equal(breakSentences[0].sentLen[0], 11); - assert.equal(breakSentences[1].sentLen[0], 32); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts deleted file mode 100644 index 0e653983f1b3..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import { Context } from "mocha"; - -describe("DictionaryExamples tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("single input element", async () => { - const inputText = [{ text: "fly", translation: "volar" }]; - const parameters = { - to: "es", - from: "en", - }; - const response = await client.path("/dictionary/examples").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const dictionaryExamples = response.body; - assert.equal(dictionaryExamples[0].normalizedSource, "fly"); - assert.isTrue(dictionaryExamples[0].normalizedTarget === "volar"); - }); - - it("multiple input elements", async () => { - const inputText = [ - { text: "fly", translation: "volar" }, - { text: "beef", translation: "came" }, - ]; - const parameters = { - to: "es", - from: "en", - }; - const response = await client.path("/dictionary/examples").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const dictionaryExamples = response.body; - assert.isTrue(dictionaryExamples.length === 2); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts deleted file mode 100644 index be1976a9372d..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import { Context } from "mocha"; - -describe("DictionaryLookup tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("single input element", async () => { - const inputText = [{ text: "fly" }]; - const parameters = { - to: "es", - from: "en", - }; - const response = await client.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: parameters, - }); - - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const dictionaryEntries = response.body; - assert.isTrue(dictionaryEntries[0].normalizedSource === "fly"); - assert.isTrue(dictionaryEntries[0].displaySource === "fly"); - }); - - it("multiple input elements", async () => { - const inputText = [{ text: "fly" }, { text: "fox" }]; - const parameters = { - to: "es", - from: "en", - }; - const response = await client.path("/dictionary/lookup").post({ - body: inputText, - queryParameters: parameters, - }); - - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const dictionaryEntries = response.body; - assert.isTrue(dictionaryEntries.length === 2); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts deleted file mode 100644 index 8d9fc8b89ced..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import { Context } from "mocha"; - -describe("GetLanguages tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("all scopes", async () => { - const response = await client.path("/languages").get(); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.translation !== null); - assert.isTrue(languages.transliteration !== null); - assert.isTrue(languages.dictionary !== null); - }); - - it("translation scope", async () => { - const parameters = { - queryParameters: { - scope: "translation", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.translation !== null); - assert.isTrue(languages?.translation?.["af"]?.dir !== null); - assert.isTrue(languages?.translation?.["af"]?.name !== null); - assert.isTrue(languages?.translation?.["af"]?.nativeName !== null); - }); - - it("transliteration scope", async () => { - const parameters = { - queryParameters: { - scope: "transliteration", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.transliteration !== null); - assert.isTrue(languages?.transliteration?.["be"]?.name !== null); - assert.isTrue(languages?.transliteration?.["be"]?.nativeName !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts !== null); - - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].code !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].dir !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].name !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].nativeName !== null); - - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].toScripts !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].toScripts[0].code !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].toScripts[0].dir !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].toScripts[0].name !== null); - assert.isTrue(languages?.transliteration?.["be"]?.scripts[0].toScripts[0].nativeName !== null); - }); - - it("transliteration scope multiple scripts", async () => { - const parameters = { - queryParameters: { - scope: "transliteration", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.transliteration !== null); - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.name !== null); - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.nativeName !== null); - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.scripts !== null); - - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.scripts?.length === 2); - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.scripts[0].toScripts.length === 2); - assert.isTrue(languages?.transliteration?.["zh-Hant"]?.scripts[1].toScripts.length === 2); - }); - - it("dictionary scope", async () => { - const parameters = { - queryParameters: { - scope: "dictionary", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.dictionary !== null); - assert.isTrue(languages?.dictionary?.["de"]?.name !== null); - assert.isTrue(languages?.dictionary?.["de"]?.nativeName !== null); - assert.isTrue(languages?.dictionary?.["de"]?.translations !== null); - - assert.isTrue(languages?.dictionary?.["de"]?.translations[0].code !== null); - assert.isTrue(languages?.dictionary?.["de"]?.translations[0].dir !== null); - assert.isTrue(languages?.dictionary?.["de"]?.translations[0].name !== null); - assert.isTrue(languages?.dictionary?.["de"]?.translations[0].nativeName !== null); - }); - - it("dictionary scope with multiple translations", async () => { - const parameters = { - queryParameters: { - scope: "dictionary", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.dictionary !== null); - assert.isTrue(languages?.dictionary?.["en"]?.name !== null); - assert.isTrue(languages?.dictionary?.["en"]?.nativeName !== null); - assert.isTrue(languages?.dictionary?.["en"]?.translations !== null); - assert.isTrue(languages?.dictionary?.["en"]?.translations?.length !== 1); - }); - - it("with culture", async () => { - const parameters = { - headers: { - "Accept-Language": "es", - }, - }; - const response = await client.path("/languages").get(parameters); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const languages = response.body; - assert.isTrue(languages.translation !== null); - assert.isTrue(languages.transliteration !== null); - assert.isTrue(languages.dictionary !== null); - - assert.isTrue(languages?.translation?.["en"]?.name !== null); - assert.isTrue(languages?.translation?.["en"]?.nativeName !== null); - assert.isTrue(languages?.translation?.["en"]?.dir !== null); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts deleted file mode 100644 index 0815772ba98a..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { - createCustomTranslationClient, - createTranslationClient, - createTokenTranslationClient, - createAADAuthenticationTranslationClient, - startRecorder, -} from "./utils/recordedClient"; -import { Context } from "mocha"; - -describe("Translate tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - let customClient: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - customClient = await createCustomTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("translate basic", async () => { - const parameters = { - to: "cs", - from: "en", - }; - const response = await client.path("/translate").post({ - body: [{ text: "This is a test." }], - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].translations.length > 0); - assert.isTrue(translations[0].translations[0].text !== null); - }); - - it("with auto detect", async () => { - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].translations.length > 0); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[0].translations[0].text !== null); - }); - - it("no translate tag", async () => { - const inputText = [{ text: "今天是怎么回事是非常可怕的" }]; - const parameters = { - to: "zh-chs", - from: "en", - textType: "html", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].translations[0].text.includes("今天是怎么回事是")); - }); - - it("dictionary tag", async () => { - const inputText = [ - { - text: 'The word < mstrans:dictionary translation ="wordomatic">wordomatic is a dictionary entry.', - }, - ]; - const parameters = { - to: "es", - from: "en", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].translations[0].text.includes("wordomatic")); - }); - - it("transliteration", async () => { - const inputText = [{ text: "hudha akhtabar." }]; - const parameters = { - to: "zh-Hans", - from: "ar", - fromScript: "Latn", - toScript: "Latn", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].translations[0].text !== null); - }); - - it("from latin to latin script", async () => { - const inputText = [{ text: "ap kaise ho" }]; - const parameters = { - to: "ta", - from: "hi", - fromScript: "Latn", - toScript: "Latn", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].translations[0].transliteration != null); - assert.isTrue( - translations[0].translations[0].transliteration?.text.includes("eppadi irukkiraai?"), - ); - }); - - it("multiple input text", async () => { - const inputText = [ - { text: "This is a test." }, - { text: "Esto es una prueba." }, - { text: "Dies ist ein Test." }, - ]; - const parameters = { - to: "cs", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 3); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[1].detectedLanguage?.language === "es"); - assert.isTrue(translations[2].detectedLanguage?.language === "de"); - - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[1].detectedLanguage?.score === 1); - assert.isTrue(translations[2].detectedLanguage?.score === 1); - - assert.isTrue(translations[0].translations[0].text != null); - assert.isTrue(translations[1].translations[0].text != null); - assert.isTrue(translations[2].translations[0].text != null); - }); - - it("multiple target languages", async () => { - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs,es,de", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].translations.length === 3); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - - assert.isTrue(translations[0].translations[0].text != null); - assert.isTrue(translations[0].translations[1].text != null); - assert.isTrue(translations[0].translations[2].text != null); - }); - - it("different text types", async () => { - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs", - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - }); - - it("with profanity", async () => { - const inputText = [{ text: "shit this is fucking crazy" }]; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: { - to: "zh-cn", - profanityAction: "Marked", - profanityMarker: "Asterisk", - }, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[0].translations[0].text.includes("***")); - }); - - it("with alignment", async () => { - const inputText = [{ text: "It is a beautiful morning" }]; - const parameters = { - to: "cs", - includeAlignment: true, - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[0].translations[0].alignment?.proj != null); - }); - - it("with include sentence length", async () => { - const inputText = [ - { - text: "La réponse se trouve dans la traduction automatique. La meilleure technologie de traduction automatique ne peut pas toujours fournir des traductions adaptées à un site ou des utilisateurs comme un être humain. Il suffit de copier et coller un extrait de code n'importe où.", - }, - ]; - const parameters = { - to: "fr", - includeSentenceLength: true, - }; - const response = await client.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].detectedLanguage?.language === "fr"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[0].translations[0].sentLen?.srcSentLen.length === 3); - assert.isTrue(translations[0].translations[0].sentLen?.transSentLen.length === 3); - }); - - it("with custom endpoint", async () => { - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs", - includeSentenceLength: true, - }; - const response = await customClient.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations.length === 1); - assert.isTrue(translations[0].translations.length === 1); - assert.isTrue(translations[0].detectedLanguage?.language === "en"); - assert.isTrue(translations[0].detectedLanguage?.score === 1); - assert.isTrue(translations[0].translations[0].text != null); - }); - - it("with token", async () => { - const tokenClient = await createTokenTranslationClient({ recorder }); - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs", - }; - const response = await tokenClient.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - }); - - it("with AAD authentication", async () => { - const tokenClient = await createAADAuthenticationTranslationClient({ recorder }); - const inputText = [{ text: "This is a test." }]; - const parameters = { - to: "cs", - }; - const response = await tokenClient.path("/translate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts deleted file mode 100644 index 6e6e6b039691..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import { TextTranslationClient, isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import { Context } from "mocha"; -import { editDistance } from "./utils/testHelper"; - -describe("Transliterate tests", () => { - let recorder: Recorder; - let client: TextTranslationClient; - - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); - client = await createTranslationClient({ recorder }); - }); - - afterEach(async function () { - await recorder.stop(); - }); - - it("transliterate basic", async () => { - const inputText = [{ text: "这里怎么一回事?" }]; - const parameters = { - language: "zh-Hans", - fromScript: "Hans", - toScript: "Latn", - }; - const response = await client.path("/transliterate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].script !== null); - assert.isTrue(translations[0].text !== null); - }); - - it("multiple text array", async () => { - const inputText = [{ text: "यहएककसौटीहैयहएककसौटीहै" }, { text: "यहएककसौटीहै" }]; - const parameters = { - language: "hi", - fromScript: "Deva", - toScript: "Latn", - }; - const response = await client.path("/transliterate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].script !== null); - assert.isTrue(translations[0].text !== null); - }); - - it("with edit distance", async () => { - const inputText = [{ text: "gujarat" }, { text: "hadman" }, { text: "hukkabar" }]; - const parameters = { - language: "gu", - fromScript: "Latn", - toScript: "gujr", - }; - const response = await client.path("/transliterate").post({ - body: inputText, - queryParameters: parameters, - }); - assert.equal(response.status, "200"); - - if (isUnexpected(response)) { - throw response.body; - } - - const translations = response.body; - assert.isTrue(translations[0].text !== null); - assert.isTrue(translations[1].text !== null); - assert.isTrue(translations[2].text !== null); - - const expectedText = ["ગુજરાત", "હદમાં", "હુક્કાબાર"]; - - let editDistanceValue = 0; - for (let i = 0; i < expectedText.length; i++) { - editDistanceValue = editDistanceValue + editDistance(expectedText[i], translations[i].text); - } - assert.isTrue(editDistanceValue < 6); - }); -}); diff --git a/sdk/translation/ai-translation-text-rest/test/public/utils/StaticAccessTokenCredential.ts b/sdk/translation/ai-translation-text-rest/test/public/utils/StaticAccessTokenCredential.ts deleted file mode 100644 index 27f5c8a0ed70..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/utils/StaticAccessTokenCredential.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { TokenCredential, AccessToken } from "@azure/core-auth"; - -export class StaticAccessTokenCredential implements TokenCredential { - // AccessToken is an object with two properties: - // - A "token" property with a string value. - // - And an "expiresOnTimestamp" property with a numeric unix timestamp as its value. - constructor(private accessToken: string) {} - async getToken(): Promise { - return { - expiresOnTimestamp: Date.now() + 10000, - token: this.accessToken, - }; - } -} diff --git a/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts b/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts deleted file mode 100644 index 2db999cabc3c..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Context } from "mocha"; -import { - Recorder, - RecorderStartOptions, - isPlaybackMode, - assertEnvironmentVariable, -} from "@azure-tools/test-recorder"; -import { StaticAccessTokenCredential } from "./StaticAccessTokenCredential"; -import createTextTranslationClient, { - TranslatorCredential, - TranslatorTokenCredential, - TextTranslationClient, -} from "../../../src"; -import { ClientOptions } from "@azure-rest/core-client"; -import { createDefaultHttpClient, createPipelineRequest } from "@azure/core-rest-pipeline"; -import { TokenCredential } from "@azure/core-auth"; -import { ClientSecretCredential } from "@azure/identity"; - -const envSetupForPlayback: Record = { - TEXT_TRANSLATION_API_KEY: "fakeapikey", - TEXT_TRANSLATION_ENDPOINT: "https://fakeEndpoint.cognitive.microsofttranslator.com", - TEXT_TRANSLATION_CUSTOM_ENDPOINT: "https://fakeCustomEndpoint.cognitiveservices.azure.com", - TEXT_TRANSLATION_REGION: "fakeregion", - TEXT_TRANSLATION_AAD_REGION: "fakeregion", - TEXT_TRANSLATION_RESOURCE_ID: "fakeresourceid", -}; - -const recorderEnvSetup: RecorderStartOptions = { - envSetupForPlayback, -}; - -export async function startRecorder(context: Context): Promise { - const recorder = new Recorder(context.currentTest); - await recorder.start(recorderEnvSetup); - return recorder; -} - -export async function createTranslationClient(options: { - recorder?: Recorder; - clientOptions?: ClientOptions; -}): Promise { - const { recorder, clientOptions = {} } = options; - const updatedOptions = recorder ? recorder.configureClientOptions(clientOptions) : clientOptions; - const endpoint = assertEnvironmentVariable("TEXT_TRANSLATION_ENDPOINT"); - const apikey = assertEnvironmentVariable("TEXT_TRANSLATION_API_KEY"); - const region = assertEnvironmentVariable("TEXT_TRANSLATION_REGION"); - - const translatorCredential: TranslatorCredential = { - key: apikey, - region, - }; - const client = createTextTranslationClient(endpoint, translatorCredential, updatedOptions); - return client; -} - -export async function createCustomTranslationClient(options: { - recorder?: Recorder; - clientOptions?: ClientOptions; -}): Promise { - const { recorder, clientOptions = {} } = options; - const updatedOptions = recorder ? recorder.configureClientOptions(clientOptions) : clientOptions; - const customEndpoint = assertEnvironmentVariable("TEXT_TRANSLATION_CUSTOM_ENDPOINT"); - const apikey = assertEnvironmentVariable("TEXT_TRANSLATION_API_KEY"); - const region = assertEnvironmentVariable("TEXT_TRANSLATION_REGION"); - - const translatorCredential: TranslatorCredential = { - key: apikey, - region, - }; - const client = createTextTranslationClient(customEndpoint, translatorCredential, updatedOptions); - return client; -} - -export async function createTokenTranslationClient(options: { - recorder?: Recorder; - clientOptions?: ClientOptions; -}): Promise { - const { recorder, clientOptions = {} } = options; - const updatedOptions = recorder ? recorder.configureClientOptions(clientOptions) : clientOptions; - const endpoint = assertEnvironmentVariable("TEXT_TRANSLATION_ENDPOINT"); - const apikey = assertEnvironmentVariable("TEXT_TRANSLATION_API_KEY"); - const region = assertEnvironmentVariable("TEXT_TRANSLATION_REGION"); - - const issueTokenURL: string = - "https://" + - region + - ".api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=" + - apikey; - let credential: TokenCredential; - if (isPlaybackMode()) { - credential = createMockToken(); - } else { - const tokenClient = createDefaultHttpClient(); - const request = createPipelineRequest({ - url: issueTokenURL, - method: "POST", - }); - request.allowInsecureConnection = true; - const response = await tokenClient.sendRequest(request); - const token: string = response.bodyAsText!; - credential = new StaticAccessTokenCredential(token); - } - const client = createTextTranslationClient(endpoint, credential, updatedOptions); - return client; -} - -export async function createAADAuthenticationTranslationClient(options: { - recorder?: Recorder; - clientOptions?: ClientOptions; -}): Promise { - const { recorder, clientOptions = {} } = options; - const updatedOptions = recorder ? recorder.configureClientOptions(clientOptions) : clientOptions; - const endpoint = assertEnvironmentVariable("TEXT_TRANSLATION_ENDPOINT"); - const region = assertEnvironmentVariable("TEXT_TRANSLATION_AAD_REGION"); - const azureResourceId = assertEnvironmentVariable("TEXT_TRANSLATION_RESOURCE_ID"); - - let tokenCredential: TokenCredential; - if (isPlaybackMode()) { - tokenCredential = createMockToken(); - } else { - const clientId = assertEnvironmentVariable("TEXT_TRANSLATION_CLIENT_ID"); - const tenantId = assertEnvironmentVariable("TEXT_TRANSLATION_TENANT_ID"); - const secret = assertEnvironmentVariable("TEXT_TRANSLATION_CLIENT_SECRET"); - - tokenCredential = new ClientSecretCredential(tenantId, clientId, secret); - } - - const translatorTokenCredentials: TranslatorTokenCredential = { - tokenCredential, - azureResourceId, - region, - }; - const client = createTextTranslationClient(endpoint, translatorTokenCredentials, updatedOptions); - return client; -} - -export function createMockToken(): { - getToken: (_scopes: string) => Promise<{ token: string; expiresOnTimestamp: number }>; -} { - return { - getToken: async (_scopes: string) => { - return { token: "testToken", expiresOnTimestamp: 11111 }; - }, - }; -} diff --git a/sdk/translation/ai-translation-text-rest/test/public/utils/testHelper.ts b/sdk/translation/ai-translation-text-rest/test/public/utils/testHelper.ts deleted file mode 100644 index f5066aa27be0..000000000000 --- a/sdk/translation/ai-translation-text-rest/test/public/utils/testHelper.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -export function editDistance(s1: string, s2: string): number { - const n1 = s1.length; - const n2 = s2.length; - return distance(s1, s2, n1, n2); -} - -export function distance(s1: string, s2: string, n1: number, n2: number): number { - if (n1 === 0) { - return n2; - } - - if (n2 === 0) { - return n1; - } - - if (s1[n1 - 1] === s2[n2 - 1]) { - const d: number = distance(s1, s2, n1 - 1, n2 - 1); - return d; - } - const nums: number[] = [ - distance(s1, s2, n1, n2 - 1), - distance(s1, s2, n1 - 1, n2), - distance(s1, s2, n1 - 1, n2 - 1), - ]; - return 1 + Math.min(...nums); -} diff --git a/sdk/translation/ai-translation-text-rest/tests.yml b/sdk/translation/ai-translation-text-rest/tests.yml deleted file mode 100644 index 2e20837b1591..000000000000 --- a/sdk/translation/ai-translation-text-rest/tests.yml +++ /dev/null @@ -1,15 +0,0 @@ -parameters: -- name: Location - displayName: Location - type: string - default: eastus - -trigger: none - -extends: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: - PackageName: "@azure-rest/ai-translation-text" - ServiceDirectory: translation - Location: "${{ parameters.Location }}" - SupportedClouds: 'Public' diff --git a/sdk/translation/ai-translation-text-rest/tsconfig.json b/sdk/translation/ai-translation-text-rest/tsconfig.json deleted file mode 100644 index ae41228e0bda..000000000000 --- a/sdk/translation/ai-translation-text-rest/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../../tsconfig", - "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", - "paths": { - "@azure-rest/ai-translation-text": ["./src/index"] - } - }, - "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] -} diff --git a/sdk/translation/ai-translation-text-rest/tsp-location.yaml b/sdk/translation/ai-translation-text-rest/tsp-location.yaml index 151e72c1cf9d..6ee51b3c42cf 100644 --- a/sdk/translation/ai-translation-text-rest/tsp-location.yaml +++ b/sdk/translation/ai-translation-text-rest/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 9583ed6c26ce1f10bbea92346e28a46394a784b4 -repo: Azure/azure-rest-api-specs +commit: 8efaa61aa60b750f83b68893abb0481c9dbf5c13 +repo: /mnt/vss/_work/1/s/azure-rest-api-specs +additionalDirectories: