Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (52 loc) · 1.67 KB
/
Copy pathmain.py
File metadata and controls
56 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from client import client
from templates import template, template_biomarker
from utils import (
note_drop_null,
keep_first_with_max_serial,
note_sort,
concatenate_notes,
format_notes,
extract_suvr_values,
replace_missing,
check_qc,
)
__all__ = [
"client",
"template",
"template_biomarker",
"note_drop_null",
"keep_first_with_max_serial",
"note_sort",
"concatenate_notes",
"format_notes",
"extract_suvr_values",
"replace_missing",
"check_qc",
"info_extractn",
]
def info_extractn(text, template):
response = client.chat.completions.create(
model="gpt-4.1",
messages=[
{
"role": "system",
"content": "You are a neurologist tasked with extracting relevant information from clinical notes.",
},
{
"role": "user",
"content": f"""
Carefully read through the notes and extract the following info as the template mentioned.
Return the extracted information in the same order as the template.
Return the date in the format MM/DD/YYYY, or MM/DD if there is no year recorded, but do not include the date in the extracted information unless it is explicitly required.
If the note does not include a piece of information, return \"missing\" for that field.
Return in json format.
Template: {template}
Clinical Note:
{text}
""",
},
],
max_tokens=4096,
response_format={"type": "json_object"},
)
return response.choices[0].message.content