question

Vinny-1652 avatar image
1 Vote"
Vinny-1652 asked YutongTie-MSFT answered

Which endpoint should I be using for Text analytics API connection?

I am following the QuickStart Python tutorial for using the Text Analytics API and it suggests saving your endpoint and key from the deployed resource i.e. 'Key 1' and 'endpoint' url.

key = "<paste-your-text-analytics-key-here>"
endpoint = "<paste-your-text-analytics-endpoint-here>"

I then use:

from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential

def authenticate_client():
ta_credential = AzureKeyCredential(key)
text_analytics_client = TextAnalyticsClient(
endpoint=endpoint, credential=ta_credential)
return text_analytics_client

client = authenticate_client()

the above should connect to the API.

At the moment when I run one of the features, for example, sentiment analysis, as per:

def sentiment_analysis_example(client):

 documents = ["I had the best day of my life. I wish you were there with me."]
 response = client.analyze_sentiment(documents = documents)[0]
 print("Document Sentiment: {}".format(response.sentiment))
 print("Overall scores: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(
     response.confidence_scores.positive,
     response.confidence_scores.neutral,
     response.confidence_scores.negative,
 ))
 for idx, sentence in enumerate(response.sentences):
     print("Sentence: {}".format(sentence.text))
     print("Sentence {} sentiment: {}".format(idx+1, sentence.sentiment))
     print("Sentence score:\nPositive={0:.2f}\nNeutral={1:.2f}\nNegative={2:.2f}\n".format(
         sentence.confidence_scores.positive,
         sentence.confidence_scores.neutral,
         sentence.confidence_scores.negative,
     ))

I get the following error:

ValueError: The value provided for the url part Endpoint was incorrect, and resulted in an invalid url




azure-cognitive-servicesazure-text-analytics
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DestinJoy-0985 avatar image
2 Votes"
DestinJoy-0985 answered

It seems you are passing a wrong end point.Go to test API resource and find out the end point .Provide the end point then it should work.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YutongTie-MSFT avatar image
0 Votes"
YutongTie-MSFT answered

Hi,

Please go to the Azure portal. If the Text Analytics resource you created in the Prerequisites section deployed successfully, click the Go to Resource button under Next Steps. You can find your key and endpoint in the resource's key and endpoint page, under resource management.

Regards,
Yutong

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.