Translates text to a specified target language using the underlying Hugging Face model.
This endpoint accepts JSON data with the text and language details,
processes it through the machine learning model, and returns the translated text.
Parameters:
Name |
Type |
Description |
Default |
**kwargs |
Any
|
Arbitrary keyword arguments, usually empty as parameters are in the POST body.
|
{}
|
POST body parameters
text (str): The text to be translated.
decoding_strategy (str): Strategy to use for decoding text; e.g., 'beam_search', 'greedy'. Default is 'generate'.
source_lang (str): Source language code.
target_lang (str): Target language code. Default is 'en'.
additional_params (dict): Other model-specific parameters for translation.
Returns:
Type |
Description |
Dict[str, Any]
|
Dict[str, Any]: A dictionary with the original text, target language, and translated text.
|
Example CURL requests:
To translate text from English to French:
curl -X POST localhost:8080/translate \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"source_lang": "en",
"target_lang": "fr",
"decoding_strategy": "beam_search",
"num_beams": 5
}'
To translate text from Spanish to German:
/usr/bin/curl -X POST localhost:3000/api/v1/translate \
-H "Content-Type: application/json" \
-d '{
"text": "संयुक्त राष्ट्र के प्रमुख का कहना है कि सीरिया में कोई सैन्य समाधान नहीं है",
"source_lang": "hi_IN",
"target_lang": "en_XX",
"decoding_strategy": "generate",
"decoder_start_token_id": 2,
"early_stopping": true,
"eos_token_id": 2,
"forced_eos_token_id": 2,
"max_length": 200,
"num_beams": 5,
"pad_token_id": 1
}' | jq