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.1.tar.gz (9.2 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.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wagtail_localize_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 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.1.tar.gz
Algorithm Hash digest
SHA256 adfc481d1b5a97cca4ddaa2af74c7b0d7777d1803e9452ead432ee0de852805f
MD5 baaf77fb761cbaf68a09bf431cfee7c0
BLAKE2b-256 58394e9b7e7f3dd1e788c7f10124554b4a5f64d39a3956af149902ad8e7044d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for wagtail_localize_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb2ba5000efbc876feb3aa9ac260e90b3a2eb86721bdcd01a7a31315041ff242
MD5 26bf6967505f4401888258805b1d8d2d
BLAKE2b-256 446f8aac1067ad273d8fd94756664b50ac81bd9163c92b8662abd322ccc61d41

See more details on using hashes here.

Provenance

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