Files
ai-extractor/extract.py
2026-01-12 14:17:00 +00:00

23 lines
492 B
Python

from openai import OpenAI
import json, re
client = OpenAI()
def extract_weight_report(text, lab):
prompt = f"""
Return ONLY valid JSON matching this structure:
...
Document:
{text}
"""
response = client.responses.create(
model="gpt-4.1-mini",
input=[{"role":"user","content":[{"type":"input_text","text":prompt}]}]
)
raw = response.output[0].content[0].text
raw = re.search(r"\{.*\}", raw, re.S).group()
return json.loads(raw)