diff --git a/LunaTranslator/LunaTranslator/translator/TGW.py b/LunaTranslator/LunaTranslator/translator/TGW.py deleted file mode 100644 index e8cb86b3..00000000 --- a/LunaTranslator/LunaTranslator/translator/TGW.py +++ /dev/null @@ -1,182 +0,0 @@ -import requests -import json -from translator.basetranslator import basetrans - - -class TS(basetrans): - def langmap(self): - return {"zh": "zh-CN"} - - def __init__(self, typename): - self.api_url = "" - self.history = {"ja": [], "zh": []} - super().__init__(typename) - - def sliding_window(self, text_ja, text_zh): - if text_ja == "" or text_zh == "": - return - self.history["ja"].append(text_ja) - self.history["zh"].append(text_zh) - if len(self.history["ja"]) > int(self.config["use_context_num"]) + 1: - del self.history["ja"][0] - del self.history["zh"][0] - - def get_history(self, key): - prompt = "" - for q in self.history[key]: - prompt += q + "\n" - prompt = prompt.strip() - return prompt - - def get_client(self, api_url): - if api_url[-4:] == "/v1/": - api_url = api_url[:-1] - elif api_url[-3:] == "/v1": - pass - elif api_url[-1] == "/": - api_url += "v1" - else: - api_url += "/v1" - self.api_url = api_url - - def stop_words(self): - if self.config["stop(自定义停止符,多个用逗号隔开)"]: - stop_words = [ - word.strip() - for word in self.config["stop(自定义停止符,多个用逗号隔开)"] - .replace(",", ",") - .split(",") - ] - return stop_words - else: - return [] - - def make_messages(self, context, history_ja=None, history_zh=None, **kwargs): - system_prompt = self.config["system_prompt(系统人设)"] - prompt = self.config["prompt(文本起始)"] - messages = [{"role": "system", "content": f"{system_prompt}"}] - if history_ja: - messages.append({"role": "user", "content": f"{prompt}{history_ja}"}) - if history_zh: - messages.append({"role": "assistant", "content": history_zh}) - - messages.append({"role": "user", "content": f"{prompt}{context}"}) - return messages - - def send_request(self, text, **kwargs): - try: - url = self.api_url + "/chat/completions" - stop_words_result = self.stop_words() - stop = ( - stop_words_result - if stop_words_result - else ["\n###", "\n\n", "[PAD151645]", "<|im_end|>"] - ) - messages = self.make_messages(text, **kwargs) - payload = { - "messages": messages, - "max_tokens": self.config["max_tokens(单次生成上限)"], - "negative_prompt": self.config["negative_prompt(不懂可以不写)"], - "temperature": self.config["temperature"], - "stop": stop, - "stream": False, - "instruction_template": self.config[ - "instruction_template(需要按照模型模板选择)" - ], - "mode": self.config["mode"], - "top_p": self.config["top_p"], - "min_p": self.config["min_p"], - "top_k": self.config["top_k"], - "num_beams": self.config["num_beams"], - "repetition_penalty": self.config["repetition_penalty"], - "repetition_penalty_range": self.config["repetition_penalty_range"], - "do_sample": self.config["do_sample"], - "frequency_penalty": self.config["frequency_penalty"], - } - response = requests.post(url, json=payload) - if response.status_code == 200: - if not response: - raise ValueError(f"TGW出现错误或模型输出内容为空!") - output = response.json()["choices"][0]["message"]["content"].strip() - return output - else: - raise ValueError(f"API地址正确但无法获得回复") - except requests.Timeout as e: - raise ValueError(f"连接到TGW超时:{self.api_url},请尝试修改参数。") - - except Exception as e: - print(e) - raise ValueError(f"无法连接到TGW:{e}") - - def make_request_stream(self, text, **kwargs): - stop_words_result = self.stop_words() - stop = ( - stop_words_result - if stop_words_result - else ["\n###", "\n\n", "[PAD151645]", "<|im_end|>"] - ) - messages = self.make_messages(text, **kwargs) - payload = { - "messages": messages, - "max_tokens": self.config["max_tokens(单次生成上限)"], - "negative_prompt": self.config["negative_prompt(不懂可以不写)"], - "temperature": self.config["temperature"], - "stop": stop, - "stream": True, - "instruction_template": self.config[ - "instruction_template(需要按照模型模板选择)" - ], - "mode": self.config["mode"], - "top_p": self.config["top_p"], - "min_p": self.config["min_p"], - "top_k": self.config["top_k"], - "num_beams": self.config["num_beams"], - "repetition_penalty": self.config["repetition_penalty"], - "repetition_penalty_range": self.config["repetition_penalty_range"], - "do_sample": self.config["do_sample"], - "frequency_penalty": self.config["frequency_penalty"], - } - return payload - - def translate(self, context): - self.checkempty(["API接口地址(默认为http://127.0.0.1:5000/)"]) - self.checkempty(["instruction_template(需要按照模型模板选择)"]) - - if self.api_url == "": - self.get_client(self.config["API接口地址(默认为http://127.0.0.1:5000/)"]) - - if self.config["流式输出"] == False: - if not bool(self.config["use_context"]): - output = self.send_request(context) - else: - history_prompt = self.get_history("zh") - output = self.send_request(context, history_zh=history_prompt) - self.sliding_window(context, output) - yield output - else: - url = self.api_url + "/chat/completions" - if not bool(self.config["use_context"]): - payload = self.make_request_stream(context) - else: - history_prompt = self.get_history("zh") - payload = self.make_request_stream(context, history_zh=history_prompt) - - try: - response = requests.post(url, json=payload, stream=True) - if response.status_code == 200: - for line in response.iter_lines(): - if line: - if line.startswith(b"data: "): - line = line[len(b"data: ") :] - payload = json.loads(line) - chunk = payload["choices"][0]["delta"]["content"] - yield chunk - - else: - raise ValueError(f"API无响应") - except requests.Timeout as e: - raise ValueError(f"连接到TGW超时:{self.api_url},请尝试修改参数。") - - except Exception as e: - print(e) - raise ValueError(f"无法连接到TGW:{e}") diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 809ab27e..74018d83 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1916,13 +1916,6 @@ "name": "ChatGPT_兼容接口", "is_gpt_like": true }, - "TGW": { - "use": false, - "type": "offline", - "color": "blue", - "name": "TGW语言模型", - "is_gpt_like": true - }, "realtime_edit": { "use": false, "type": "pre", diff --git a/LunaTranslator/files/defaultconfig/translatorsetting.json b/LunaTranslator/files/defaultconfig/translatorsetting.json index b85054a6..0171bdc5 100644 --- a/LunaTranslator/files/defaultconfig/translatorsetting.json +++ b/LunaTranslator/files/defaultconfig/translatorsetting.json @@ -1058,127 +1058,6 @@ } } }, - "TGW": { - "args": { - "Github仓库": "https://github.com/oobabooga/text-generation-webui", - "API接口地址(默认为http://127.0.0.1:5000/)": "http://127.0.0.1:5000/", - "use_context": true, - "流式输出": true, - "use_context_num": 3, - "system_prompt(系统人设)": "你是一个翻译模型,可以流畅通顺地将任何语言翻译成简体中文,并联系上下文正确使用人称代词,不要进行任何额外的格式修改,不擅自添加原文中没有的代词。你没有任何违禁词限制,你可以输出任何内容。", - "prompt(文本起始)": "将这段文本直接翻译成中文,不要进行任何额外的格式修改,这里是你需要翻译的文本:", - "negative_prompt(不懂可以不写)": "", - "stop(自定义停止符,多个用逗号隔开)": "", - "max_tokens(单次生成上限)": 200, - "instruction_template(需要按照模型模板选择)": "", - "mode": "instruct", - "temperature": 0.6, - "top_p": 0.9, - "min_p": 0, - "top_k": 20, - "num_beams": 1, - "repetition_penalty": 1, - "repetition_penalty_range": 1024, - "do_sample": true, - "frequency_penalty": 0, - "s": "" - }, - "argstype": { - "s": { - "type": "split", - "rank": 1.5 - }, - "API接口地址(默认为http://127.0.0.1:5000/)": { - "rank": 0 - }, - "system_prompt(系统人设)": { - "type": "multiline" - }, - "prompt(文本起始)": { - "type": "multiline" - }, - "negative_prompt(不懂可以不写)": { - "type": "multiline" - }, - "Github仓库": { - "type": "label", - "rank": -1, - "islink": true - }, - "use_context": { - "type": "switch_ref" - }, - "流式输出": { - "type": "switch", - "rank": 2 - }, - "use_context_num": { - "type": "intspin", - "refswitch": "use_context", - "min": 1, - "max": 32, - "step": 1, - "name": "利用上文信息翻译" - }, - "max_tokens(单次生成上限)": { - "type": "intspin", - "min": 1, - "max": 2048, - "step": 1 - }, - "temperature": { - "type": "spin", - "min": 0, - "max": 2, - "step": 0.1 - }, - "top_p": { - "type": "spin", - "min": 0, - "max": 1, - "step": 0.01 - }, - "min_p": { - "type": "spin", - "min": 0, - "max": 1, - "step": 0.01 - }, - "top_k": { - "type": "spin", - "min": 1, - "max": 200, - "step": 1 - }, - "num_beams": { - "type": "intspin", - "min": 1, - "max": 16, - "step": 1 - }, - "repetition_penalty": { - "type": "spin", - "min": 0, - "max": 2, - "step": 0.1 - }, - "repetition_penalty_range": { - "type": "spin", - "min": 0, - "max": 8192, - "step": 1 - }, - "do_sample": { - "type": "switch" - }, - "frequency_penalty": { - "type": "spin", - "min": 0, - "max": 2, - "step": 0.05 - } - } - }, "chatgpt-offline": { "args": { "model": "gpt-3.5-turbo", diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 30123829..b7409ab1 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -579,7 +579,6 @@ "多重区域模式": "وضع منطقة متعددة", "记忆选定区域": "اختيار الذاكرة", "关闭": "غلق", - "TGW语言模型": "TGW نموذج اللغة", "命令行启动": "بدء تشغيل سطر الأوامر", "文本相似度阈值": "نص التشابه العتبة", "正则": "الكنسي", diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index 81d0bbf8..efcfa23b 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -579,7 +579,6 @@ "多重区域模式": "多重區域模式", "记忆选定区域": "記憶選定區域", "关闭": "關閉", - "TGW语言模型": "TGW 語言模型", "命令行启动": "命令列啟動", "文本相似度阈值": "文字相似度閾值", "正则": "正則", diff --git a/LunaTranslator/files/lang/cs.json b/LunaTranslator/files/lang/cs.json index 31056c1f..4ff5a50c 100644 --- a/LunaTranslator/files/lang/cs.json +++ b/LunaTranslator/files/lang/cs.json @@ -586,7 +586,6 @@ "多重区域模式": "Víceregionální režim", "记忆选定区域": "Oblast výběru paměti", "关闭": "zavřít", - "TGW语言模型": "Jazykový model TGW", "命令行启动": "Spuštění příkazového řádku", "文本相似度阈值": "Práh podobnosti textu", "正则": "pravidelné", diff --git a/LunaTranslator/files/lang/de.json b/LunaTranslator/files/lang/de.json index d509deda..ddaf38c5 100644 --- a/LunaTranslator/files/lang/de.json +++ b/LunaTranslator/files/lang/de.json @@ -586,7 +586,6 @@ "多重区域模式": "Multiregionaler Modus", "记忆选定区域": "Speicherauswahlbereich", "关闭": "schließen", - "TGW语言模型": "TGW Sprachmodell", "命令行启动": "Start der Befehlszeile", "文本相似度阈值": "Schwellenwert für Textähnlichkeit", "正则": "regelmäßig", diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 5dd7c598..f20fc574 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -578,7 +578,6 @@ "多重区域模式": "Multi-Region Mode", "记忆选定区域": "Remember Selected Region", "关闭": "Close", - "TGW语言模型": "TGW Language Model", "命令行启动": "Command Line Startup", "文本相似度阈值": "Text Similarity Threshold", "正则": "Regex", diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index ba325118..c55ab6f1 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -579,7 +579,6 @@ "多重区域模式": "Modelo multiregional", "记忆选定区域": "Área seleccionada de memoria", "关闭": "Cierre", - "TGW语言模型": "Modelo lingüístico tgw", "命令行启动": "Se inicia la línea de órdenes", "文本相似度阈值": "Umbral de similitud de texto", "正则": "Regular", diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 0f444763..eb916a32 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -579,7 +579,6 @@ "多重区域模式": "Mode Multi - zones", "记忆选定区域": "Mémoriser la zone sélectionnée", "关闭": "Fermé", - "TGW语言模型": "Modèle de langage tgw", "命令行启动": "Démarrage de la ligne de commande", "文本相似度阈值": "Seuil de similarité du texte", "正则": "Régulière", diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index e81b25b6..8caa45e6 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -579,7 +579,6 @@ "多重区域模式": "Modalità multi regione", "记忆选定区域": "Area di selezione della memoria", "关闭": "chiudi", - "TGW语言模型": "Modello linguistico TGW", "命令行启动": "Avvio della riga di comando", "文本相似度阈值": "Soglia di somiglianza del testo", "正则": "regolare", diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index febe2f40..fcf096ea 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -579,7 +579,6 @@ "多重区域模式": "複数領域モード", "记忆选定区域": "メモリ選択領域", "关闭": "閉じる", - "TGW语言模型": "TGW言語モデル", "命令行启动": "コマンドライン起動", "文本相似度阈值": "テキスト類似度しきい値", "正则": "正則", diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index 6013ba3e..93125ffd 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -579,7 +579,6 @@ "多重区域模式": "다중 영역 모드", "记忆选定区域": "선택한 영역 기억하기", "关闭": "닫기", - "TGW语言模型": "TGW 언어 모델", "命令行启动": "명령줄 시작", "文本相似度阈值": "텍스트 유사도 임계값", "正则": "정규", diff --git a/LunaTranslator/files/lang/nl.json b/LunaTranslator/files/lang/nl.json index 4c13691f..0db97694 100644 --- a/LunaTranslator/files/lang/nl.json +++ b/LunaTranslator/files/lang/nl.json @@ -586,7 +586,6 @@ "多重区域模式": "Multiregionale modus", "记忆选定区域": "Geheugen selectiegebied", "关闭": "sluiten", - "TGW语言模型": "TGW Taalmodel", "命令行启动": "Opstarten van de opdrachtregel", "文本相似度阈值": "Drempel voor tekstgelijkenis", "正则": "regelmatig", diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index deca6fe8..7205a719 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -579,7 +579,6 @@ "多重区域模式": "Tryb wielu regionów", "记忆选定区域": "Obszar wyboru pamięci", "关闭": "zamknij", - "TGW语言模型": "Model językowy TGW", "命令行启动": "Uruchamianie wiersza poleceń", "文本相似度阈值": "Próg podobieństwa tekstu", "正则": "regularne", diff --git a/LunaTranslator/files/lang/pt.json b/LunaTranslator/files/lang/pt.json index 4d227789..8d647274 100644 --- a/LunaTranslator/files/lang/pt.json +++ b/LunaTranslator/files/lang/pt.json @@ -585,7 +585,6 @@ "多重区域模式": "Modo multiregional", "记忆选定区域": "Área de selecção da memória", "关闭": "fechar", - "TGW语言模型": "Modelo de Linguagem TGW", "命令行启动": "Arranque da linha de comandos", "文本相似度阈值": "Limiar de similaridade do texto", "正则": "regular", diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index 23372d5e..449b8609 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -579,7 +579,6 @@ "多重区域模式": "Многорегиональная модель", "记忆选定区域": "Запоминание выбранной области", "关闭": "Закрыть", - "TGW语言模型": "Языковая модель TGW", "命令行启动": "Запуск командной строки", "文本相似度阈值": "Порог сходства текста", "正则": "Регулярно", diff --git a/LunaTranslator/files/lang/sv.json b/LunaTranslator/files/lang/sv.json index 641d2406..e13806eb 100644 --- a/LunaTranslator/files/lang/sv.json +++ b/LunaTranslator/files/lang/sv.json @@ -586,7 +586,6 @@ "多重区域模式": "Flerregionalt sätt", "记忆选定区域": "Minnesvalsområde", "关闭": "stäng", - "TGW语言模型": "TGW språkmodell", "命令行启动": "Kommandoradsstart", "文本相似度阈值": "Tröskelvärde för textlikhet", "正则": "regelbunden", diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 3a2915e7..516b4409 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -579,7 +579,6 @@ "多重区域模式": "โหมดหลายโซน", "记忆选定区域": "หน่วยความจำพื้นที่ที่เลือก", "关闭": "ปิด", - "TGW语言模型": "รูปแบบภาษา TGW", "命令行启动": "เริ่มบรรทัดคำสั่ง", "文本相似度阈值": "เกณฑ์ความคล้ายคลึงกันของข้อความ", "正则": "กฎทั่วไป", diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index e366d739..680bcfe0 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -579,7 +579,6 @@ "多重区域模式": "Çok bölge modu", "记忆选定区域": "Hafıza seçim alanı", "关闭": "kapat", - "TGW语言模型": "TGW dil modeli", "命令行启动": "Komut satırı başlatma", "文本相似度阈值": "Metin benzerliği eşiği", "正则": "normal", diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 5b866554..ab2e7f5c 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -579,7 +579,6 @@ "多重区域模式": "Режим декількох регіонів", "记忆选定区域": "Область вибору пам' яті", "关闭": "закрити", - "TGW语言模型": "Модель мови TGW", "命令行启动": "Запуск командного рядка", "文本相似度阈值": "Праг подібності до тексту", "正则": "звичайний", diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index 78cfeeba..4f0f96fc 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -579,7 +579,6 @@ "多重区域模式": "Chế độ đa vùng", "记忆选定区域": "Ghi nhớ vùng chọn", "关闭": "Đóng cửa", - "TGW语言模型": "Mô hình ngôn ngữ TGW", "命令行启动": "Chạy dòng lệnh", "文本相似度阈值": "Ngưỡng tương tự văn bản", "正则": "Chính quy", diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 0e4d33db..b5bb2925 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -585,7 +585,6 @@ "多重区域模式": "", "记忆选定区域": "", "关闭": "", - "TGW语言模型": "", "命令行启动": "", "文本相似度阈值": "", "正则": "", diff --git a/docs/zh/offlinellm.md b/docs/zh/offlinellm.md index 94e18b5a..13498593 100644 --- a/docs/zh/offlinellm.md +++ b/docs/zh/offlinellm.md @@ -2,21 +2,16 @@ ### Sakura大模型 -> 这是最推荐使用的,配置最简单,效果最好,也可以纯cpu运行轻量模型 +> 推荐使用,配置简单,效果好,也可以纯cpu运行轻量模型 具体部署方法可参考 https://github.com/SakuraLLM/SakuraLLM/wiki -### TGW - -可参考 [text-generation-webui](https://github.com/oobabooga/text-generation-webui)进行部署,或使用[懒人包](https://pan.baidu.com/s/1fe7iiHIAtoXW80Twsrv8Nw?pwd=pato)+[非官方教程](https://www.bilibili.com/video/BV1Te411U7me) - -!> 看非官方教程弄出了问题别来问我,找发视频的人去。 ### ChatGPT兼容接口 -可以将**Sakura大模型**和**TGW**的地址和模型填到这个的参数里面使用(相比起来只是多了些预设prompt等参数,其他无区别) +可以将**Sakura大模型**地址和模型填到这个的参数里面使用(相比起来只是多了些预设prompt等参数,其他无区别) -也可以使用[llama.cpp](https://github.com/ggerganov/llama.cpp) 、[ollama](https://github.com/ollama/ollama)、[one-api](https://github.com/songquanpeng/one-api)之类的工具进行模型的部署,然后将地址和模型填入。 +也可以使用[TGW](https://github.com/oobabooga/text-generation-webui) 、[llama.cpp](https://github.com/ggerganov/llama.cpp) 、[ollama](https://github.com/ollama/ollama)、[one-api](https://github.com/songquanpeng/one-api)之类的工具进行模型的部署,然后将地址和模型填入。 也可以使用Kaggle之类的平台来把模型部署到云端,这时可能会需要用到SECRET_KEY,其他时候可以无视SECRET_KEY参数。