Skip to main content

Translate markdown files using OpenAI ChatGPT, and generate localized copies of each file.

Project description

mdGPT - Mark Down General Purpose Transformer

Translate markdown files using OpenAI ChatGPT, and generate localized copies of each file.

Installation

Using pip

pip install mdgpt

Set environment variable OPENAI_API_KEY or create it in a .env file

export OPENAI_API_KEY=YOUR_API_KEY

Download example prompts:

curl -o prompts.yaml https://raw.githubusercontent.com/Djarnis/mdGPT/main/prompts.yaml

Use the example WEBSITE_BUILDER option from the prompts to build some example files;

mdbuild -d example -p prompts -l en

To translate the markdown files into Finish (fi) versions, run this command:

mdtranslate -p prompts -d example -sl en -tl fi

Adjust the prompts to suit your needs.

MODEL

You can change the MODEL to any engine supported by OpenAI, change the default temperature, and adjust max tokens.

WEBSITE_BUILDER

...

URL_PROMPT

...

MARKDOWN_PROMPT

...

ONLY_INDEXES

Optional boolean value, if you only want index.md files translated.

FIELD_KEYS

Optional list of frontmatter keys you want to tranlate.

...


Using repo source and Poetry:

Step 1: Install Poetry

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

On Unix-based systems like Linux and MacOS, you can install Poetry by using the following command in your terminal:

curl -sSL https://install.python-poetry.org | python -

On Windows, you can use PowerShell to install Poetry with the following command:

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

You can check if Poetry was installed correctly by running:

poetry --version

Step 2: Rename .env.tpl to .env

In your project directory, you have a file named .env.tpl which serves as a template for environment variables. To use this file, you should rename it to .env.

On Unix-based systems, use the following command:

mv .env.tpl .env

On Windows, use the following command:

rename .env.tpl .env

Step 3: Add OPENAI_API_KEY value to .env

Open your .env file in a text editor. You should see a line that looks something like this:

OPENAI_API_KEY=

After the equal sign, add your OpenAI API key in quotes. It should look something like this:

OPENAI_API_KEY="your-api-key-goes-here"

Save the .env file and close it.

Please note:

  • Make sure to replace "your-api-key-goes-here" with your actual OpenAI API key.
  • Do not share your .env file or post it online, as it contains sensitive information.

Step 4: Install mdGPT

From the project directory, install mdGPT and its dependencies:

poetry install

This installs mdGPT and all its dependencies, and you can now follow the example below.

Example

Build Markdown files

The example website (./example/en) was created using the WEBSITE_BUILDER option included in the prompts.yaml file.

poetry run mdbuild -d example -p prompts -l en

Which will create these files in the ./example/en directory:

  • index.md
  • about.md
  • contact.md
  • history.md

Translate website

To translate the markdown files into Finish (fi) versions, run this command:

poetry run mdtranslate -p prompts -d example -sl en -tl fi

And you should get a /fi subdirectory ./example/fi/ containing these files, translated from their original English (en) source:

  • index.md
  • tietoja.md
  • yhteystiedot.md
  • historia.md

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

mdgpt-0.1.2.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

mdgpt-0.1.2-py3-none-any.whl (9.3 kB view hashes)

Uploaded Python 3

Supported by

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