From c79ebef46066cd6d4a76eb3885ba9ae61ec34f13 Mon Sep 17 00:00:00 2001 From: Dazed Date: Thu, 6 Apr 2023 07:38:38 -0500 Subject: [PATCH] refactor: move prompt to env --- .env.example | 6 +++++- main.py | 16 +++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index c7de0c7..45c16e8 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,7 @@ key="" -openai.organization='' +organization='' +system="\n\n###\n\n You are a professional Japanese visual novel translator, editor, and localizer.\ +You always manages to carry all of the little nuances of the original Japanese text to your output,\ +while still making it a prose masterpiece, and localizing it in a way that an average American would\ +understand.\ diff --git a/main.py b/main.py index 3eda02e..f5cadc3 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ import openai load_dotenv() openai.organization = os.getenv('org') openai.api_key = os.getenv('key') +SYSTEM = os.getenv('system') THREADS = 20 COST = .002 # Depends on the model https://openai.com/pricing @@ -82,13 +83,12 @@ def parseMap(data, filename): for page in event['pages']: totalLines += len(page['list']) - with tqdm(total = totalLines, leave=False, desc=filename, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}', position=0, delay=10) as pbar: + with tqdm(total = totalLines, leave=False, desc=filename, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}', position=0) as pbar: for event in events: if event is not None: with ThreadPoolExecutor(max_workers=THREADS) as executor: for page in event['pages']: future = executor.submit(searchCodes, page, pbar) - pbar.close() # Verify if an exception was thrown try: @@ -171,17 +171,7 @@ def translateGPT(t, history): """Translate text using GPT""" - system = "Context: " + history + "\n\n###\n\n You are a professional Japanese visual novel translator,\ -editor, and localizer. You always manages to carry all of the little nuances of the original Japanese text to your output,\ -while still making it a prose masterpiece, and localizing it in a way that an average American would understand.\ -The 'Context' at the top is previously translated text for the work.\ -You translate Onomatopoeia literally.\ -When I give you something to translate, answer with just the translation.\ -Translation Examples:\ -\\n<ルイ>そう、私はルイよ。= \\n Yes, I'm Rui.\ -\\nそう、私はルイよ。= \\nYes, I'm Rui.\ -\\n<瑠唯>イヤァァァ\"ァ\"ァ\"ァ\"ァ\"っ!!? = \\n Iyaaaaaaa\!!?\ -\\nイグぅぅぅぅぅぅぅゥゥゥゥゥゥっ!!!♡♡♡ = \\nIguuuuuuuuuuuuu!!!♡♡♡" + system = "Context: " + history + system response = openai.ChatCompletion.create( temperature=0, model="gpt-3.5-turbo",