Skip to content

Commit 584e3ee

Browse files
committed
Consolidate prompt constants
1 parent ff0bfeb commit 584e3ee

File tree

2 files changed

+69
-47
lines changed

2 files changed

+69
-47
lines changed

server/api/services/prompt_services.py

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ class PromptTemplates:
3131
Return the entire output as a JSON array.
3232
"""
3333

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.
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.
4040
Here's an example of the required response format:
41-
________________________________________
41+
________________________________________
4242
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-
________________________________________
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+
________________________________________
4747
Please provide your response to the user's question following these guidelines precisely.
4848
[PROVIDED-INFO] = {listOfEmbeddings}"""
4949

@@ -95,3 +95,57 @@ def get_title_generation_system_prompt(cls):
9595
def get_title_generation_user_prompt(cls, context):
9696
"""Get the title generation user prompt."""
9797
return cls.TITLE_GENERATION_USER_PROMPT.format(context=context)
98+
99+
# Assistant tool prompts
100+
ASSISTANT_TOOL_DESCRIPTION = """
101+
Search the user's uploaded documents for information relevant to answering their question.
102+
Call this function when you need to find specific information from the user's documents
103+
to provide an accurate, citation-backed response. Always search before answering questions
104+
about document content.
105+
"""
106+
107+
ASSISTANT_TOOL_PROPERTY_DESCRIPTION = """
108+
A specific search query to find relevant information in the user's documents.
109+
Use keywords, phrases, or questions related to what the user is asking about.
110+
Be specific rather than generic - use terms that would appear in the relevant documents.
111+
"""
112+
113+
ASSISTANT_INSTRUCTIONS = """
114+
You are an AI assistant that helps users find and understand information about bipolar disorder
115+
from their uploaded bipolar disorder research documents using semantic search.
116+
117+
SEMANTIC SEARCH STRATEGY:
118+
- Always perform semantic search using the search_documents function when users ask questions
119+
- Use conceptually related terms and synonyms, not just exact keyword matches
120+
- Search for the meaning and context of the user's question, not just literal words
121+
- Consider medical terminology, lay terms, and related conditions when searching
122+
123+
FUNCTION USAGE:
124+
- When a user asks about information that might be in their documents ALWAYS use the search_documents function first
125+
- Perform semantic searches using concepts, symptoms, treatments, and related terms from the user's question
126+
- Only provide answers based on information found through document searches
127+
128+
RESPONSE FORMAT:
129+
After gathering information through semantic searches, provide responses that:
130+
1. Answer the user's question directly using only the found information
131+
2. Structure responses with clear sections and paragraphs
132+
3. Include citations using this exact format: ***[Name {name}, Page {page_number}]***
133+
4. Only cite information that directly supports your statements
134+
135+
If no relevant information is found in the documents, clearly state that the information is not available in the uploaded documents.
136+
"""
137+
138+
@classmethod
139+
def get_assistant_tool_description(cls):
140+
"""Get the assistant tool description."""
141+
return cls.ASSISTANT_TOOL_DESCRIPTION
142+
143+
@classmethod
144+
def get_assistant_tool_property_description(cls):
145+
"""Get the assistant tool property description."""
146+
return cls.ASSISTANT_TOOL_PROPERTY_DESCRIPTION
147+
148+
@classmethod
149+
def get_assistant_instructions(cls):
150+
"""Get the assistant instructions."""
151+
return cls.ASSISTANT_INSTRUCTIONS

server/api/views/assistant/views.py

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from ...services.embedding_services import get_closest_embeddings
1717
from ...services.conversions_services import convert_uuids
18+
from ...services.prompt_services import PromptTemplates
1819

1920
# Configure logging
2021
logger = logging.getLogger(__name__)
@@ -119,18 +120,8 @@ def post(self, request):
119120

120121
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
121122

122-
TOOL_DESCRIPTION = """
123-
Search the user's uploaded documents for information relevant to answering their question.
124-
Call this function when you need to find specific information from the user's documents
125-
to provide an accurate, citation-backed response. Always search before answering questions
126-
about document content.
127-
"""
128-
129-
TOOL_PROPERTY_DESCRIPTION = """
130-
A specific search query to find relevant information in the user's documents.
131-
Use keywords, phrases, or questions related to what the user is asking about.
132-
Be specific rather than generic - use terms that would appear in the relevant documents.
133-
"""
123+
TOOL_DESCRIPTION = PromptTemplates.get_assistant_tool_description()
124+
TOOL_PROPERTY_DESCRIPTION = PromptTemplates.get_assistant_tool_property_description()
134125

135126
tools = [
136127
{
@@ -195,30 +186,7 @@ def search_documents(query: str, user=user) -> str:
195186
except Exception as e:
196187
return f"Error searching documents: {str(e)}. Please try again if the issue persists."
197188

198-
INSTRUCTIONS = """
199-
You are an AI assistant that helps users find and understand information about bipolar disorder
200-
from their uploaded bipolar disorder research documents using semantic search.
201-
202-
SEMANTIC SEARCH STRATEGY:
203-
- Always perform semantic search using the search_documents function when users ask questions
204-
- Use conceptually related terms and synonyms, not just exact keyword matches
205-
- Search for the meaning and context of the user's question, not just literal words
206-
- Consider medical terminology, lay terms, and related conditions when searching
207-
208-
FUNCTION USAGE:
209-
- When a user asks about information that might be in their documents ALWAYS use the search_documents function first
210-
- Perform semantic searches using concepts, symptoms, treatments, and related terms from the user's question
211-
- Only provide answers based on information found through document searches
212-
213-
RESPONSE FORMAT:
214-
After gathering information through semantic searches, provide responses that:
215-
1. Answer the user's question directly using only the found information
216-
2. Structure responses with clear sections and paragraphs
217-
3. Include citations using this exact format: ***[Name {name}, Page {page_number}]***
218-
4. Only cite information that directly supports your statements
219-
220-
If no relevant information is found in the documents, clearly state that the information is not available in the uploaded documents.
221-
"""
189+
INSTRUCTIONS = PromptTemplates.get_assistant_instructions()
222190

223191
MODEL_DEFAULTS = {
224192
"instructions": INSTRUCTIONS,

0 commit comments

Comments
 (0)