From b1eb1441a9cf721ba611240c4101d813d02a8998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:34:41 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/gui/textbrowser.py | 3 +-- LunaTranslator/LunaTranslator/translator/chatgpt-3rd-party.py | 3 +++ LunaTranslator/LunaTranslator/translator/chatgpt.py | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/textbrowser.py b/LunaTranslator/LunaTranslator/gui/textbrowser.py index ad6753a8..68a3d503 100644 --- a/LunaTranslator/LunaTranslator/gui/textbrowser.py +++ b/LunaTranslator/LunaTranslator/gui/textbrowser.py @@ -256,11 +256,10 @@ class Textbrowser( ): lastpos=None posx=pos for i in range(len(text)): - if text[i] =='\n':continue self.textcursor.setPosition(posx) posx+=1 tl1=self.textbrowser.cursorRect(self.textcursor).topLeft() - if lastpos is None or tl1.y()!=lastpos.y(): + if lastpos is None or tl1.y()!=lastpos.y() or text[i] =='\n': lastpos=tl1 subpos.append(lastpos) subtext.append('') diff --git a/LunaTranslator/LunaTranslator/translator/chatgpt-3rd-party.py b/LunaTranslator/LunaTranslator/translator/chatgpt-3rd-party.py index 6090daf7..ec39a48a 100644 --- a/LunaTranslator/LunaTranslator/translator/chatgpt-3rd-party.py +++ b/LunaTranslator/LunaTranslator/translator/chatgpt-3rd-party.py @@ -61,10 +61,13 @@ class TS(basetrans): continue try: json_data = json.loads(response_data[6:]) + if json_data['choices'][0]['finish_reason']: + break msg = json_data["choices"][0]["delta"]['content'] yield msg message+=msg except: + print_exc() raise Exception(response_data) else: diff --git a/LunaTranslator/LunaTranslator/translator/chatgpt.py b/LunaTranslator/LunaTranslator/translator/chatgpt.py index 904e5b84..73cc8941 100644 --- a/LunaTranslator/LunaTranslator/translator/chatgpt.py +++ b/LunaTranslator/LunaTranslator/translator/chatgpt.py @@ -77,10 +77,13 @@ class TS(basetrans): continue try: json_data = json.loads(response_data[6:]) + if json_data['choices'][0]['finish_reason']: + break msg = json_data["choices"][0]["delta"]['content'] yield msg message+=msg except: + print_exc() raise Exception(response_data) else: