File size: 2,113 Bytes
750b88d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Answering, judging and memorize prompts."""
from __future__ import annotations

ANSWER_SYS = ("You are a clinician answering a question about ONE patient. You have the patient's memory below "
              "as your ONLY source. Find the relevant facts and answer.")

ANSWER_USER = ("PATIENT MEMORY (your memory):\n{ctx}\n\n"
               "Today's date: {as_of}.\n\nQUESTION:\n{qtext}\n\n"
               'Return JSON: {{"answer": "<your answer>"}}')

ANSWER_NOCTX = ("You are a clinician answering a question about ONE patient. The patient's "
                "dialogue history is your ONLY source. Find the relevant facts and answer.\n\n"
                "Today's date: {as_of}.\n\nQUESTION:\n{qtext}\n\n"
                'Return JSON: {{"answer": "<your answer>"}}')

ANSWER_NOCTX_NOJSON = ("You are a clinician answering a question about ONE patient. The patient's "
                       "dialogue history is your ONLY source. Find the relevant facts and answer.\n\n"
                       "Today's date: {as_of}.\n\nQUESTION:\n{qtext}")

JUDGE_SYS = ("Judge whether CANDIDATE matches GOLD in meaning for this patient. Ignore wording/format; match "
             "the core clinical fact; same MC option = match. If GOLD says the information is not documented, "
             "CANDIDATE matches if it says the information is not in the record, in any wording; \"unknown\" or "
             "\"cannot determine\" does not match. Return ONLY JSON.")

JUDGE_USER = 'QUESTION: {question}\nGOLD: {gold}\nCANDIDATE: {cand}\n{{"match": true|false}}'

MEMORIZE_TEMPLATE = "This is a clinical visit record. Store the information it contains in memory:\n\n{context}"


def qtext(q_raw: dict) -> str:
    """Question text, with its options appended when they are not already part of it."""
    s = q_raw.get("question", "")
    opts = q_raw.get("options")
    if opts:
        first = opts[0]
        already = f"{first.get('label')}." in s and str(first.get('content', ''))[:20] in s
        if not already:
            s += "\n" + "\n".join(f"  {o.get('label')}. {o.get('content')}" for o in opts)
    return s