|
8 | 8 | Formality, |
9 | 9 | GlossaryInfo, |
10 | 10 | GlossaryLanguagePair, |
| 11 | + ModelType, |
11 | 12 | Language, |
12 | 13 | SplitSentences, |
13 | 14 | TextResult, |
@@ -347,6 +348,7 @@ def translate_text( |
347 | 348 | non_splitting_tags: Union[str, List[str], None] = None, |
348 | 349 | splitting_tags: Union[str, List[str], None] = None, |
349 | 350 | ignore_tags: Union[str, List[str], None] = None, |
| 351 | + model_type: Union[str, ModelType, None] = None, |
350 | 352 | ) -> Union[TextResult, List[TextResult]]: |
351 | 353 | """Translate text(s) into the target language. |
352 | 354 |
|
@@ -387,6 +389,8 @@ def translate_text( |
387 | 389 | :param ignore_tags: (Optional) XML tags containing text that should not |
388 | 390 | be translated. |
389 | 391 | :type ignore_tags: List of XML tags or comma-separated-list of tags. |
| 392 | + :param model_type: (Optional) Controls whether the translation engine |
| 393 | + should use a potentially slower model to achieve higher quality. |
390 | 394 | :return: List of TextResult objects containing results, unless input |
391 | 395 | text was one string, then a single TextResult object is returned. |
392 | 396 | """ |
@@ -425,6 +429,8 @@ def translate_text( |
425 | 429 | request_data["tag_handling"] = tag_handling |
426 | 430 | if outline_detection is not None: |
427 | 431 | request_data["outline_detection"] = bool(outline_detection) |
| 432 | + if model_type is not None: |
| 433 | + request_data["model_type"] = str(model_type) |
428 | 434 |
|
429 | 435 | def join_tags(tag_argument: Union[str, Iterable[str]]) -> List[str]: |
430 | 436 | if isinstance(tag_argument, str): |
@@ -462,8 +468,14 @@ def join_tags(tag_argument: Union[str, Iterable[str]]) -> List[str]: |
462 | 468 | else "" |
463 | 469 | ) |
464 | 470 | billed_characters = int(translation.get("billed_characters")) |
| 471 | + model_type_used = translation.get("model_type_used") |
465 | 472 | output.append( |
466 | | - TextResult(text, detected_source_language, billed_characters) |
| 473 | + TextResult( |
| 474 | + text, |
| 475 | + detected_source_language, |
| 476 | + billed_characters, |
| 477 | + model_type_used, |
| 478 | + ) |
467 | 479 | ) |
468 | 480 |
|
469 | 481 | return output if multi_input else output[0] |
|
0 commit comments