| 367 | self.add_cache_impact_parameters("temperature", self.options["temperature"]) |
| 368 | |
| 369 | def do_translate(self, text): |
| 370 | maxlen = max(2000, len(text) * 5) |
| 371 | for model in self.model.split(";"): |
| 372 | try: |
| 373 | xf_model = self.client.get_model(model) |
| 374 | xf_prompt = self.prompt(text, self.prompttext) |
| 375 | xf_prompt = [ |
| 376 | { |
| 377 | "role": "user", |
| 378 | "content": xf_prompt[0]["content"] |
| 379 | + "\n" |
| 380 | + xf_prompt[1]["content"], |
| 381 | } |
| 382 | ] |
| 383 | response = xf_model.chat( |
| 384 | generate_config=self.options, |
| 385 | messages=xf_prompt, |
| 386 | ) |
| 387 | |
| 388 | response = response["choices"][0]["message"]["content"].replace( |
| 389 | "<end_of_turn>", "" |
| 390 | ) |
| 391 | if len(response) > maxlen: |
| 392 | raise Exception("Response too long") |
| 393 | return response.strip() |
| 394 | except Exception as e: |
| 395 | print(e) |
| 396 | raise Exception("All models failed") |
| 397 | |
| 398 | |
| 399 | class OpenAITranslator(BaseTranslator): |