(self, inputs: Dict[str, str])
| 30 | self.init_flag = True |
| 31 | |
| 32 | def __call__(self, inputs: Dict[str, str]) -> Dict[str, str]: |
| 33 | if not self.init_flag: |
| 34 | self.init_model() |
| 35 | |
| 36 | question = inputs["input"] |
| 37 | answer = inputs["output"] |
| 38 | |
| 39 | src_lang = detect_lang(answer) |
| 40 | tgt_lang = detect_lang(question) |
| 41 | |
| 42 | if src_lang != tgt_lang: |
| 43 | translated_answer = self.chain.run(text=answer, language=tgt_lang) |
| 44 | outputs = deepcopy(inputs) |
| 45 | outputs["output"] = translated_answer |
| 46 | return outputs |
| 47 | else: |
| 48 | return inputs |
| 49 | |
| 50 | def create_openai_model(self, openai_api_key: str, model_name: str) -> OpenAI: |
| 51 | if openai_api_key is None: |
nothing calls this directly
no test coverage detected