Implements the ShareGPT dataset. Loads data from a JSON file and generates sample requests based on conversation turns.
| 263 | |
| 264 | |
| 265 | class EBChatDataset(BenchmarkDataset): |
| 266 | """ |
| 267 | Implements the ShareGPT dataset. Loads data from a JSON file and generates |
| 268 | sample requests based on conversation turns. |
| 269 | """ |
| 270 | |
| 271 | prompt_len: int |
| 272 | |
| 273 | def __init__(self, **kwargs) -> None: |
| 274 | super().__init__(**kwargs) |
| 275 | self.load_data() |
| 276 | |
| 277 | def load_data(self) -> None: |
| 278 | if self.dataset_path is None: |
| 279 | raise ValueError("dataset_path must be provided for loading data.") |
| 280 | |
| 281 | with open(self.dataset_path, encoding="utf-8") as f: |
| 282 | self.data = [json.loads(i.strip()) for i in f.readlines()] |
| 283 | |
| 284 | if self.shuffle: |
| 285 | random.seed(self.random_seed) |
| 286 | random.shuffle(self.data) |
| 287 | |
| 288 | def sample( |
| 289 | self, |
| 290 | num_requests: int, |
| 291 | lora_path: Optional[str] = None, |
| 292 | max_loras: Optional[int] = None, |
| 293 | output_len: Optional[int] = None, |
| 294 | enable_multimodal_chat: bool = False, |
| 295 | **kwargs, |
| 296 | ) -> list: |
| 297 | samples: list = [] |
| 298 | cnt = 1 |
| 299 | for entry in self.data: |
| 300 | if len(samples) >= num_requests: |
| 301 | break |
| 302 | json_data = entry |
| 303 | prompt = entry["messages"][-1].get("content", "") |
| 304 | history_QA = entry.get("messages", []) |
| 305 | response_format = entry.get("response_format") |
| 306 | new_output_len = int(entry.get("max_tokens", output_len if output_len else 12288)) |
| 307 | |
| 308 | if enable_multimodal_chat: |
| 309 | prompt = self.apply_multimodal_chat_transformation(prompt, None) |
| 310 | samples.append( |
| 311 | SampleRequest( |
| 312 | no=cnt, |
| 313 | json_data=json_data, |
| 314 | prompt=prompt, |
| 315 | prompt_len=0, |
| 316 | history_QA=history_QA, |
| 317 | expected_output_len=new_output_len, |
| 318 | response_format=response_format, |
| 319 | ) |
| 320 | ) |
| 321 | cnt += 1 |
| 322 |
no outgoing calls
no test coverage detected