Process a batch of prompts and return responses.
(batch_data)
| 158 | ] |
| 159 | |
| 160 | def process_batch(batch_data): |
| 161 | """Process a batch of prompts and return responses.""" |
| 162 | batch_prompts, batch_indices = batch_data |
| 163 | batch_responses = [] |
| 164 | |
| 165 | for i, prompt in enumerate(batch_prompts): |
| 166 | try: |
| 167 | response = model.generate(prompt, max_out_len) |
| 168 | batch_responses.append(response) |
| 169 | except Exception as e: |
| 170 | # 保持与evaluate方法一致的错误处理 |
| 171 | original_index = batch_indices[i] |
| 172 | print(f"\n⚠️ Error on item {original_index + 1}: {e}") |
| 173 | batch_responses.append(f"Error: {str(e)}") |
| 174 | |
| 175 | return batch_indices, batch_responses |
| 176 | |
| 177 | # Prepare batch data with indices |
| 178 | batch_data_list = [] |