Skip to content

Commit 2f31e41

Browse files
committed
Format the line length of the prompts
1 parent bd6f737 commit 2f31e41

1 file changed

Lines changed: 70 additions & 43 deletions

File tree

server/api/services/prompt_services.py

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,77 @@
77
class PromptTemplates:
88
"""Central repository for all prompt templates used in the application."""
99

10+
# Text Extraction
11+
1012
TEXT_EXTRACTION_RULE_EXTRACTION = """
11-
You're analyzing medical text from multiple sources. Each chunk is labeled [chunk-X].
13+
You're analyzing medical text from multiple sources. Each chunk is labeled [chunk-X].
1214
13-
Act as a seasoned physician or medical professional who treats patients with bipolar disorder.
15+
Act as a seasoned physician or medical professional who treats patients with bipolar disorder.
1416
15-
Identify rules for medication inclusion or exclusion based on medical history or concerns.
17+
Identify rules for medication inclusion or exclusion based on medical history or concerns.
1618
17-
For each rule you find, return a JSON object using the following format:
19+
For each rule you find, return a JSON object using the following format:
1820
19-
{
20-
"rule": "<condition or concern>",
21-
"type": "INCLUDE" or "EXCLUDE",
22-
"reason": "<short explanation for why this rule applies>",
23-
"medications": ["<medication 1>", "<medication 2>", ...],
24-
"source": "<chunk-X>"
25-
}
21+
{
22+
"rule": "<condition or concern>",
23+
"type": "INCLUDE" or "EXCLUDE",
24+
"reason": "<short explanation for why this rule applies>",
25+
"medications": ["<medication 1>", "<medication 2>", ...],
26+
"source": "<chunk-X>"
27+
}
2628
27-
Only include rules that are explicitly stated or strongly implied in the chunk.
29+
Only include rules that are explicitly stated or strongly implied in the chunk.
2830
29-
Only use the chunks provided. If no rule is found in a chunk, skip it.
31+
Only use the chunks provided. If no rule is found in a chunk, skip it.
3032
31-
Return the entire output as a JSON array.
32-
"""
33+
Return the entire output as a JSON array.
34+
"""
3335

34-
EMBEDDINGS_QUERY_RESPONSE = """You are an AI assistant tasked with providing detailed, well-structured responses based on the information provided in [PROVIDED-INFO]. Follow these guidelines strictly:
35-
1. Content: Use information contained within [PROVIDED-INFO] to answer the question.
36-
2. Organization: Structure your response with clear sections and paragraphs.
37-
3. Citations: After EACH sentence that uses information from [PROVIDED-INFO], include a citation in this exact format:***[{{file_id}}], Page {{page_number}}, Chunk {{chunk_number}}*** . Only use citations that correspond to the information you're presenting.
38-
4. Clarity: Ensure your answer is well-structured and easy to follow.
39-
5. Direct Response: Answer the user's question directly without unnecessary introductions or filler phrases.
40-
Here's an example of the required response format:
41-
________________________________________
42-
See's Candy in the context of sales during a specific event. The candy counters rang up 2,690 individual sales on a Friday, and an additional 3,931 transactions on a Saturday ***[16s848as-vcc1-85sd-r196-7f820a4s9de1, Page 5, Chunk 26]***.
43-
People like the consumption of fudge and peanut brittle the most ***[130714d7-b9c1-4sdf-b146-fdsf854cad4f, Page 9, Chunk 19]***.
44-
Here is the history of See's Candy: the company was purchased in 1972, and its products have not been materially altered in 101 years ***[895sdsae-b7v5-416f-c84v-7f9784dc01e1, Page 2, Chunk 13]***.
45-
Bipolar disorder treatment often involves mood stabilizers. Lithium is a commonly prescribed mood stabilizer effective in reducing manic episodes ***[b99988ac-e3b0-4d22-b978-215e814807f4, Page 29, Chunk 122]***. For acute hypomania or mild to moderate mania, initial treatment with risperidone or olanzapine monotherapy is suggested ***[b99988ac-e3b0-4d22-b978-215e814807f4, Page 24, Chunk 101]***.
46-
________________________________________
47-
Please provide your response to the user's question following these guidelines precisely.
48-
[PROVIDED-INFO] = {listOfEmbeddings}"""
49-
50-
CONVERSATION_SYSTEM_PROMPT = """You are a knowledgeable assistant. Balancer is a powerful tool for selecting bipolar medication for patients. We are open-source and available for free use. Your primary role is to assist licensed clinical professionals with information related to Balancer and bipolar medication selection. If applicable, use the supplied tools to assist the professional."""
51-
52-
CONVERSATION_PAGE_CONTEXT_PROMPT = """If applicable, please use the following content to ask questions. If not applicable, please answer to the best of your ability: {page_context}"""
36+
# Embeddings/Search
37+
38+
EMBEDDINGS_QUERY_RESPONSE = """You are an AI assistant tasked with providing detailed, well-structured responses based
39+
on the information provided in [PROVIDED-INFO]. Follow these guidelines strictly:
40+
1. Content: Use information contained within [PROVIDED-INFO] to answer the question.
41+
2. Organization: Structure your response with clear sections and paragraphs.
42+
3. Citations: After EACH sentence that uses information from [PROVIDED-INFO],
43+
include a citation in this exact format:***[{{file_id}}], Page {{page_number}}, Chunk {{chunk_number}}*** .
44+
Only use citations that correspond to the information you're presenting.
45+
4. Clarity: Ensure your answer is well-structured and easy to follow.
46+
5. Direct Response: Answer the user's question directly without unnecessary introductions or filler phrases.
47+
Here's an example of the required response format:
48+
________________________________________
49+
See's Candy in the context of sales during a specific event. The candy counters rang up 2,690 individual sales on a Friday,
50+
and an additional 3,931 transactions on a Saturday ***[16s848as-vcc1-85sd-r196-7f820a4s9de1, Page 5, Chunk 26]***.
51+
People like the consumption of fudge and peanut brittle the most ***[130714d7-b9c1-4sdf-b146-fdsf854cad4f, Page 9, Chunk 19]***.
52+
Here is the history of See's Candy: the company was purchased in 1972, and its products have not been materially
53+
altered in 101 years ***[895sdsae-b7v5-416f-c84v-7f9784dc01e1, Page 2, Chunk 13]***.
54+
Bipolar disorder treatment often involves mood stabilizers. Lithium is a commonly prescribed mood stabilizer
55+
effective in reducing manic episodes ***[b99988ac-e3b0-4d22-b978-215e814807f4, Page 29, Chunk 122]***.
56+
For acute hypomania or mild to moderate mania, initial treatment with risperidone or olanzapine monotherapy is
57+
suggested ***[b99988ac-e3b0-4d22-b978-215e814807f4, Page 24, Chunk 101]***.
58+
________________________________________
59+
Please provide your response to the user's question following these guidelines precisely.
60+
[PROVIDED-INFO] = {listOfEmbeddings}"""
61+
62+
# Conversation/Chat
63+
64+
CONVERSATION_SYSTEM_PROMPT = """You are a knowledgeable assistant.
65+
Balancer is a powerful tool for selecting bipolar medication for patients. We are open-source and available for free use.
66+
Your primary role is to assist licensed clinical professionals with information related to Balancer and bipolar medication selection.
67+
If applicable, use the supplied tools to assist the professional."""
68+
69+
CONVERSATION_PAGE_CONTEXT_PROMPT = """If applicable, please use the following content to ask questions.
70+
If not applicable, please answer to the best of your ability: {page_context}"""
5371

5472
MEDICINE_DESCRIPTION_PROMPT = """Give a brief description of this medicine: %s"""
5573

74+
# Title Generation
75+
5676
TITLE_GENERATION_SYSTEM_PROMPT = (
5777
"""You are a helpful assistant that generates short, descriptive titles."""
5878
)
5979

60-
TITLE_GENERATION_USER_PROMPT = """Based on the following conversation, generate a short, descriptive title (max 6 words):
61-
62-
{context}"""
80+
TITLE_GENERATION_USER_PROMPT = """Based on the following conversation, generate a short, descriptive title (max 6 words): {context}"""
6381

6482
@classmethod
6583
def get_text_extraction_prompt(cls):
@@ -96,7 +114,7 @@ def get_title_generation_user_prompt(cls, context):
96114
"""Get the title generation user prompt."""
97115
return cls.TITLE_GENERATION_USER_PROMPT.format(context=context)
98116

99-
# Assistant tool prompts
117+
# Assistant Instructions
100118
ASSISTANT_TOOL_DESCRIPTION = """
101119
Search your internal library of bipolar disorder sources for information relevant to answering the user's question.
102120
Call this function when you need to find specific information from your source library
@@ -111,9 +129,12 @@ def get_title_generation_user_prompt(cls, context):
111129
"""
112130

113131
ASSISTANT_INSTRUCTIONS = """
114-
When you are asked a question, respond as if you are a chatbot with a library of sources that the user can't see. The user did not upload these sources, so they don't know about them. You have to explain what is in the sources and give references to the sources.
132+
When you are asked a question, respond as if you are a chatbot with a library of sources that the user can't see.
133+
The user did not upload these sources, so they don't know about them.
134+
You have to explain what is in the sources and give references to the sources.
115135
116-
When a prompt is received that is unrelated to bipolar disorder, mental health treatment, or psychiatric medications, respond to the user by saying you are limited to bipolar-specific conversations.
136+
When a prompt is received that is unrelated to bipolar disorder, mental health treatment, or psychiatric medications,
137+
respond to the user by saying you are limited to bipolar-specific conversations.
117138
118139
You are an AI assistant that helps users find and understand information about bipolar disorder
119140
from your internal library of bipolar disorder research sources using semantic search.
@@ -155,10 +176,16 @@ def get_assistant_instructions(cls):
155176
"""Get the assistant instructions."""
156177
return cls.ASSISTANT_INSTRUCTIONS
157178

158-
# Risk endpoint prompts
159-
RISK_BASIC_MEDICATION_PROMPT = """You are to provide a concise list of 5 key benefits and 5 key risks for the medication suggested when taking it for Bipolar. Each point should be short, clear and be kept under 10 words. Begin the benefits section with !!!benefits!!! and the risks section with !!!risk!!!. Please provide this information for the medication: {medication}."""
179+
# Risk Assessment
180+
181+
RISK_BASIC_MEDICATION_PROMPT = """You are to provide a concise list of 5 key benefits and 5 key risks for the medication suggested
182+
when taking it for Bipolar. Each point should be short, clear and be kept under 10 words. Begin the benefits
183+
section with !!!benefits!!! and the risks section with !!!risk!!!. Please provide this information for the medication: {medication}."""
160184

161-
RISK_DIAGNOSIS_MEDICATION_PROMPT = """You are providing medication information from a diagnosis/clinical perspective. Provide a concise list of 5 key benefits and 5 key risks for the medication {medication} when prescribed for Bipolar disorder, focusing on clinical evidence and diagnostic considerations. Each point should be short, clear and be kept under 10 words. Begin the benefits section with !!!benefits!!! and the risks section with !!!risk!!!."""
185+
RISK_DIAGNOSIS_MEDICATION_PROMPT = """You are providing medication information from a diagnosis/clinical perspective.
186+
Provide a concise list of 5 key benefits and 5 key risks for the medication {medication} when prescribed for Bipolar disorder,
187+
focusing on clinical evidence and diagnostic considerations. Each point should be short, clear and be kept under 10 words.
188+
Begin the benefits section with !!!benefits!!! and the risks section with !!!risk!!!."""
162189

163190
@classmethod
164191
def get_risk_basic_medication_prompt(cls, medication):

0 commit comments

Comments
 (0)