Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.03k stars 1.19k forks source link

Custom Entity Recognition - SyntaxError: Missing initializer in const declaration #23609

Closed jackUTS closed 1 year ago

jackUTS commented 1 year ago

Describe the bug Following the guide for Custom Entity Recognition(https://github.com/Azure/azure-sdk-for-js/tree/@azure/ai-text-analytics_6.0.0-beta.1/sdk/textanalytics/ai-text-analytics/samples). const actions: AnalyzeBatchAction[] = [ { kind: "CustomEntityRecognition", deploymentName: "ner-deploy", projectName = "product-ner", }, ];

returns error "Syntax Error: Missing Initializer in const declaration"

To Reproduce Steps to reproduce the behavior:

  1. copy sample code from link aboive
  2. run code in terminal

Expected behavior program runs as expected from sample.

Screenshots image

Code const { AnalyzeBatchAction, AzureKeyCredential, TextAnalysisClient, } = require("@azure/ai-text-analytics");

const client = new TextAnalysisClient("", new AzureKeyCredential(""));

const documents = [ "Apple iPhone 14 Pro Max 256GB - $1899", "NBA 2K23 - $109", ];

async function main() { const actions: AnalyzeBatchAction[] = [ { kind: "CustomEntityRecognition", deploymentName: "ner-deploy", projectName = "product-ner", }, ]; const poller = await client.beginAnalyzeBatch(actions, documents, "en"); for await (const actionResult of results) { if (actionResult.kind !== "CustomEntityRecognition") { throw new Error(Expected a CustomEntityRecognition results but got: ${actionResult.kind}); } if (actionResult.error) { const { code, message } = actionResult.error; throw new Error(Unexpected error (${code}): ${message}); } for (const result of actionResult.results) { console.log(- Document ${result.id}); if (result.error) { const { code, message } = result.error; throw new Error(Unexpected error (${code}): ${message}); } console.log("\tRecognized Entities:"); for (const entity of result.entities) { console.log(\t- Entity "${entity.text}" of type ${entity.category}); } } } }

main();

azure-sdk commented 1 year ago

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Storage:0.18694614,Azure.Identity:0.11207476,Cosmos:0.09292228'

xirzec commented 1 year ago

This looks to me like you are using TS syntax inside a JS file?

Try removing the :AnalyzeBatchAction[] part here:

const actions: AnalyzeBatchAction[] = [
{
kind: "CustomEntityRecognition",
deploymentName: "ner-deploy",
projectName = "product-ner",
},
];

to make it:

const actions = [
{
kind: "CustomEntityRecognition",
deploymentName: "ner-deploy",
projectName = "product-ner",
},
];
jackUTS commented 1 year ago

Hi @xirzec,

This seemed to fix the issue, thanks, not sure where I got the typescript from.

I'm now having issues with TextAnalysisClient, as below. const client = new TextAnalysisClient("https://custom-ner.cognitiveservices.azure.com/", new AzureKeyCredential("<redacted>")); ^

TypeError: TextAnalysisClient is not a constructor

Any chance you could assist?

xirzec commented 1 year ago

@jackUTS Above it looked like you were using @azure/ai-text-analytics which has a TextAnalyticsClient: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics

But now it seems like you are trying to use the newer TextAnalysisClient from @azure/ai-language-text? https://github.com/Azure/azure-sdk-for-js/blob/b16bb8e2b97e4602257c6639bd8aad2d80cbb3f1/sdk/cognitivelanguage/ai-language-text/README.md

So maybe check you are importing from the correct package?

Also if that credential is real, you should rotate it immediately. :)

deyaaeldeen commented 1 year ago

@jackUTS Could you please use @azure/ai-language-text@1.0.0? Here is a sample for custom entity recognition. Please note that @azure/ai-text-analytics@6.0.0-beta.1 is a beta library that we're planning to deprecate.

ghost commented 1 year ago

Hi @jackUTS. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost commented 1 year ago

Hi @jackUTS, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.