How to make a googletrans translator tool for Agent #5973
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @dkbs12 What language are you trying to translate? Maybe we can help finding a model. and then in your custom components from deep_translator import GoogleTranslator
translated = GoogleTranslator(source='auto', target='de').translate("keep it up, you are awesome") inside of def translate(
self,
results: Optional[List[Dict[str, Any]]] = None,
query: Optional[str] = None,
documents: Optional[Union[List[Document], List[Answer], List[str], List[Dict[str, Any]]]] = None,
dict_key: Optional[str] = None,
) -> Union[str, List[Document], List[Answer], List[str], List[Dict[str, Any]]]: For the custom component, I'd suggest that you simply copy https://github.com/deepset-ai/haystack/blob/main/haystack/nodes/translator/transformers.py to your own googletrans.py file and just rename the class and adjust the three methods. |
Beta Was this translation helpful? Give feedback.
Hello @dkbs12 What language are you trying to translate? Maybe we can help finding a model.
If you would like to create your custom component, here are some ideas. You could use deep-translator, which also support google translator: https://github.com/nidhaloff/deep-translator#id1
pip install deep-translator
and then in your custom components
translate
method you would do the following:inside of