Skip to content

Commit e041428

Browse files
committed
Add prompt_services.py
1 parent 9c2b0cf commit e041428

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
Centralized prompt management for the application.
3+
Contains all prompts used across different services.
4+
"""
5+
6+
7+
class PromptTemplates:
8+
"""Central repository for all prompt templates used in the application."""
9+
10+
TEXT_EXTRACTION_RULE_EXTRACTION = """
11+
You're analyzing medical text from multiple sources. Each chunk is labeled [chunk-X].
12+
13+
Act as a seasoned physician or medical professional who treats patients with bipolar disorder.
14+
15+
Identify rules for medication inclusion or exclusion based on medical history or concerns.
16+
17+
For each rule you find, return a JSON object using the following format:
18+
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+
}
26+
27+
Only include rules that are explicitly stated or strongly implied in the chunk.
28+
29+
Only use the chunks provided. If no rule is found in a chunk, skip it.
30+
31+
Return the entire output as a JSON array.
32+
"""
33+
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}"""
53+
54+
MEDICINE_DESCRIPTION_PROMPT = """Give a brief description of this medicine: %s"""
55+
56+
TITLE_GENERATION_SYSTEM_PROMPT = (
57+
"""You are a helpful assistant that generates short, descriptive titles."""
58+
)
59+
60+
TITLE_GENERATION_USER_PROMPT = """Based on the following conversation, generate a short, descriptive title (max 6 words):
61+
62+
{context}"""
63+
64+
@classmethod
65+
def get_text_extraction_prompt(cls):
66+
"""Get the text extraction rule extraction prompt."""
67+
return cls.TEXT_EXTRACTION_RULE_EXTRACTION
68+
69+
@classmethod
70+
def get_embeddings_query_prompt(cls, list_of_embeddings):
71+
"""Get the embeddings query response prompt with embedded data."""
72+
return cls.EMBEDDINGS_QUERY_RESPONSE.format(listOfEmbeddings=list_of_embeddings)
73+
74+
@classmethod
75+
def get_conversation_system_prompt(cls):
76+
"""Get the conversation system prompt."""
77+
return cls.CONVERSATION_SYSTEM_PROMPT
78+
79+
@classmethod
80+
def get_conversation_page_context_prompt(cls, page_context):
81+
"""Get the conversation page context prompt."""
82+
return cls.CONVERSATION_PAGE_CONTEXT_PROMPT.format(page_context=page_context)
83+
84+
@classmethod
85+
def get_medicine_description_prompt(cls, tokens):
86+
"""Get the medicine description prompt."""
87+
return cls.MEDICINE_DESCRIPTION_PROMPT % tokens
88+
89+
@classmethod
90+
def get_title_generation_system_prompt(cls):
91+
"""Get the title generation system prompt."""
92+
return cls.TITLE_GENERATION_SYSTEM_PROMPT
93+
94+
@classmethod
95+
def get_title_generation_user_prompt(cls, context):
96+
"""Get the title generation user prompt."""
97+
return cls.TITLE_GENERATION_USER_PROMPT.format(context=context)

0 commit comments

Comments
 (0)