> For the complete documentation index, see [llms.txt](https://docs.vntranslator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vntranslator.com/advanced/custom-mt/mt-kit.md).

# MT Kit

## Custom MT in VNTranslator

```json
{
    "configVersion": 3,
    "name": "mtkit",  
    "title": "mtkit",        
    "description": "",
    "schema": [],           
    "lang": {
        "source": [
            { "name": "Arabic", "value": "Arabic" },
            { "name": "Bulgarian", "value": "Bulgarian" },
            { "name": "Chinese", "value": "Chinese" },
            { "name": "Czech", "value": "Czech" },
            { "name": "Danish", "value": "Danish" },
            { "name": "German", "value": "German" },
            { "name": "Greek", "value": "Greek" },
            { "name": "English", "value": "English" },
            { "name": "Spanish", "value": "Spanish" },
            { "name": "Estonian", "value": "Estonian" },
            { "name": "Finnish", "value": "Finnish" },
            { "name": "French", "value": "French" },
            { "name": "Hungarian", "value": "Hungarian" },
            { "name": "Indonesian", "value": "Indonesian" },
            { "name": "Italian", "value": "Italian" },
            { "name": "Japanese", "value": "Japanese" },
            { "name": "Korean", "value": "Korean" },
            { "name": "Lithuanian", "value": "Lithuanian" },
            { "name": "Latvian", "value": "Latvian" },
            { "name": "Norwegian", "value": "Norwegian" },
            { "name": "Dutch", "value": "Dutch" },
            { "name": "Polish", "value": "Polish" },
            { "name": "Portuguese", "value": "Portuguese" },
            { "name": "Romanian", "value": "Romanian" },
            { "name": "Russian", "value": "Russian" },
            { "name": "Slovak", "value": "Slovak" },
            { "name": "Slovenian", "value": "Slovenian" },
            { "name": "Swedish", "value": "Swedish" },
            { "name": "Thai", "value": "Thai" },
            { "name": "Turkish", "value": "Turkish" },
            { "name": "Ukrainian", "value": "Ukrainian" }
	    ],
        "target": [
            { "name": "Arabic", "value": "Arabic" },
            { "name": "Bulgarian", "value": "Bulgarian" },
            { "name": "Chinese", "value": "Chinese" },
            { "name": "Czech", "value": "Czech" },
            { "name": "Danish", "value": "Danish" },
            { "name": "German", "value": "German" },
            { "name": "Greek", "value": "Greek" },
            { "name": "English", "value": "English" },
            { "name": "Spanish", "value": "Spanish" },
            { "name": "Estonian", "value": "Estonian" },
            { "name": "Finnish", "value": "Finnish" },
            { "name": "French", "value": "French" },
            { "name": "Hungarian", "value": "Hungarian" },
            { "name": "Indonesian", "value": "Indonesian" },
            { "name": "Italian", "value": "Italian" },
            { "name": "Japanese", "value": "Japanese" },
            { "name": "Korean", "value": "Korean" },
            { "name": "Lithuanian", "value": "Lithuanian" },
            { "name": "Latvian", "value": "Latvian" },
            { "name": "Norwegian", "value": "Norwegian" },
            { "name": "Dutch", "value": "Dutch" },
            { "name": "Polish", "value": "Polish" },
            { "name": "Portuguese", "value": "Portuguese" },
            { "name": "Romanian", "value": "Romanian" },
            { "name": "Russian", "value": "Russian" },
            { "name": "Slovak", "value": "Slovak" },
            { "name": "Slovenian", "value": "Slovenian" },
            { "name": "Swedish", "value": "Swedish" },
            { "name": "Thai", "value": "Thai" },
            { "name": "Turkish", "value": "Turkish" },
            { "name": "Ukrainian", "value": "Ukrainian" }
	    ]
    },
    "request": {
        "method": "web_scraping",
        "encodeURI": false,
        "encodeURIComponent": true,       
        "initialUrl": "http://127.0.0.1:5454/translate",   
        "url": "http://127.0.0.1:5454/translate?sl=$SOURCE_LANG&tl=$TARGET_LANG&text=$SOURCE_TEXT",        
        "querySelector": "body",                
        "querySelectorAll": null,
        "queryProperty": "innerText"
    }
}
```

## Python Script

{% hint style="info" %}
You will need python >= 3.10
{% endhint %}

```python
# VNTranslator - Custom MT Kit

from flask import Flask, request
import json
import requests
import urllib.parse

APP_DEBUG = True
APP_HOST = "127.0.0.1"
APP_PORT = 5454

OPENAI_API_URL = "https://api.openai.com/v1/chat/completions"
OPENAI_API_KEY = "YOUR_API_KEY"
OPENAI_MODEL = "gpt-4o-mini"
OPENAI_PROMPT = "You are a professional translator specializing in {SOURCE_LANG} to {TARGET_LANG} translation for Visual Novels. \
You will be provided with text, please translate it and provide the best translation: {SOURCE_TEXT}"

app = Flask(__name__)
@app.route('/translate', methods=['GET'])
def translate():

    print("===== New Request =====")
    print(f"{request.method} {request.path}")
    
    source_text = request.args.get("text", "")
    source_lang = request.args.get("sl", "Japanese")
    target_lang = request.args.get("tl", "English") 

    if not source_text:
        print(f"Err: Missing text!")
        return  f"Err: Missing text!", 400

    # Decode text & format prompt
    source_text = urllib.parse.unquote(source_text)
    prompt = OPENAI_PROMPT.format(SOURCE_LANG=source_lang, TARGET_LANG=target_lang, SOURCE_TEXT=source_text).strip()
    print(json.dumps({'source_lang': source_lang, 'target_lang': target_lang, 'text': source_text}, ensure_ascii=False, indent=4))
    print(f"Prompt: {prompt}")

    # Set header
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {OPENAI_API_KEY}",
    } 
    # Set data
    data = {
        "model": OPENAI_MODEL,
        "messages": [
            {"role": "system", "content": prompt},
            {"role": "user", "content": source_text},
        ],
        "temperature": 0.7,
    }

    # Send request
    try:
        response = requests.post(OPENAI_API_URL, headers=headers, json=data)
        response.raise_for_status()
    except requests.exceptions.RequestException as e:
        print(f"Err: Failed to request: {e}")
        return f"Err: Failed to request: {e}", 500

    # Extract response
    try:
        response_data = response.json()
        translation = response_data["choices"][0]["message"]["content"]
    except (KeyError, IndexError) as e:
        print(f"Err: Invalid response: {e}")
        return f"Err: Invalid response: {e}", 500
    
    # Return response
    print(f"Response: {translation}\n")
    return translation, response.status_code

if __name__ == '__main__':
    app.run(debug=APP_DEBUG, host=APP_HOST, port=APP_PORT)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.vntranslator.com/advanced/custom-mt/mt-kit.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
