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: