(
self,
lang_in: str,
lang_out: str,
model: str,
envs=None,
prompt: Template | None = None,
ignore_cache=False,
)
| 303 | CustomPrompt = True |
| 304 | |
| 305 | def __init__( |
| 306 | self, |
| 307 | lang_in: str, |
| 308 | lang_out: str, |
| 309 | model: str, |
| 310 | envs=None, |
| 311 | prompt: Template | None = None, |
| 312 | ignore_cache=False, |
| 313 | ): |
| 314 | self.set_envs(envs) |
| 315 | if not model: |
| 316 | model = self.envs["OLLAMA_MODEL"] |
| 317 | super().__init__(lang_in, lang_out, model, ignore_cache) |
| 318 | self.options = { |
| 319 | "temperature": 0, # 随机采样可能会打断公式标记 |
| 320 | "num_predict": 2000, |
| 321 | } |
| 322 | self.client = ollama.Client(host=self.envs["OLLAMA_HOST"]) |
| 323 | self.prompt_template = prompt |
| 324 | self.add_cache_impact_parameters("temperature", self.options["temperature"]) |
| 325 | |
| 326 | def do_translate(self, text: str) -> str: |
| 327 | if (max_token := len(text) * 5) > self.options["num_predict"]: |
nothing calls this directly
no test coverage detected