Skip to content

Commit

Permalink
feat: fix finish_reason check in translator engines
Browse files Browse the repository at this point in the history
  • Loading branch information
versun committed Jun 24, 2024
1 parent a7a947c commit ac50081
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion translator/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def translate(
presence_penalty=self.presence_penalty,
max_tokens=self.max_tokens,
)
if res.choices[0].finish_reason.lower() == "stop" or res.choices[0].message.content:
#if res.choices[0].finish_reason.lower() == "stop" or res.choices[0].message.content:
if res.choices and res.choices[0].message.content:
translated_text = res.choices[0].message.content
logging.info("OpenAITranslator->%s: %s", res.choices[0].finish_reason, translated_text)
# else:
Expand Down
3 changes: 2 additions & 1 deletion translator/models/doubao.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def translate(self, text: str, target_language: str, system_prompt: str = None,
],
max_tokens=self.max_tokens,
)
if res.choices[0].finish_reason.lower() == "stop" or res.choices[0].message.content:
#if res.choices[0].finish_reason.lower() == "stop" or res.choices[0].message.content:
if res.choices and res.choices[0].message.content:
translated_text = res.choices[0].message.content
logging.info("DoubaoTranslator->%s: %s", res.choices[0].finish_reason, translated_text)
tokens = res.usage.total_tokens
Expand Down

0 comments on commit ac50081

Please sign in to comment.