Nidhal Baccouri
commited on
Commit
·
3dcf81b
1
Parent(s):
fd94b62
updated readme
Browse files- deep_translator/chatgpt.py +0 -10
- docs/README.rst +50 -1
deep_translator/chatgpt.py
CHANGED
@@ -68,13 +68,3 @@ class ChatGptTranslator(BaseTranslator):
|
|
68 |
@return: list of translations
|
69 |
"""
|
70 |
return self._translate_batch(batch, **kwargs)
|
71 |
-
|
72 |
-
|
73 |
-
if __name__ == "__main__":
|
74 |
-
T = ChatGptTranslator(
|
75 |
-
target="german",
|
76 |
-
)
|
77 |
-
r = T.translate_batch(
|
78 |
-
["you are awesome", "Thanks for having me", "Nice to meet you!"]
|
79 |
-
)
|
80 |
-
print("result: ", r)
|
|
|
68 |
@return: list of translations
|
69 |
"""
|
70 |
return self._translate_batch(batch, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/README.rst
CHANGED
@@ -81,6 +81,7 @@ When you should use it
|
|
81 |
- If you want to translate from a file
|
82 |
- If you want to get translations from many sources and not only one
|
83 |
- If you want to automate translations
|
|
|
84 |
- If you want to compare different translations
|
85 |
- If you want to detect language automatically
|
86 |
|
@@ -90,6 +91,7 @@ Why you should use it
|
|
90 |
|
91 |
- It's the only python tool that integrates many translators
|
92 |
- Multi language support
|
|
|
93 |
- Supports batch translation
|
94 |
- High level of abstraction
|
95 |
- Automatic language detection
|
@@ -113,6 +115,7 @@ Features
|
|
113 |
* Support for the `DeeplTranslator translator <https://www.deepl.com/en/translator/>`_ (version >= 1.2.5)
|
114 |
* Support for the `Papago translator <https://papago.naver.com/>`_ (version >= 1.4.4)
|
115 |
* Support for the `Libre translator <https://libretranslate.com/>`_
|
|
|
116 |
* Support for proxy usage
|
117 |
* Automatic single language detection
|
118 |
* Batch language detection
|
@@ -145,7 +148,9 @@ Also, you can install extras if you want support for specific use case. For exam
|
|
145 |
|
146 |
$ pip install deep-translator[pdf] # add support for pdf translation
|
147 |
|
148 |
-
$
|
|
|
|
|
149 |
|
150 |
============
|
151 |
Quick Start
|
@@ -154,6 +159,8 @@ Quick Start
|
|
154 |
.. code-block:: python
|
155 |
|
156 |
from deep_translator import GoogleTranslator
|
|
|
|
|
157 |
translated = GoogleTranslator(source='auto', target='de').translate("keep it up, you are awesome") # output -> Weiter so, du bist großartig
|
158 |
|
159 |
or using proxies:
|
@@ -192,12 +199,20 @@ In this section, demos on how to use all different integrated translators in thi
|
|
192 |
|
193 |
*Example*: If you want to use english as a source or target language, you can pass **english** or **en** as an argument
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
Imports
|
196 |
--------
|
197 |
|
198 |
.. code-block:: python
|
199 |
|
200 |
from deep_translator import (GoogleTranslator,
|
|
|
201 |
MicrosoftTranslator,
|
202 |
PonsTranslator,
|
203 |
LingueeTranslator,
|
@@ -556,6 +571,40 @@ Microsoft Translator
|
|
556 |
|
557 |
translated = MicrosoftTranslator(api_key='some-key', target='german').translate_file('path/to/file')
|
558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
|
560 |
Papago Translator
|
561 |
---------------------
|
|
|
81 |
- If you want to translate from a file
|
82 |
- If you want to get translations from many sources and not only one
|
83 |
- If you want to automate translations
|
84 |
+
- If you want to use ChatGpt for translations
|
85 |
- If you want to compare different translations
|
86 |
- If you want to detect language automatically
|
87 |
|
|
|
91 |
|
92 |
- It's the only python tool that integrates many translators
|
93 |
- Multi language support
|
94 |
+
- Support for ChatGpt (version >= 1.11.0)
|
95 |
- Supports batch translation
|
96 |
- High level of abstraction
|
97 |
- Automatic language detection
|
|
|
115 |
* Support for the `DeeplTranslator translator <https://www.deepl.com/en/translator/>`_ (version >= 1.2.5)
|
116 |
* Support for the `Papago translator <https://papago.naver.com/>`_ (version >= 1.4.4)
|
117 |
* Support for the `Libre translator <https://libretranslate.com/>`_
|
118 |
+
* Support for ChatGpt
|
119 |
* Support for proxy usage
|
120 |
* Automatic single language detection
|
121 |
* Batch language detection
|
|
|
148 |
|
149 |
$ pip install deep-translator[pdf] # add support for pdf translation
|
150 |
|
151 |
+
$ pip install deep-translator[ai] # add support for ChatGpt
|
152 |
+
|
153 |
+
$ poetry add deep-translator --extras "docx pdf ai" # for poetry usage
|
154 |
|
155 |
============
|
156 |
Quick Start
|
|
|
159 |
.. code-block:: python
|
160 |
|
161 |
from deep_translator import GoogleTranslator
|
162 |
+
|
163 |
+
# Use any translator you like, in this example GoogleTranslator
|
164 |
translated = GoogleTranslator(source='auto', target='de').translate("keep it up, you are awesome") # output -> Weiter so, du bist großartig
|
165 |
|
166 |
or using proxies:
|
|
|
199 |
|
200 |
*Example*: If you want to use english as a source or target language, you can pass **english** or **en** as an argument
|
201 |
|
202 |
+
.. note::
|
203 |
+
|
204 |
+
For all translators that require an ApiKey, you can either specify it as an argument to the translator class
|
205 |
+
or you can export it as an environment variable, this way you won't have to provide it to the class.
|
206 |
+
|
207 |
+
*Example*: export OPENAI_API_KEY="your_key"
|
208 |
+
|
209 |
Imports
|
210 |
--------
|
211 |
|
212 |
.. code-block:: python
|
213 |
|
214 |
from deep_translator import (GoogleTranslator,
|
215 |
+
ChatGptTranslator,
|
216 |
MicrosoftTranslator,
|
217 |
PonsTranslator,
|
218 |
LingueeTranslator,
|
|
|
571 |
|
572 |
translated = MicrosoftTranslator(api_key='some-key', target='german').translate_file('path/to/file')
|
573 |
|
574 |
+
ChatGpt Translator
|
575 |
+
---------------------
|
576 |
+
|
577 |
+
.. note::
|
578 |
+
|
579 |
+
You need to require an **api key** if you want to use the ChatGpt translator.
|
580 |
+
If you have an openai account, you can create an api key (https://platform.openai.com/account/api-keys).
|
581 |
+
|
582 |
+
- Required and optional attributes
|
583 |
+
|
584 |
+
There are two required attributes, namely "api_key" (string) and "target" (string or list).
|
585 |
+
Attribute "source" is optional.
|
586 |
+
|
587 |
+
You can provide your api key as an argument or you can export it as an env var
|
588 |
+
e.g. `export OPENAI_API_KEY="your_key"`
|
589 |
+
|
590 |
+
.. code-block:: python
|
591 |
+
|
592 |
+
text = 'happy coding'
|
593 |
+
translated = ChatGptTranslator(api_key='your_key', target='german').translate(text=text)
|
594 |
+
|
595 |
+
- Translate batch of texts
|
596 |
+
|
597 |
+
.. code-block:: python
|
598 |
+
|
599 |
+
texts = ["hallo welt", "guten morgen"]
|
600 |
+
translated = ChatGptTranslator(api_key='some-key', target='english').translate_batch(texts)
|
601 |
+
|
602 |
+
- Translate from a file:
|
603 |
+
|
604 |
+
.. code-block:: python
|
605 |
+
|
606 |
+
translated = ChatGptTranslator(api_key='some-key', target='german').translate_file('path/to/file')
|
607 |
+
|
608 |
|
609 |
Papago Translator
|
610 |
---------------------
|