<jupyter_start><jupyter_text>Azure NLP test<jupyter_code>import os, requests, uuid, json
from dotenv import load_dotenv
load_dotenv()
TRANSLATOR_TEXT_SUBSCRIPTION_KEY = os.getenv('TRANSLATOR_TEXT_SUBSCRIPTION_KEY')
TRANSLATOR_TEXT_ENDPOINTS = os.getenv('TRANSLATOR_TEXT_ENDPOINT')
path = '/translate?api-version=3.0'
params = '&to=en'
constructed_url = TRANSLATOR_TEXT_ENDPOINTS + path + params
headers = {
    'Ocp-Apim-Subscription-Key': TRANSLATOR_TEXT_SUBSCRIPTION_KEY,
    'Content-type': 'application/json',
    'X-ClientTraceId': str(uuid.uuid4())
}
body = [{
    'text': 'Hi Hermann how are you. Do you already know what you will do next?'
}]
request = requests.post(constructed_url, headers=headers, json=body)
response = request.json()
print(json.dumps(response, sort_keys=True, indent=4,
                 ensure_ascii=False, separators=(',', ': ')))
request.
assert 'detectedLanguage' in response[0], 'Missing detected language ' + response
assert 'translations' in response[0], 'Missing detected language ' + response
target_language = 'de'
params = '&to={}'.format(target_language)
params
response[0]['translations'][0]['text']
response[0]['detectedLanguage']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13643926788685523, 'fraction_numerical': 0.0074875207986688855, 'mean_word_length': 6.711538461538462, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '289746', 'license': 'MIT', 'n_tokens_mistral': 404, 'n_tokens_neox': 401, 'n_words': 82, 'path': '02_azure_translate.ipynb', 'repo_name': 'SubmitCode/gpt-2', 'size': '1202'}