MCPcopy Create free account
hub / github.com/DeepL/deepl-python / action_text

Function action_text

deepl/__main__.py:79–114  ·  view source on GitHub ↗

Action function for the text command.

(
    deepl_client: deepl.DeepLClient,
    show_detected_source: bool = False,
    show_billed_characters: Optional[bool] = None,
    show_model_type_used: Optional[bool] = None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

77
78
79def action_text(
80 deepl_client: deepl.DeepLClient,
81 show_detected_source: bool = False,
82 show_billed_characters: Optional[bool] = None,
83 show_model_type_used: Optional[bool] = None,
84 **kwargs,
85):
86 """Action function for the text command."""
87
88 if show_model_type_used and kwargs.get("model_type") is None:
89 # specify model_type so API includes model_type_used response parameter
90 kwargs["model_type"] = deepl.ModelType.LATENCY_OPTIMIZED
91
92 translation = deepl_client.translate_text(**kwargs)
93 output_list = (
94 translation if isinstance(translation, List) else [translation]
95 )
96 for output in output_list:
97 if show_detected_source:
98 print(f"Detected source language: {output.detected_source_lang}")
99 if show_billed_characters:
100 text_value = (
101 "unknown"
102 if output.billed_characters is None
103 else str(output.billed_characters)
104 )
105 print(f"Billed characters: {text_value}")
106 if show_model_type_used:
107 text_value = (
108 "unknown"
109 if output.model_type_used is None
110 else output.model_type_used
111 )
112 print(f"Model type used: {text_value}")
113
114 print(output.text)
115
116
117def action_rephrase(

Callers

nothing calls this directly

Calls 1

translate_textMethod · 0.80

Tested by

no test coverage detected