Convert raw input messages to unified dict list format. Args: inputs: Raw input. Returns: list: Processed input message list.
(self, inputs)
| 158 | return "unknown" |
| 159 | |
| 160 | def preproc_content(self, inputs): |
| 161 | """Convert raw input messages to unified dict list format. |
| 162 | |
| 163 | Args: |
| 164 | inputs: Raw input. |
| 165 | |
| 166 | Returns: |
| 167 | list: Processed input message list. |
| 168 | """ |
| 169 | if self.check_content(inputs) == "str": |
| 170 | return [dict(type="text", value=inputs)] |
| 171 | elif self.check_content(inputs) == "dict": |
| 172 | assert "type" in inputs and "value" in inputs |
| 173 | return [inputs] |
| 174 | elif self.check_content(inputs) == "liststr": |
| 175 | res = [] |
| 176 | for s in inputs: |
| 177 | mime, pth = parse_file(s, self.image_key_name) |
| 178 | if mime is None or mime == "unknown": |
| 179 | res.append(dict(type="text", value=s)) |
| 180 | else: |
| 181 | res.append(dict(type=mime.split("/")[0], value=pth)) |
| 182 | return res |
| 183 | elif self.check_content(inputs) == "listdict": |
| 184 | for item in inputs: |
| 185 | assert "type" in item and "value" in item |
| 186 | # Skip file parsing for system prompts (plain text) |
| 187 | if item["type"] == "system": |
| 188 | continue |
| 189 | mime, s = parse_file(item["value"], self.image_key_name) |
| 190 | if mime is None: |
| 191 | assert item["type"] == "text", item["value"] |
| 192 | else: |
| 193 | assert item["type"] in ["image", "image_url"] |
| 194 | item["type"] = mime |
| 195 | item["value"] = s |
| 196 | return inputs |
| 197 | else: |
| 198 | return None |
| 199 | |
| 200 | def prepare_inputs(self, inputs): |
| 201 | """Prepare message format for API interface. |