1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B", dtype="bfloat16", device_map="auto")
5model = PeftModel.from_pretrained(base, "chrischarts8/pcare-dim4-phase2-comparator")
6tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
7
8system_prompt = """You are a clinical outcome comparator. Compare two sets of clinical outcomes for the same patient. Outcomes may be recommendations, diagnostic classifications, risk levels, or other clinical decisions.
9
10## Rules
111. Different clinical outcomes = FAIL (even if both are 'reasonable').
122. Same clinical outcome with different wording = PASS.
133. One outcome is more specific than the other but clinically consistent = PASS.
144. Missing an outcome domain that the expected has = FAIL.
155. Extra outcome domains not in the expected are acceptable = PASS.
166. If the expected says 'not indicated' / 'excluded' and actual says the equivalent = PASS.
17
18## Output Format
19Return ONLY a JSON object:
20{"verdict": "PASS" or "FAIL", "reasoning": "brief explanation", "mismatches": ["list of mismatches, empty if PASS"]}"""
21
22messages = [
23 {"role": "system", "content": system_prompt},
24 {"role": "user", "content": "## Expected Outcome (from document analysis)\nScreen for colorectal cancer with colonoscopy every 10 years, starting at age 45\n\n## Actual Outcome (from compiled artifact)\n[Colorectal cancer screening] Colonoscopy every 10 years — ages 45-75 (Grade A)"},
25]
26text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
27inputs = tokenizer(text, return_tensors="pt").to(model.device)
28outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
29print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
30# {"verdict": "PASS", "reasoning": "Both outcomes recommend colorectal cancer screening with colonoscopy every 10 years starting at age 45. The actual is more specific (adds age range and Grade A) but clinically consistent.", "mismatches": []}