Update sakura.py

This commit is contained in:
恍兮惚兮 2024-08-17 18:31:01 +08:00
parent a9190ec194
commit 819476f612

View File

@ -54,11 +54,15 @@ class TS(basetrans):
src = gpt["src"] src = gpt["src"]
if self.needzhconv: if self.needzhconv:
dst = zhconv.convert(gpt["dst"], "zh-hans") dst = zhconv.convert(gpt["dst"], "zh-hans")
info = zhconv.convert(gpt["info"], "zh-hans") if "info" in gpt.keys() else None info = (
zhconv.convert(gpt["info"], "zh-hans")
if "info" in gpt.keys()
else None
)
else: else:
dst = gpt["dst"] dst = gpt["dst"]
info = gpt["info"] if "info" in gpt.keys() else None info = gpt["info"] if "info" in gpt.keys() else None
if info: if info:
single = f"{src}->{dst} #{info}" single = f"{src}->{dst} #{info}"
else: else:
@ -118,6 +122,7 @@ class TS(basetrans):
) )
# print(content) # print(content)
messages.append({"role": "user", "content": content}) messages.append({"role": "user", "content": content})
print(messages)
return messages return messages
def send_request(self, query, is_test=False, **kwargs): def send_request(self, query, is_test=False, **kwargs):
@ -293,7 +298,9 @@ class TS(basetrans):
# output_text = output["choices"][0]["message"]["content"] # output_text = output["choices"][0]["message"]["content"]
if bool(self.config["流式输出"]) == True: if bool(self.config["流式输出"]) == True:
output = self.send_request_stream(query, history_zh=history_prompt) output = self.send_request_stream(
query, history_zh=history_prompt, gpt_dict=gpt_dict
)
completion_tokens = 0 completion_tokens = 0
output_text = "" output_text = ""
for o in output: for o in output:
@ -305,7 +312,9 @@ class TS(basetrans):
else: else:
finish_reason = o["choices"][0]["finish_reason"] finish_reason = o["choices"][0]["finish_reason"]
else: else:
output = self.send_request(query, history_zh=history_prompt) output = self.send_request(
query, history_zh=history_prompt, gpt_dict=gpt_dict
)
for o in output: for o in output:
completion_tokens = o["usage"]["completion_tokens"] completion_tokens = o["usage"]["completion_tokens"]
output_text = o["choices"][0]["message"]["content"] output_text = o["choices"][0]["message"]["content"]
@ -324,6 +333,7 @@ class TS(basetrans):
query, query,
history_zh=history_prompt, history_zh=history_prompt,
frequency_penalty=frequency_penalty, frequency_penalty=frequency_penalty,
gpt_dict=gpt_dict,
) )
completion_tokens = 0 completion_tokens = 0
output_text = "" output_text = ""
@ -341,6 +351,7 @@ class TS(basetrans):
query, query,
history_zh=history_prompt, history_zh=history_prompt,
frequency_penalty=frequency_penalty, frequency_penalty=frequency_penalty,
gpt_dict=gpt_dict,
) )
yield "\0" yield "\0"
for o in output: for o in output: