| from openai import OpenAI |
| import json, os |
|
|
| with open("/home/mshahidul/readctrl/prompts/subclaims_extraction_vali.txt", "r") as f: |
| prompt_template = f.read() |
|
|
|
|
| api_file = "/home/mshahidul/api_new.json" |
| with open(api_file, "r") as f: |
| api_keys = json.load(f) |
| openai_api_key = api_keys["openai"] |
|
|
| client = OpenAI(api_key=openai_api_key) |
|
|
|
|
| def openai_return(prompt, model="gpt-5"): |
| """Send a prompt to GPT and parse JSON.""" |
| response = client.chat.completions.create( |
| model=model, |
| messages=[ |
| {"role": "system", "content": "You are a helpful assistant."}, |
| {"role": "user", "content": prompt} |
| ] |
| ) |
| content = response.choices[0].message.content.strip() |
| cleaned = content.replace("```json", "").replace("```", "").strip() |
| try: |
| return json.loads(cleaned) |
| except json.JSONDecodeError: |
| print("⚠️ JSON parse failed — storing raw text.") |
| return cleaned |
|
|
| with open("/home/mshahidul/readctrl/data/extracting_subclaim/extracted_subclaims_full_data.json", "r") as f: |
| data = json.load(f) |
|
|
| save_path="/home/mshahidul/readctrl/data/model_validity_check/subclaims_validity_check_v1.json" |
| res=[] |
| if os.path.exists(save_path): |
| with open(save_path, "r") as f: |
| res = json.load(f) |
| import tqdm |
| for i in tqdm.tqdm(range(5)): |
| for label in ["easy", "intermediate", "hard"]: |
| new_prompt = prompt_template.replace("<<<TEXT>>>",data[i][f"{label}_text"]).replace("<<<SUBCLAIMS>>>", json.dumps(data[i][f"{label}_subclaims"], indent=2, ensure_ascii=False)) |
| |
| sample = openai_return(new_prompt, model="gpt-5") |
|
|
| res.append(sample) |
| if len(res) % 2 == 0: |
| with open(save_path, "w") as f: |
| json.dump(res, f, indent=2, ensure_ascii=False) |
| print(f"Saved {len(res)} samples so far.") |
|
|
| with open(save_path, "w") as f: |
| json.dump(res, f, indent=2, ensure_ascii=False) |
|
|
|
|