MCPcopy
hub / github.com/PDFMathTranslate/PDFMathTranslate / do_translate

Method do_translate

pdf2zh/translator.py:582–596  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

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
599class SiliconTranslator(OpenAITranslator):

Callers

nothing calls this directly

Calls 1

promptMethod · 0.80

Tested by

no test coverage detected