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.1.2.tar.gz (9.4 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.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wagtail_localize_ai-0.1.2.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

Hashes for wagtail_localize_ai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ad75c93b3df91215be052ad037b32437104bcd00663f6b13c9f40aaebaa489b9
MD5 8e6a1a7f366cccb7106be45e1ab6ea23
BLAKE2b-256 b2cd7cdf9851a50a2fa771b7b3259d550ef26d652f5e283dff201bbb0a265e85

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_localize_ai-0.1.2.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.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_localize_ai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 37a61303a79bd59d5bad216a8dc9bcc806a0c736be1066e1836247b5237c79ff
MD5 8d72b7179dd5f206007a7df331fabf0b
BLAKE2b-256 0e9a2b9ec744547bb512288e32f59c9db7c461cda221347a62eca082a2343bfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_localize_ai-0.1.2-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