Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A Python library for language detection and translation using OpenAI's GPT-4o.
SimpleAITranslator is a Python library designed to identify the language of a given text and translate text between multiple languages using OpenAI's GPT-4o. The library is especially useful for translating text containing multiple languages into a single target language.
To use this library, you must have an OpenAI API key. This key allows the library to utilize OpenAI's GPT-4o for translation and language detection.
You can install the SimpleAITranslator library from PyPI:
pip install simpleaitranslator
Before using SimpleAITranslator with OpenAI, you need to set your OpenAI API key. You can do this by creating an instance of the TranslatorOpenAI class.
from simpleaitranslator.translator import TranslatorOpenAI
# Set your OpenAI API key
translator = TranslatorOpenAI(open_ai_api_key="YOUR_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 TranslatorAzureOpenAI class for this.
from simpleaitranslator.translator import TranslatorAzureOpenAI
# Set your Azure OpenAI API key and related parameters
translator = TranslatorAzureOpenAI(
azure_endpoint="YOUR_AZURE_ENDPOINT",
api_key="YOUR_AZURE_API_KEY",
api_version="YOUR_API_VERSION",
azure_deployment="YOUR_AZURE_DEPLOYMENT"
)
To detect the language of a given text:
from simpleaitranslator.translator import TranslatorOpenAI
# Set your OpenAI API key
translator = TranslatorOpenAI(open_ai_api_key="YOUR_OPENAI_API_KEY")
# Detect language
detected_language = translator.get_text_language("Hello world")
print(detected_language.language_ISO_639_1_code) # Output: 'en'
print(detected_language.language_name) # Output: 'English'
To translate text containing multiple languages into another language:
from simpleaitranslator.translator import TranslatorOpenAI
# Set your OpenAI API key
translator = TranslatorOpenAI(open_ai_api_key="YOUR_OPENAI_API_KEY")
# Translate text
translated_text = translator.translate("Cześć jak się masz? Meu nome é Adam", "en")
print(translated_text) # Output: "Hello how are you? My name is Adam"
Here is a complete example demonstrating how to use the library:
from simpleaitranslator.translator import TranslatorOpenAI
# Initialize the translator with your OpenAI API key
translator = TranslatorOpenAI(open_ai_api_key="YOUR_OPENAI_API_KEY")
# Detect language
detected_language = translator.get_text_language("jak ty się nazywasz")
print(detected_language.language_ISO_639_1_code) # Output: 'pl'
print(detected_language.language_name) # Output 'Polish'
# Translate text
translated_text = translator.translate("Cześć jak się masz? Meu nome é Adam", "en")
print(translated_text) # Output: "Hello how are you? My name is Adam"
SimpleAITranslator supports all languages supported by GPT-4o. For a complete list of language codes, you can visit the ISO 639-1 website.
Here are some of the most popular languages and their ISO 639-1 codes:
en
es
fr
de
zh
ja
ko
pt
ru
it
nl
ar
hi
bn
tr
pl
sv
no
da
fi
el
he
SimpleAITranslator is licensed under the MIT License. See the LICENSE file for more details.
FAQs
A Python library for language detection and translation using OpenAI's GPT-4o.
We found that ai-translator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.