Skip to main content

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_ai to your INSTALLED_APPS
  • Add wagtail.contrib.settings to your INSTALLED_APPS (used to setup model and prompt)
  • Setup WAGTAILLOCALIZE_MACHINE_TRANSLATOR like 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

wagtail_localize_ai-0.2.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_localize_ai-0.2.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_localize_ai-0.2.0.tar.gz.

File metadata

  • Download URL: wagtail_localize_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wagtail_localize_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0230463209ee7582746bdc6e2935f2c7ab06cf1bab9cd7a4454e2b456deb7e1d
MD5 f678d279b964ee54e0fdea49242cbb87
BLAKE2b-256 0da803630adaa747da3114cc4c09f2a5b101c26689216dd1d712e2bc0b736ba5

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_localize_ai-0.2.0.tar.gz:

Publisher: python-publish.yml on infofactory/wagtail-localize-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wagtail_localize_ai-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_localize_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e66212dfdc3287e3e5c602a12190a8f31053fcc3208c3a87fedacef4c3a43bc3
MD5 c03c56b19d52c4be2d8238429588a591
BLAKE2b-256 eb1989d801210691582e759d28202d92e22b0de6473f978c31e6b1110a92a4c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_localize_ai-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on infofactory/wagtail-localize-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page