Skip to content

Commit

Permalink
[Text Translation] Using latest TypeSpec and fixing GA review comments (
Browse files Browse the repository at this point in the history
Azure#29564)

### Packages impacted by this PR
ai-translation-text-rest

### Issues associated with this PR


### Describe the problem that is addressed by this PR
* Using latest TypeSpec
* Providing overrides for the Text Translation CLient

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_
* Only refactoring, no change in functionality

### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)

---------

Co-authored-by: Michal Materna <mimat@microsoft.com>
  • Loading branch information
MikeyMCZ and Michal Materna authored May 31, 2024
1 parent 2e252ec commit 1e76d19
Show file tree
Hide file tree
Showing 68 changed files with 587 additions and 432 deletions.
8 changes: 1 addition & 7 deletions sdk/translation/ai-translation-text-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# Release History

## 1.0.0-beta.2 (Unreleased)
## 1.0.0 (2024-05-21)

### Features Added
- Added support for AAD authentication.

### Breaking Changes

### Bugs Fixed

### Other Changes

## 1.0.0-beta.1 (2023-04-18)
Initial release

Expand Down
2 changes: 1 addition & 1 deletion sdk/translation/ai-translation-text-rest/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/translation/ai-translation-text-rest",
"Tag": "js/translation/ai-translation-text-rest_6dacbcc4a1"
"Tag": "js/translation/ai-translation-text-rest_34ef4ea36f"
}
2 changes: 1 addition & 1 deletion sdk/translation/ai-translation-text-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@azure-rest/ai-translation-text",
"sdk-type": "client",
"author": "Microsoft Corporation",
"version": "1.0.0-beta.2",
"version": "1.0.0",
"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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ export interface BreakSentenceItemOutput {
export function buildMultiCollection(items: string[], parameterName: string): string;

// @public
export interface CommonScriptModelOutput {
code: string;
dir: string;
name: string;
nativeName: string;
}
function createClient(credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient;

// @public
function createClient(endpoint: string, options?: ClientOptions): TextTranslationClient;

// @public
function createClient(endpoint: undefined | string, credential?: undefined | TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient;
function createClient(endpoint: string, credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient;
export default createClient;

// @public
Expand Down Expand Up @@ -166,70 +164,70 @@ export interface FindSentenceBoundariesQueryParamProperties {
}

// @public (undocumented)
export interface GetLanguages {
get(options?: GetLanguagesParameters): StreamableMethod<GetLanguages200Response | GetLanguagesDefaultResponse>;
export interface GetSupportedLanguages {
get(options?: GetSupportedLanguagesParameters): StreamableMethod<GetSupportedLanguages200Response | GetSupportedLanguagesDefaultResponse>;
}

// @public (undocumented)
export interface GetLanguages200Headers {
export interface GetSupportedLanguages200Headers {
"x-requestid": string;
etag: string;
}

// @public
export interface GetLanguages200Response extends HttpResponse {
export interface GetSupportedLanguages200Response extends HttpResponse {
// (undocumented)
body: GetLanguagesResultOutput;
body: GetSupportedLanguagesResultOutput;
// (undocumented)
headers: RawHttpHeaders & GetLanguages200Headers;
headers: RawHttpHeaders & GetSupportedLanguages200Headers;
// (undocumented)
status: "200";
}

// @public (undocumented)
export interface GetLanguagesDefaultHeaders {
export interface GetSupportedLanguagesDefaultHeaders {
"x-requestid": string;
}

// @public (undocumented)
export interface GetLanguagesDefaultResponse extends HttpResponse {
export interface GetSupportedLanguagesDefaultResponse extends HttpResponse {
// (undocumented)
body: ErrorResponseOutput;
// (undocumented)
headers: RawHttpHeaders & GetLanguagesDefaultHeaders;
headers: RawHttpHeaders & GetSupportedLanguagesDefaultHeaders;
// (undocumented)
status: string;
}

// @public (undocumented)
export interface GetLanguagesHeaderParam {
export interface GetSupportedLanguagesHeaderParam {
// (undocumented)
headers?: RawHttpHeadersInput & GetLanguagesHeaders;
headers?: RawHttpHeadersInput & GetSupportedLanguagesHeaders;
}

// @public (undocumented)
export interface GetLanguagesHeaders {
export interface GetSupportedLanguagesHeaders {
"Accept-Language"?: string;
"If-None-Match"?: string;
"X-ClientTraceId"?: string;
}

// @public (undocumented)
export type GetLanguagesParameters = GetLanguagesQueryParam & GetLanguagesHeaderParam & RequestParameters;
export type GetSupportedLanguagesParameters = GetSupportedLanguagesQueryParam & GetSupportedLanguagesHeaderParam & RequestParameters;

// @public (undocumented)
export interface GetLanguagesQueryParam {
export interface GetSupportedLanguagesQueryParam {
// (undocumented)
queryParameters?: GetLanguagesQueryParamProperties;
queryParameters?: GetSupportedLanguagesQueryParamProperties;
}

// @public (undocumented)
export interface GetLanguagesQueryParamProperties {
export interface GetSupportedLanguagesQueryParamProperties {
scope?: string;
}

// @public
export interface GetLanguagesResultOutput {
export interface GetSupportedLanguagesResultOutput {
dictionary?: Record<string, SourceDictionaryLanguageOutput>;
translation?: Record<string, TranslationLanguageOutput>;
transliteration?: Record<string, TransliterationLanguageOutput>;
Expand All @@ -241,7 +239,7 @@ export interface InputTextItem {
}

// @public (undocumented)
export function isUnexpected(response: GetLanguages200Response | GetLanguagesDefaultResponse): response is GetLanguagesDefaultResponse;
export function isUnexpected(response: GetSupportedLanguages200Response | GetSupportedLanguagesDefaultResponse): response is GetSupportedLanguagesDefaultResponse;

// @public (undocumented)
export function isUnexpected(response: Translate200Response | TranslateDefaultResponse): response is TranslateDefaultResponse;
Expand All @@ -258,6 +256,17 @@ export function isUnexpected(response: LookupDictionaryEntries200Response | Look
// @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<LookupDictionaryEntries200Response | LookupDictionaryEntriesDefaultResponse>;
Expand Down Expand Up @@ -390,9 +399,15 @@ export interface LookupDictionaryExamplesQueryParamProperties {
to: string;
}

// @public
export type ProfanityAction = "NoAction" | "Marked" | "Deleted";

// @public
export type ProfanityMarker = "Asterisk" | "Tag";

// @public (undocumented)
export interface Routes {
(path: "/languages"): GetLanguages;
(path: "/languages"): GetSupportedLanguages;
(path: "/translate"): Translate;
(path: "/transliterate"): Transliterate;
(path: "/breaksentence"): FindSentenceBoundaries;
Expand All @@ -401,14 +416,14 @@ export interface Routes {
}

// @public
export interface SentenceLengthOutput {
export interface SentenceBoundariesOutput {
srcSentLen: number[];
transSentLen: number[];
}

// @public
export interface SourceDictionaryLanguageOutput {
dir: string;
dir: LanguageDirectionalityOutput;
name: string;
nativeName: string;
translations: Array<TargetDictionaryLanguageOutput>;
Expand All @@ -422,7 +437,7 @@ export interface SourceTextOutput {
// @public
export interface TargetDictionaryLanguageOutput {
code: string;
dir: string;
dir: LanguageDirectionalityOutput;
name: string;
nativeName: string;
}
Expand All @@ -432,6 +447,9 @@ export type TextTranslationClient = Client & {
path: Routes;
};

// @public
export type TextType = string | "Plain" | "Html";

// @public (undocumented)
export interface Translate {
post(options: TranslateParameters): StreamableMethod<Translate200Response | TranslateDefaultResponse>;
Expand Down Expand Up @@ -483,7 +501,7 @@ export interface TranslatedTextAlignmentOutput {
export interface TranslatedTextItemOutput {
detectedLanguage?: DetectedLanguageOutput;
sourceText?: SourceTextOutput;
translations: Array<TranslationOutput>;
translations: Array<TranslationTextOutput>;
}

// @public (undocumented)
Expand Down Expand Up @@ -514,25 +532,25 @@ export interface TranslateQueryParamProperties {
fromScript?: string;
includeAlignment?: boolean;
includeSentenceLength?: boolean;
profanityAction?: string;
profanityMarker?: string;
profanityAction?: ProfanityAction;
profanityMarker?: ProfanityMarker;
suggestedFrom?: string;
textType?: string;
textType?: TextType;
to: string;
toScript?: string;
}

// @public
export interface TranslationLanguageOutput {
dir: string;
dir: LanguageDirectionalityOutput;
name: string;
nativeName: string;
}

// @public
export interface TranslationOutput {
export interface TranslationTextOutput {
alignment?: TranslatedTextAlignmentOutput;
sentLen?: SentenceLengthOutput;
sentLen?: SentenceBoundariesOutput;
text: string;
to: string;
transliteration?: TransliteratedTextOutput;
Expand All @@ -557,8 +575,8 @@ export interface TranslatorTokenCredential {
}

// @public
export interface TransliterableScriptOutput extends CommonScriptModelOutput {
toScripts: Array<CommonScriptModelOutput>;
export interface TransliterableScriptOutput extends LanguageScriptOutput {
toScripts: Array<LanguageScriptOutput>;
}

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttran
export async function main() {
console.log("== List supported languages sample ==");

const translationClient = TextTranslationClient(endpoint, undefined, undefined);
const translationClient = TextTranslationClient(endpoint);
const langResponse = await translationClient.path("/languages").get();

if (isUnexpected(langResponse)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* or when localization is not available.
*/
import TextTranslationClient, {
GetLanguagesParameters,
GetSupportedLanguagesParameters,
isUnexpected,
} from "@azure-rest/ai-translation-text";

Expand All @@ -25,12 +25,12 @@ const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttran
export async function main() {
console.log("== List supported localized languages sample ==");

const parameters: GetLanguagesParameters = {
const parameters: GetSupportedLanguagesParameters = {
headers: {
"Accept-Language": "cs",
},
};
const translationClient = TextTranslationClient(endpoint, undefined, undefined);
const translationClient = TextTranslationClient(endpoint);
const langResponse = await translationClient.path("/languages").get(parameters);

if (isUnexpected(langResponse)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* service to get a list of supported languages for a selected scope
*/
import TextTranslationClient, {
GetLanguagesParameters,
GetSupportedLanguagesParameters,
isUnexpected,
} from "@azure-rest/ai-translation-text";

Expand All @@ -18,12 +18,12 @@ const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttran
export async function main() {
console.log("== Scoped list supported languages sample ==");

const parameters: GetLanguagesParameters = {
const parameters: GetSupportedLanguagesParameters = {
queryParameters: {
scope: "translation",
},
};
const translationClient = TextTranslationClient(endpoint, undefined, undefined);
const translationClient = TextTranslationClient(endpoint);
const langResponse = await translationClient.path("/languages").get(parameters);

if (isUnexpected(langResponse)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Take a look at our [API Documentation][apiref] for more information about the AP
[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/cognitive-services/translator/translator-text-apis
[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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function main() {
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}.`
`Detected languages of the input text: ${breakSentence?.detectedLanguage?.language} with score: ${breakSentence?.detectedLanguage?.score}.`,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ async function main() {
const dictionaryExamples = dictionaryResponse.body;
for (const dictionaryExample of dictionaryExamples) {
console.log(
`For the given input ${dictionaryExample?.examples?.length} examples were found in the dictionary.`
`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
}'.`
`Example: '${firstExample.targetPrefix + firstExample.targetTerm + firstExample.targetSuffix}'.`,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ async function main() {
const dictionaryEntries = dictionaryResponse.body;
for (const dictionaryEntry of dictionaryEntries) {
console.log(
`For the given input ${dictionaryEntry?.translations?.length} entries were found in the dictionary.`
`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}.`
`First entry: '${dictionaryEntry?.translations[0]?.displayTarget}', confidence: ${dictionaryEntry?.translations[0]?.confidence}.`,
);
}
}
Expand Down
Loading

0 comments on commit 1e76d19

Please sign in to comment.