23 lines
492 B
Python
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)
|