A Python library for language detection and translation using OpenAI's GPT-4.
Project description
SimpleAITranslator
Overview
SimpleAITranslator is a Python library designed to identify the language of a given text and translate text between multiple languages using OpenAI's GPT-4. The library is especially useful for translating text containing multiple languages into a single target language.
Features
- Language Detection: Identify the language of a given text in ISO 639-3 format.
- Translation: Translate text containing multiple languages into another language in ISO 639-3 format.
Requirements
To use this library, you must have an OpenAI API key. This key allows the library to utilize OpenAI's GPT-4 for translation and language detection.
Installation
You can install the SimpleAITranslator library from PyPI:
pip install simpleaitranslator
Usage
Setting the OpenAI API Key
Before using SimpleAITranslator, you need to set your OpenAI API key. You can do this by calling the set_openai_api_key
function.
from simpleaitranslator.translator import set_openai_api_key
# Set your OpenAI API key
set_openai_api_key("YOUR_OPENAI_API_KEY")
Setting the Azure OpenAI API Key
If you are using Azure's OpenAI services, you need to set your Azure OpenAI API key along with additional required parameters. Use the set_azure_openai_api_key
function to do this.
from simpleaitranslator.translator import set_azure_openai_api_key
# Set your Azure OpenAI API key
set_azure_openai_api_key(
azure_endpoint="YOUR_AZURE_ENDPOINT",
api_key="YOUR_AZURE_API_KEY",
api_version="YOUR_API_VERSION",
azure_deployment="YOUR_AZURE_DEPLOYMENT"
)
Language Detection
To detect the language of a given text:
from simpleaitranslator.translator import get_text_language,set_openai_api_key
set_openai_api_key("YOUR_OPENAI_API_KEY")
print(get_text_language("Hello world")) # Output: 'eng'
Translation
To translate text containing multiple languages into another language:
from simpleaitranslator.translator import translate, set_openai_api_key
set_openai_api_key("YOUR_OPENAI_API_KEY")
print(translate("Cześć jak się masz? Meu nome é Adam", "eng")) # Output: "Hello how are you? My name is Adam"
Full Example
Here is a complete example demonstrating how to use the library:
from simpleaitranslator.translator import get_text_language, translate, set_openai_api_key
set_openai_api_key("YOUR_OPENAI_API_KEY")
# Detect language
print(get_text_language("jak ty się nazywasz")) # Output: 'pol'
# Translate text
print(translate("Cześć jak się masz? Meu nome é Adam", "eng")) # Output: "Hello how are you? My name is Adam"
Supported Languages
SimpleAITranslator supports all languages supported by GPT-4. For a complete list of language codes, you can visit the ISO 639-3 website.
Here are some of the most popular languages and their ISO 639-3 codes:
- English (eng)
- Spanish (spa)
- French (fra)
- German (deu)
- Chinese (zho)
- Japanese (jpn)
- Korean (kor)
- Portuguese (por)
- Russian (rus)
- Italian (ita)
- Dutch (nld)
- Arabic (ara)
- Hindi (hin)
- Bengali (ben)
- Turkish (tur)
- Polish (pol)
- Swedish (swe)
- Norwegian (nor)
- Danish (dan)
- Finnish (fin)
- Greek (ell)
- Hebrew (heb)
Additional Resources
Authors
License
SimpleAITranslator is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for simpleaitranslator-2.0.19.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63eb1001dbd349c6a3d4e7fcd82b801cc36f524809060e37b47bb2f7cbb8d05b |
|
MD5 | 083da84197d5f339e09f5436b7f16cc1 |
|
BLAKE2b-256 | c2fd267e6413b7a803bf65bd6c2d3853efda0ac527090cae4433e50fbd80b57a |
Hashes for simpleaitranslator-2.0.19-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 871504a0d0bb2c12fd5d62dea0a396e96bd1188042568d777bae7ae487d800f8 |
|
MD5 | 78451a4f2af038c5983ce63842887124 |
|
BLAKE2b-256 | d9c8ebfe683f17313c8a525cfad2b441d4bf0bff57eed13f4e1113401ac0124d |