refine OpenAi Api (#159)

This commit is contained in:
KevinHuSh
2024-03-27 17:55:45 +08:00
committed by GitHub
parent 0cb95c688e
commit bf2e3d7fc1
5 changed files with 16 additions and 12 deletions

View File

@ -43,8 +43,8 @@ class GptTurbo(Base):
model=self.model_name,
messages=history,
**gen_conf)
ans = response.output.choices[0]['message']['content'].strip()
if response.output.choices[0].get("finish_reason", "") == "length":
ans = response.choices[0].message.content.strip()
if response.choices[0].finish_reason == "length":
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
return ans, response.usage.completion_tokens
@ -114,12 +114,12 @@ class ZhipuChat(Base):
history.insert(0, {"role": "system", "content": system})
try:
response = self.client.chat.completions.create(
self.model_name,
model=self.model_name,
messages=history,
**gen_conf
)
ans = response.output.choices[0]['message']['content'].strip()
if response.output.choices[0].get("finish_reason", "") == "length":
ans = response.choices[0].message.content.strip()
if response.choices[0].finish_reason == "length":
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
return ans, response.usage.completion_tokens