in evals/translators/microsoft.py [0:0]
def translate(texts):
source = os.environ["SRC"]
target = os.environ["TRG"]
params = {"api-version": "3.0", "from": source, "to": [target]}
results = []
# decrease partition size if hitting limit of max 10000 characters per request
for partition in tqdm(list(toolz.partition_all(20, texts))):
body = [{"text": text} for text in partition]
response = requests.post(url, params=params, headers=headers, json=body)
if response.status_code != 200:
raise ValueError(
f"Incorrect response. code: {response.status_code} body: {response.json()}"
)
results += [r["translations"][0]["text"] for r in response.json()]
return results