| 580 | self.add_cache_impact_parameters("prompt", self.prompt("", self.prompttext)) |
| 581 | |
| 582 | def do_translate(self, text) -> str: |
| 583 | try: |
| 584 | response = self.client.chat.completions.create( |
| 585 | model=self.model, |
| 586 | **self.options, |
| 587 | messages=self.prompt(text, self.prompttext), |
| 588 | ) |
| 589 | except openai.BadRequestError as e: |
| 590 | if ( |
| 591 | json.loads(response.choices[0].message.content.strip())["error"]["code"] |
| 592 | == "1301" |
| 593 | ): |
| 594 | return "IRREPARABLE TRANSLATION ERROR" |
| 595 | raise e |
| 596 | return response.choices[0].message.content.strip() |
| 597 | |
| 598 | |
| 599 | class SiliconTranslator(OpenAITranslator): |