mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
parent
22379db61f
commit
a4db0c981a
@ -164,6 +164,7 @@ class TS(basetrans):
|
|||||||
history_prompt = self.get_history("zh")
|
history_prompt = self.get_history("zh")
|
||||||
payload = self.make_request_stream(context, history_zh=history_prompt)
|
payload = self.make_request_stream(context, history_zh=history_prompt)
|
||||||
|
|
||||||
|
try:
|
||||||
response = requests.post(url, timeout=self.timeout, json=payload, stream=True)
|
response = requests.post(url, timeout=self.timeout, json=payload, stream=True)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
for line in response.iter_lines():
|
for line in response.iter_lines():
|
||||||
@ -174,3 +175,14 @@ class TS(basetrans):
|
|||||||
chunk = payload['choices'][0]['delta']['content']
|
chunk = payload['choices'][0]['delta']['content']
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError(f"API无响应")
|
||||||
|
except requests.Timeout as e:
|
||||||
|
raise ValueError(
|
||||||
|
f"连接到TGW超时:{self.api_url},当前最大连接时间为: {self.timeout},请尝试修改参数。"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
raise ValueError(f"无法连接到TGW:{e}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user