Convert the raw input messages to a list of dicts. Args: inputs: raw input messages. Returns: list(dict): The preprocessed input messages. Will return None if failed to preprocess the input.
(self, inputs)
| 62 | return 'unknown' |
| 63 | |
| 64 | def preproc_content(self, inputs): |
| 65 | """Convert the raw input messages to a list of dicts. |
| 66 | |
| 67 | Args: |
| 68 | inputs: raw input messages. |
| 69 | |
| 70 | Returns: |
| 71 | list(dict): The preprocessed input messages. Will return None if failed to preprocess the input. |
| 72 | """ |
| 73 | if self.check_content(inputs) == 'str': |
| 74 | return [dict(type='text', value=inputs)] |
| 75 | elif self.check_content(inputs) == 'dict': |
| 76 | assert 'type' in inputs and 'value' in inputs |
| 77 | return [inputs] |
| 78 | elif self.check_content(inputs) == 'liststr': |
| 79 | res = [] |
| 80 | for s in inputs: |
| 81 | mime, pth = parse_file(s) |
| 82 | if mime is None or mime == 'unknown': |
| 83 | res.append(dict(type='text', value=s)) |
| 84 | else: |
| 85 | res.append(dict(type=mime.split('/')[0], value=pth)) |
| 86 | return res |
| 87 | elif self.check_content(inputs) == 'listdict': |
| 88 | for item in inputs: |
| 89 | assert 'type' in item and 'value' in item |
| 90 | mime, s = parse_file(item['value']) |
| 91 | if mime is None: |
| 92 | assert item['type'] == 'text' |
| 93 | else: |
| 94 | assert mime.split('/')[0] == item['type'] |
| 95 | item['value'] = s |
| 96 | return inputs |
| 97 | else: |
| 98 | return None |
| 99 | |
| 100 | def generate(self, message, dataset=None): |
| 101 | """Generate the output message. |
no test coverage detected