| 56 | ) |
| 57 | |
| 58 | async def _response_async(self, msg: str) -> LLMResponse: |
| 59 | # response is based on this fallback order: |
| 60 | # - response_dict |
| 61 | # - response_fn_async |
| 62 | # - response_fn |
| 63 | # - default_response |
| 64 | if self.config.response_fn_async is not None: |
| 65 | response = await self.config.response_fn_async(msg) |
| 66 | else: |
| 67 | response = self.config.response_fn(msg) |
| 68 | |
| 69 | mapped_response = self.config.response_dict.get( |
| 70 | msg, response or self.config.default_response |
| 71 | ) |
| 72 | return lm.LLMResponse( |
| 73 | message=to_string(mapped_response), |
| 74 | cached=False, |
| 75 | ) |
| 76 | |
| 77 | def chat( |
| 78 | self, |