Skip to content

Commit

Permalink
refactor: improve content extraction in translator response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaawwa committed Feb 25, 2025
1 parent 8d1c75e commit a88bf06
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pdf2zh/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ def do_translate(self, text) -> str:
if not response.choices:
if hasattr(response, "error"):
raise ValueError("Error response from Service", response.error)
return response.choices[0].message.content.strip()
content = response.choices[0].message.content.strip()
content = re.sub(r"^<think>.+?</think>", "", content, flags=re.DOTALL).strip()
return content

def get_formular_placeholder(self, id: int):
return "{{v" + str(id) + "}}"
Expand Down

0 comments on commit a88bf06

Please sign in to comment.