Skip to content

Commit

Permalink
调整配置文件更友好,调整字典配置,略微调高GPT的temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
xd2333 committed Jun 3, 2023
1 parent a880460 commit 747314e
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 67 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions GalTransl/Backend/GPT3Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ def __init__(self, config: CProjectConfig, type):

if type == "offapi":
from revChatGPT.V3 import Chatbot as ChatbotV3
rand_token=randSelectInList(self.tokens)
rand_token = randSelectInList(self.tokens)
os.environ["API_URL"] = rand_token.domain

self.chatbot = ChatbotV3(
api_key=rand_token.token,
proxy=randSelectInList(self.proxies)["addr"] if self.proxies else None,
max_tokens=4096,
temperature=0.328, # 氪个328
temperature=0.5,
system_prompt=SYSTEM_PROMPT,
)
elif type == "unoffapi":
from revChatGPT.V1 import Chatbot as ChatbotV1

gpt_config = {
"access_token": config.getBackendConfigSection("ChatGPT")["ak"],
"access_token": randSelectInList(config.getBackendConfigSection("ChatGPT")["access_tokens"])["access_token"],
"proxy": randSelectInList(self.proxies)["addr"]
if self.proxies
else None,
Expand Down
4 changes: 2 additions & 2 deletions GalTransl/Backend/GPT4Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, config: CProjectConfig, type):
api_key=randSelectInList(self.tokens).token,
proxy=randSelectInList(self.proxies)["addr"] if self.proxies else None,
max_tokens=8192,
temperature=0.328,
temperature=0.5,
frequency_penalty=0.2,
system_prompt="You are a helpful assistant.",
engine="gpt-4",
Expand All @@ -123,7 +123,7 @@ def __init__(self, config: CProjectConfig, type):
gpt_config = {
"model": "gpt-4",
"paid": True,
"access_token": config.getBackendConfigSection("ChatGPT")["ak"],
"access_token": randSelectInList(config.getBackendConfigSection("ChatGPT")["access_tokens"])["access_token"],
"proxy": randSelectInList(self.proxies) if self.proxies else None,
}

Expand Down
12 changes: 8 additions & 4 deletions GalTransl/ConfigHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, projectPath: str) -> None:
self.keyValues = dict()
for k,v in self.projectConfig["common"].items():
self.keyValues[k] = v
pass
self.keyValues["enableProxy"] = self.projectConfig["proxy"]["enableProxy"]
LOGGER.info(
"inputPath: %s, outputPath: %s, cachePath: %s,keyValues: %s",
self.inputPath,
Expand Down Expand Up @@ -79,7 +79,7 @@ def getCommonConfigSection(self) -> dict:
return self.projectConfig["common"]

def getProxyConfigSection(self) -> dict:
return self.projectConfig["proxies"]
return self.projectConfig["proxy"]["proxies"]

def getBackendConfigSection(self, backendName: str) -> dict:
"""
Expand Down Expand Up @@ -205,13 +205,17 @@ def initProxyList(config: CProjectConfig) -> Optional[list[dict]]:
return result


def initDictList(config: dict, projectDir: str) -> Optional[list[str]]:
def initDictList(config: dict, dictDir: str, projectDir: str) -> Optional[list[str]]:
"""
处理字典设置项
"""
result: list[str] = []
for entry in config:
result.append(str(path.abspath(projectDir) + sep + entry))
if entry.startswith("(project_dir)"):
entry = entry.replace("(project_dir)", "")
result.append(str(path.abspath(projectDir) + sep + entry))
else:
result.append(str(path.abspath(dictDir) + sep + entry))
return result


Expand Down
9 changes: 9 additions & 0 deletions GalTransl/Frontend/GPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@ def doGPT3Translate(
pre_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["preDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
post_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["postDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
gpt_dic = CGptDict(
initDictList(
projectConfig.getDictCfgSection()["gpt.dict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
Expand All @@ -126,18 +129,21 @@ def doGPT4Translate(
pre_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["preDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
post_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["postDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
gpt_dic = CGptDict(
initDictList(
projectConfig.getDictCfgSection()["gpt.dict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
Expand Down Expand Up @@ -217,18 +223,21 @@ def doNewBingTranslate(projectConfig: CProjectConfig, multiThreading=False) -> b
pre_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["preDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
post_dic = CNormalDic(
initDictList(
projectConfig.getDictCfgSection()["postDict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
gpt_dic = CGptDict(
initDictList(
projectConfig.getDictCfgSection()["gpt.dict"],
projectConfig.getDictCfgSection()["default_dictionary_folder"],
projectConfig.getProjectDir(),
)
)
Expand Down
21 changes: 12 additions & 9 deletions GalTransl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
\____|\__,_|_| |_||_| \__,_|_| |_|___/_|
"""

CONFIG_FILENAME = "config.yaml"
CORE_VERSION = "2.0.0"
AUTHOR = "cx2333"
CONTRIBUTORS = "ryank231231"

CONFIG_FILENAME = "config.yaml"
INPUT_FOLDERNAME = "json_jp"
OUTPUT_FOLDERNAME = "json_cn"
CACHE_FOLDERNAME = "transl_cache"
TRANSLATOR_SUPPORTED = [
"gpt35",
"chatgpt-gpt35",
"gpt4",
"chatgpt-gpt4",
"newbing",
"caiyun",
]
TRANSLATOR_SUPPORTED = {
"gpt35": "GPT3.5 官方API",
"chatgpt-gpt35": "GPT3.5 模拟网页操作模式",
"gpt4": "GPT4 官方API",
"chatgpt-gpt4": "GPT4 模拟网页操作模式",
"newbing": "NewBing大小姐",
"caiyun": "彩云 -- 暂不可用",
}
9 changes: 5 additions & 4 deletions GalTransl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
from GalTransl.ConfigHelper import CProjectConfig
from GalTransl.Runner import run_galtransl
from GalTransl import PROGRAM_SPLASH, TRANSLATOR_SUPPORTED
from GalTransl import PROGRAM_SPLASH, TRANSLATOR_SUPPORTED, CORE_VERSION, AUTHOR, CONTRIBUTORS


def main() -> int:
Expand All @@ -10,15 +10,16 @@ def main() -> int:
parser.add_argument(
"--translator",
"-t",
choices=TRANSLATOR_SUPPORTED,
choices=TRANSLATOR_SUPPORTED.keys(),
help="choose which Translator to use",
required=True,
)
args = parser.parse_args()

print(PROGRAM_SPLASH)
print("GalTransl Core version: 1.0.1 [2023.05.23]")
print("Author: cx2333")
print(f"GalTransl Core version: {CORE_VERSION}")
print(f"Author: {AUTHOR}")
print(f"Contributors: {CONTRIBUTORS}")

cfg = CProjectConfig(args.project_dir)

Expand Down
2 changes: 2 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python run_GalTransl.py
pause
17 changes: 9 additions & 8 deletions run_GalTransl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
from GalTransl.ConfigHelper import CProjectConfig
from GalTransl.Runner import run_galtransl
from GalTransl import LOGGER, PROGRAM_SPLASH, CONFIG_FILENAME,TRANSLATOR_SUPPORTED
from GalTransl import PROGRAM_SPLASH, CONFIG_FILENAME,TRANSLATOR_SUPPORTED, CORE_VERSION, AUTHOR, CONTRIBUTORS

print(PROGRAM_SPLASH)
print(f"GalTransl Core version: {CORE_VERSION}")
print(f"Author: {AUTHOR}")
print(f"Contributors: {CONTRIBUTORS}\n")

project_dir = input("请输入项目文件夹路径,或拖入项目文件夹:")
while not os.path.exists(os.path.join(project_dir, CONFIG_FILENAME)):
Expand All @@ -12,15 +15,13 @@

print()
print("可选翻译器:")
for translator in TRANSLATOR_SUPPORTED:
print(f" {translator}")
for translator,intro in TRANSLATOR_SUPPORTED.items():
print(f" {translator}\t({intro})")

translator = input("请输入翻译器:")
while translator not in TRANSLATOR_SUPPORTED:
translator = input("请输入要使用的翻译器:")
while translator not in TRANSLATOR_SUPPORTED.keys():
print(f"翻译器{translator}不在支持列表,请重新输入\n")
translator = input("请输入翻译器:")
translator = input("请输入要使用的翻译器:")

cfg = CProjectConfig(project_dir)


run_galtransl(cfg, translator)
71 changes: 34 additions & 37 deletions sampleProject/config.inc.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
---
# 通用(杂项)设置
common:
# 日志等级,可选 ["debug", "info", "warning", "error"]
loggingLevel: debug
# 是否启用代理
enableProxy: false
retryFail: true # True/False,每次启动时重翻所有翻译失败的句子(目前仅NewBing会翻译失败)
multiThread: true # 多线程
# 是否将 GPT4 的令牌用于 GPT3.5 的请求
gpt.degradeBackend: false
# API类型,offapi为官方API,unoffapi为模拟网页操作
gpt.apiType: offical
gpt.lineBreaksImprovementMode: false # true/false,换行符改善模式,减少丢换行符情况,但可能导致循环重试
gpt.restoreContextMode: true # true/false,重启自动恢复上下文
loggingLevel: debug # 日志等级,可选 ["debug", "info", "warning", "error"]
gpt.numPerRequestTranslate: 9 # 单次翻译句子数量,不建议太大
gpt.numPerRequestProofRead: 7 # 不建议修改
gpt.enableProofRead: false # 是否开启译后校润(True/False)
gpt.numPerRequestProofRead: 7 # 单次校润句子数量,不建议修改
retryFail: true # (True/False)每次启动时重翻所有翻译失败的句子(目前仅NewBing会翻译失败)
multiThread: false # (True/False)多线程(暂不可用)
gpt.degradeBackend: false # 是否将 GPT4 的key用于 GPT3.5 的请求
gpt.lineBreaksImprovementMode: false # (True/False)换行符改善模式,减少丢换行符情况,但可能导致循环重试
gpt.restoreContextMode: true # (True/False)重启自动恢复上下文
gpt.enableProofRead: false # (True/False)是否开启译后校润,仅NewBing,GPT4支持
# 代理设置
proxies:
# 代理地址
- address: socks5://127.0.0.1:10818
# 用户名(可选)
# username: foo
# 密码(可选)
# password: bar
proxy:
# 是否启用代理
enableProxy: false
proxies:
- address: socks5://127.0.0.1:10818
# username: foo
# password: bar
# 字典
dictionary:
# 通用预处理字典
dictionary_folder: D:\\GalTransl-main\\Dict #通用字典文件夹
# 预处理字典
preDict:
- foo
- bar
# 通用后处理字典
postDict:
- foo
- bar
- 00通用字典_译前.txt
- 01H字典_矫正_译前.txt # 用于口齿不清的矫正
- (project_dir)\\项目字典_译前.txt # (project_dir)\\ 代表字典在项目文件夹
# GPT 字典
gpt.dict:
- foo
- bar
- GPT字典.txt
- (project_dir)\\项目GPT字典.txt
# 后处理字典
postDict:
- 00通用字典_符号_译后.txt # 符号矫正
- 00通用字典_译后.txt
- (project_dir)\\项目字典_译后.txt
# 与翻译后端所特定的设置
backendSpecific:
GPT35: # GPT3.5 官方 API
Expand All @@ -46,26 +43,26 @@ backendSpecific:
endpoint: https://api.openai.com # OPENAI API请求的域名,使用转发或第三方API时修改
- token: sk-yyyyyyyy
endpoint: ""
defaultEndpoint: https://api.openai.com # 默认 API 端点,不知道别修改
defaultEndpoint: https://api.openai.com # 默认 API 端点,一般不修改
GPT4: # GPT4 官方 API
tokens:
- token: sk-xxxxxxxx
endpoint: ""
- token: sk-yyyyyyyy
endpoint: ""
defaultEndpoint: https://api.openai.com
ChatGPT: # ChatGPT / GPT3.5(4) 非官方 API
ak:
- foo
- bar
account:
ChatGPT: # ChatGPT / GPT3.5(4) 非官方 API,模拟网页操作
access_tokens:
- access_token: xxx
accounts:
- username: foo
password: bar
- username: bar
password: foo
bingGPT4:
cookiePath:
- foobar/cookies.json # 你的 cookies 文件
- newbing_cookies/cookie1.json # 你的 cookies 文件
- newbing_cookies/cookie2.json # 你的 cookies 文件
# 问题分析机制配置
problemAnalyze:
GPT35: # GPT35 / ChatGPT
Expand Down

0 comments on commit 747314e

Please sign in to comment.