(items)
| 61 | return None |
| 62 | |
| 63 | def process_data(items): |
| 64 | for item in tqdm(items): |
| 65 | prompt = prompt_template.replace('$INST$', item['prompt']).replace('$RESPONSE$', item["response"]) |
| 66 | scores = None |
| 67 | trys = 0 |
| 68 | while scores is None and trys < 5: |
| 69 | output = get_response_gpt4(prompt) |
| 70 | try: |
| 71 | if '```json' in output: |
| 72 | output = extract_info(r'```json\n(.*?)\n```', output) |
| 73 | output = output.replace('\n', '') |
| 74 | scores = json.loads(output) |
| 75 | for dim in dims: |
| 76 | if dim not in scores: |
| 77 | scores = None |
| 78 | trys += 1 |
| 79 | except Exception as e: |
| 80 | trys += 1 |
| 81 | if scores is None: |
| 82 | print(output) |
| 83 | else: |
| 84 | item['scores'] = scores |
| 85 | fout.write(json.dumps(item, ensure_ascii=False)+'\n') |
| 86 | fout.flush() |
| 87 | |
| 88 | data = [json.loads(line) for line in prediction_file] |
| 89 | random.shuffle(data) |
nothing calls this directly
no test coverage detected