Skip to main content

Translate via aurora and variants, openai, azure openai, etc.

Project description

aurora-tr

pytestpythonCode style: blackLicense: MITPyPI version

Translate via aurora and variants, openai, azure openai, etc.

gpt-translation: Free Lunch

(as long as the freegpt.art service is up)

pip install aurora-tr --pre

python code

from aurora_tr import aurora_tr

res = aurora_tr(
  "test me",
  base_url = "https://api.freegpt.art/v1",
  api_key = "sk-ZRGxqeGOAugc32bKA1529c37D92443E2A27a54De3eE87fCc",
  mode="gpt-3.5-turbo",
)
print(res)
# output: {'translation': '测试我', 'notes': ''}

Quick Setup

From command line

pip install aurora-tr --pre
docker run -d --name aurora -p 8080:8080 ghcr.io/aurora-develop/aurora:latest

python code

from aurora_tr import aurora_tr

res = aurora_tr("test me", base_url="http:/127.0.0.1:8080/v1")
print(res)
# output:  {'translation': '测试我', 'notes': ''}

Detailed Instructions

Install

pip install aurora-tr --pre

Use

url for aurora REST API

First off, acquire a url (OPENAI_BASE_URL in python-openai) for the aurora REST API for aurora-tr to use, for example, search the net, beg your friends, or deploy your own aurora, etc.

N.B.: aurora is a service in the wild similar or compatible to openai (more commonly known as chatgpt).

To deplay your own aurora locolly or on a remote machine, refer to https://github.com/aurora-develop/aurora

For example (the easieast way if you can access docker):

docker run -d --name aurora -p 8080:8080 ghcr.io/aurora-develop/aurora:latest

The OPENAI_BASE_URL in this case will be http://localhost:8080/v1 or http://external_ip_or_domainname:8080/v1

python code

Default base_url, api_key and model of aurora_tr take the value of OPENAI_BASE_URL, OPENAI_API_KEY and OPENAI_MODEL from the file .env-aurora.

base_url, api_key and model can also be set directly in aurora_tr, e.g.,

res = aurora_tr(
  '....',
  url_base="https://uu.ci/v1",
  api_key=...,
  model-"gpt-4-turbo-preview",
  selector="uuci"
)

Hence, if you have deployed your own aurora API:

from aurora_tr import aurora_tr

res = aurora_tr("test me", url="http:/127.0.0.1:8080/v1")
print(res)
# output:  {'translation': '测试我', 'notes': ''}

Other examples:

from aurora_tr import aurora_tr

# default aurora, source language: English, target language: Chinese
res = aurora_tr("Test me.")
print(res)
{'translation': '测试我。', 'notes': 'Translated from English to Chinese.'}
# target language: English
res = aurora_tr("试试我", to_lang="English")
{'translation': 'Try me', 'notes': ''}
# select aurora
res = aurora_tr("Testen mich bitte")
 {'translation': '请测试我', 'notes': 'Translated from English to Chinese'}
# select uuci
import dotenv

api_key = dotenv.dotenv_values(".env").get("OPENAI_API_KEY_UUCI")
# or api_key = "......"
res = aurora_tr("Test me.", selector="uuci", api_key=api_key)
{'translation': '测试我。'}

Brief docs

aurora_tr(
    text: str,
    from_lang: Optional[str] = 'English',
    to_lang: str = 'Chinese',
    selector: str = 'aurora',
    base_url: str = '',
    api_key: str = '',
    model: str = '',
    temperature: Optional[float] = None,
)
Docstring:
Translate viaa auroa and uu.ci.

Args
----
text: string to transalte
from_lang: source language
to_lang: target language
selector: prodiver selector
base_url:
api_key: token
model: model name, anything for aurora
temperature (str): 0.2-0.4 for translation, might just left out

Returns
-------
dict/json: {"translation": "...", notes: "..."}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aurora_tr-0.1.2a0-py3-none-any.whl (5.6 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