From 0d7f847dc88cda840038a8bb6a6cf8cadeddabef Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 26 Feb 2024 00:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Gemini=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- data/config.example.ini | 30 +++++++++++++++++------------- services/translate.py | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/config.py b/config.py index f937461..94f0c3a 100644 --- a/config.py +++ b/config.py @@ -164,7 +164,7 @@ class AppConfig: translator_config['proxy'] = section['proxy'] translator_config['api_key'] = section['api_key'] translator_config['model_code'] = section['model_code'] - translator_config['prompt'] = section['prompt'] + translator_config['prompt'] = section['prompt'].replace('\n', ' ').replace('\\n', '\n') translator_config['temperature'] = section.getfloat('temperature') else: raise ValueError(f'Invalid translator type: {type_}') diff --git a/data/config.example.ini b/data/config.example.ini index 4c74b4e..2f1f3ec 100644 --- a/data/config.example.ini +++ b/data/config.example.ini @@ -170,19 +170,23 @@ api_key = # 模型代码 model_code = models/gemini-1.0-pro # 提示词 -prompt = As an advanced translation software, your role is to provide accurate translations - that respect the original content's meaning and tone. If the input text includes brackets, - ensure that these are retained in the translation. Aim to deliver the translated text in a - polite and gentle tone, as per the preferences of the audience.\n\nBelow are some examples - to guide you:\n\nExamples:\nInput1:\n来拉(莱拉) 设置一下吧\nOutput1:\nライラちゃん、設定してみましょうか。 - \n\nInput2:\n我来拉一下各位进队伍\nOutput2:\n皆さんをチームに入れさせていただきます。\n\nInput3:\n死了w\n - Output3:\n死んじゃったわw\n\nInput4:\n每天来宝这里打个卡\nOutput4:\n毎日、ここに来て宝さんにチェックインしま - \n\n\nPlease keep in mind that accurate translation is not just about linguistic conversion; - it is about conveying the same sentiment and meaning as the original input. Pay special - attention to internet vernaculars and colloquial expressions to maintain the nuances of the - source language.\n\nNow, proceed with the translation of the following Chinese comment text - into Japanese, ensuring accuracy and preservation of the original message:\nInput:\n - {{original_text}}\nOutput ONLY:\n +prompt = As an advanced translation software, your role is to provide accurate translations that respect + the original content's meaning and tone. + Ensure that texts between brackets "[]" are kept untranslated. + Aim to deliver the translated text in a polite and gentle tone, as per the preferences of the audience.\n\n + Below are some examples to guide you:\n\n + Input1:\n来拉(莱拉)设置一下吧\nOutput1:\nライラちゃん、設定してみましょうか\n\n + Input2:\n我来拉一下各位进队伍\nOutput2:\n皆さんをチームに入れさせていただきます\n\n + Input3:\n死了w\nOutput3:\n死んじゃったわw\n\n + Input4:\n每天来宝这里打个卡[比心]\nOutput4:\n毎日、ここに来て宝さんにチェックインしま[比心]\n\n + \n + Please keep in mind that accurate translation is not just about linguistic conversion; + it is about conveying the same sentiment and meaning as the original input. + Pay special attention to internet vernaculars and colloquial expressions to maintain the nuances of the + source language.\n\n + Now, proceed with the translation of the following Chinese comment text into Japanese, ensuring accuracy + and preservation of the original message:\n + Input:\n{{original_text}}\nOutput ONLY:\n # 温度,用于控制令牌选择的随机性,较低的温度适合需要更具确定性或不够开放的回答的提示,而较高的温度可以产生更加多样化或更具创意的结果 temperature = 0.4 diff --git a/services/translate.py b/services/translate.py index 044d936..6c09ec4 100644 --- a/services/translate.py +++ b/services/translate.py @@ -688,7 +688,7 @@ class GeminiTranslate(TranslateProvider): self._proxy = proxy or None self._api_key = api_key self._url = f'https://generativelanguage.googleapis.com/v1beta/{model_code}:generateContent' - self._prompt = prompt.replace('\n', ' ').replace('\\n', '\n') + self._prompt = prompt self._body = { 'contents': [ {