mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
gpt
This commit is contained in:
parent
c8a8c661c9
commit
3d588bdb4c
@ -83,15 +83,16 @@ class gptcommon(basetrans):
|
||||
# text/html
|
||||
raise Exception(response.text)
|
||||
for chunk in response.iter_lines():
|
||||
response_data = chunk.decode("utf-8").strip()
|
||||
response_data: str = chunk.decode("utf-8").strip()
|
||||
if not response_data.startswith("data: "):
|
||||
continue
|
||||
response_data = response_data[6:]
|
||||
if not response_data:
|
||||
continue
|
||||
if response_data == "data: [DONE]":
|
||||
if response_data == "[DONE]":
|
||||
break
|
||||
if response_data == ": OPENROUTER PROCESSING":
|
||||
continue
|
||||
try:
|
||||
json_data = json.loads(response_data[6:])
|
||||
json_data = json.loads(response_data)
|
||||
rs = json_data["choices"][0].get("finish_reason")
|
||||
if rs and rs != "null":
|
||||
break
|
||||
|
@ -191,18 +191,19 @@ class TS(basetrans):
|
||||
raise ValueError(f"连接到Sakura API超时:{self.api_url}")
|
||||
if not output.headers["Content-Type"].startswith("text/event-stream"):
|
||||
raise Exception(output.text)
|
||||
for o in output.iter_lines():
|
||||
o = o.decode("utf-8").strip()
|
||||
if o == "data: [DONE]":
|
||||
for chunk in output.iter_lines():
|
||||
response_data: str = chunk.decode("utf-8").strip()
|
||||
if not response_data.startswith("data: "):
|
||||
continue
|
||||
response_data = response_data[6:]
|
||||
if not response_data:
|
||||
continue
|
||||
if response_data == "[DONE]":
|
||||
break
|
||||
try:
|
||||
res = o[6:]
|
||||
# print(res)
|
||||
if res == "":
|
||||
continue
|
||||
res = json.loads(res)
|
||||
res = json.loads(response_data)
|
||||
except:
|
||||
raise Exception(o)
|
||||
raise Exception(response_data)
|
||||
|
||||
yield res
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user