Add extract.py
This commit is contained in:
22
extract.py
Normal file
22
extract.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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)
|
||||||
Reference in New Issue
Block a user