LiteLLM powered machine translator for wagtail-localize
Project description
Wagtail Localize AI Translator
A machine translator for Wagtail Localize that uses LiteLLM for translation
Prerequisites
- Python 3.9+
- a Wagtail project with Wagtail Localize correctly configured
Dependencies
Installation
Install the package using pip:
pip install wagtail-localize-ai
In your settings.py file,
- Add
wagtail_localize_aito yourINSTALLED_APPS - Add
wagtail.contrib.settingsto yourINSTALLED_APPS(used to setup model and prompt) - Setup
WAGTAILLOCALIZE_MACHINE_TRANSLATORlike this:WAGTAILLOCALIZE_MACHINE_TRANSLATOR = { "CLASS": "wagtail_localize_ai.translator.AITranslator", }
Then, run python manage.py migrate wagtail_localize_ai to create the required database tables
Setting up providers
To set up providers add to your settings.py file a dict called AI_PROVIDERS.
Each provider is a key, the value will be a dict of kwargs that will be passed to the completion function.
You can also add a _name key to provide a verbose name of the provider.
You can find all providers and their kwargs in the litellm documentation
Here are some examples for the most popular providers:
OpenAI
AI_PROVIDERS = {
"openai": {
"_name": "OpenAI",
"api_key": "sk-...",
"base_url": "https://api.openai.com/v1", # Optional
"organization": "org-...", # Optional
}
}
Anthropic
AI_PROVIDERS = {
"anthropic": {
"_name": "Anthropic",
"api_key": "sk-...",
}
}
Azure OpenAI
AI_PROVIDERS = {
"azure": {
"_name": "Azure OpenAI",
"api_key": "sk-...",
"base_url": "https://...",
"api_version": "2023-03-15-preview", # Optional
}
}
Azure AI
AI_PROVIDERS = {
"azure_ai": {
"_name": "Azure AI",
"api_key": "sk-...",
"base_url": "https://...",
}
}
Vertex AI
AI_PROVIDERS = {
"vertex_ai": {
"_name": "Vertex AI",
"vertex_project": 'project-...',
"vertex_location": 'europe-west8',
}
}
# Load the google cloud
with open("path/to/vertex_ai_service_account.json") as f:
AI_PROVIDERS["vertex_ai"]["vertex_credentials"] = json.load(f)
Usage
You can set the provider, model and prompt from the AI Translator page reachable from the Settings menu entry.
You can also see the token usage from the Logs pagea in the Reports menu entry.
License
This project is released under the BSD license.
Contributors
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wagtail_localize_ai-0.1.3.tar.gz.
File metadata
- Download URL: wagtail_localize_ai-0.1.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
144e9dfcd8b0e8f793ea195a6b54fe40e4578cf5827fe4d90c76a262d2154cd8
|
|
| MD5 |
f264dad1022e892d05fa2b998586072e
|
|
| BLAKE2b-256 |
47dea5d8e9f6c71a1ce0a3abe211b580a52ee87d78908e1d6973080df8fa1635
|
Provenance
The following attestation bundles were made for wagtail_localize_ai-0.1.3.tar.gz:
Publisher:
python-publish.yml on infofactory/wagtail-localize-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_localize_ai-0.1.3.tar.gz -
Subject digest:
144e9dfcd8b0e8f793ea195a6b54fe40e4578cf5827fe4d90c76a262d2154cd8 - Sigstore transparency entry: 193308378
- Sigstore integration time:
-
Permalink:
infofactory/wagtail-localize-ai@fd6f814f6c79249ce3a155117a674c2814ecb4c0 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/infofactory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fd6f814f6c79249ce3a155117a674c2814ecb4c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wagtail_localize_ai-0.1.3-py3-none-any.whl.
File metadata
- Download URL: wagtail_localize_ai-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab19dfb22d876e19c60c85a9b9ac1c085377abaaf040201f88640f4459993ae8
|
|
| MD5 |
ef37232be843b0203fcdc1fe0baf9ee3
|
|
| BLAKE2b-256 |
85b8ba97d0d8f4aca1f808784a1e2038b9f30593a7ec3a0ed7bf1e968dea2134
|
Provenance
The following attestation bundles were made for wagtail_localize_ai-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yml on infofactory/wagtail-localize-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wagtail_localize_ai-0.1.3-py3-none-any.whl -
Subject digest:
ab19dfb22d876e19c60c85a9b9ac1c085377abaaf040201f88640f4459993ae8 - Sigstore transparency entry: 193308380
- Sigstore integration time:
-
Permalink:
infofactory/wagtail-localize-ai@fd6f814f6c79249ce3a155117a674c2814ecb4c0 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/infofactory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fd6f814f6c79249ce3a155117a674c2814ecb4c0 -
Trigger Event:
release
-
Statement type: