51 | aphra
52 | 53 |Aphra package initializer. 54 | This module exposes the main API components and modules.
55 |22def translate(source_language, target_language, text, config_file="config.toml", log_calls=False): 86 | 23 """ 87 | 24 Translates the provided text from the source language to the target language using workflows. 88 | 25 89 | 26 This function provides a convenient interface to Aphra's workflow-based 90 | 27 translation system. 91 | 28 92 | 29 :param source_language: The source language of the text. 93 | 30 :param target_language: The target language of the text. 94 | 31 :param text: The text to be translated. 95 | 32 :param config_file: Path to the TOML file containing the configuration. 96 | 33 :param log_calls: Boolean indicating whether to log the call details. 97 | 34 :return: The improved translation of the text. 98 | 35 """ 99 | 36 # Load the model client 100 | 37 model_client = load_model_client(config_file) 101 | 38 102 | 39 # Create translation context 103 | 40 context = TranslationContext( 104 | 41 model_client=model_client, 105 | 42 source_language=source_language, 106 | 43 target_language=target_language, 107 | 44 log_calls=log_calls 108 | 45 ) 109 | 46 110 | 47 # Find the most suitable workflow for this content 111 | 48 workflow = get_suitable_workflow(text) 112 | 49 113 | 50 if workflow is None: 114 | 51 raise ValueError("No suitable workflow found for the provided text") 115 | 52 116 | 53 # Execute the workflow 117 | 54 result = workflow.run(context, text) 118 | 55 119 | 56 return result 120 |
Translates the provided text from the source language to the target language using workflows.
124 | 125 |This function provides a convenient interface to Aphra's workflow-based 126 | translation system.
127 | 128 |Parameters
129 | 130 |-
131 |
- source_language: The source language of the text. 132 |
- target_language: The target language of the text. 133 |
- text: The text to be translated. 134 |
- config_file: Path to the TOML file containing the configuration. 135 |
- log_calls: Boolean indicating whether to log the call details. 136 |
Returns
139 | 140 |141 |143 |The improved translation of the text.
142 |