Tafazzul-Nadeeem commited on
Commit
32553dc
·
1 Parent(s): 2ef477b

Precription feature completed with safeguards

Browse files
Files changed (3) hide show
  1. agents/get_prescription_text_agent.py +2 -0
  2. app.py +15 -8
  3. prompts.py +25 -6
agents/get_prescription_text_agent.py CHANGED
@@ -28,4 +28,6 @@ def get_prescription_text(messages):
28
  messages=cleaned_messages
29
  )
30
  prescription_text = response.choices[0].message.content.strip()
 
 
31
  return prescription_text
 
28
  messages=cleaned_messages
29
  )
30
  prescription_text = response.choices[0].message.content.strip()
31
+ prepend_text = "Lab tests extracted from prescription by the LLM agent: \n"
32
+ prescription_text = prepend_text + prescription_text
33
  return prescription_text
app.py CHANGED
@@ -51,13 +51,17 @@ with gr.Blocks() as demo:
51
  return base64.b64encode(f.read()).decode("utf-8")
52
 
53
  def load_welcome():
54
- return [
55
- {"role": "assistant", "content": bot_welcome_message}
56
- ]
 
57
 
58
  def clear_and_load():
59
  # Return the welcome message
60
- return [{"role": "assistant", "content": bot_welcome_message}], None
 
 
 
61
 
62
  def add_message(history, message):
63
  # Send the image to the agent4_get_prescription_text
@@ -74,9 +78,12 @@ with gr.Blocks() as demo:
74
  "image_url": {"url": f"data:image/jpeg;base64,{encoded_content}"}
75
  })
76
  history.append({"role": "user", "content": {"path": x}})
77
- # call agent4_get_prescription_text to get prescription text
78
- prescription_text = "Extracted lab tests from prescription: \n" + agent4_get_prescription_text(messages)
79
- history.append({"role": "system", "content": prescription_text})
 
 
 
80
 
81
  if message["text"] is not None:
82
  history.append({"role": "user", "content": message["text"]})
@@ -84,6 +91,7 @@ with gr.Blocks() as demo:
84
  return history, gr.MultimodalTextbox(value=None, interactive=False, file_count="multiple", placeholder="Enter message or upload file...")
85
 
86
  def respond(history):
 
87
  if len(history) == 2:
88
  history.insert(0,{"role": "system", "content": openai_opening_system_message})
89
  messages = copy.deepcopy(history)
@@ -108,7 +116,6 @@ with gr.Blocks() as demo:
108
  "content": msg["content"]
109
  }
110
  clean_messages.append(clean_msg)
111
-
112
  ########################### AGENTIC WORKFLOW ##########################
113
  # Call Agent1- the RAG Decision Agent
114
  if clean_messages[-1]["role"] == "system" and "No prescription found" in clean_messages[-1]["content"]:
 
51
  return base64.b64encode(f.read()).decode("utf-8")
52
 
53
  def load_welcome():
54
+ history = []
55
+ history.append({"role": "system", "content": openai_opening_system_message})
56
+ history.append({"role": "assistant", "content": bot_welcome_message})
57
+ return history
58
 
59
  def clear_and_load():
60
  # Return the welcome message
61
+ history = []
62
+ history.append({"role": "system", "content": openai_opening_system_message})
63
+ history.append({"role": "assistant", "content": bot_welcome_message})
64
+ return history, None
65
 
66
  def add_message(history, message):
67
  # Send the image to the agent4_get_prescription_text
 
78
  "image_url": {"url": f"data:image/jpeg;base64,{encoded_content}"}
79
  })
80
  history.append({"role": "user", "content": {"path": x}})
81
+
82
+ # call agent4_get_prescription_text if there is an image_url in the message
83
+ has_image_url = any("image_url" in item for item in messages[0]["content"])
84
+ if has_image_url:
85
+ prescription_text = agent4_get_prescription_text(messages)
86
+ history.append({"role": "system", "content": prescription_text})
87
 
88
  if message["text"] is not None:
89
  history.append({"role": "user", "content": message["text"]})
 
91
  return history, gr.MultimodalTextbox(value=None, interactive=False, file_count="multiple", placeholder="Enter message or upload file...")
92
 
93
  def respond(history):
94
+
95
  if len(history) == 2:
96
  history.insert(0,{"role": "system", "content": openai_opening_system_message})
97
  messages = copy.deepcopy(history)
 
116
  "content": msg["content"]
117
  }
118
  clean_messages.append(clean_msg)
 
119
  ########################### AGENTIC WORKFLOW ##########################
120
  # Call Agent1- the RAG Decision Agent
121
  if clean_messages[-1]["role"] == "system" and "No prescription found" in clean_messages[-1]["content"]:
prompts.py CHANGED
@@ -11,19 +11,38 @@ and may vary from the information provided here.
11
  **Can I help you with anything?**
12
  """
13
  openai_opening_system_message = """"You are a helpful assistant of a diagnostic
14
- services business in an agentic AI framework. Provide the response in markdown format.
15
  The system uses RAG to retrieve relevant information from a knowledge base.
16
- You can also answer questions based on the information provided by the user.
17
- If the user has uploaded an image and an agent has replied in the message that No prescription
18
- found, then just reply "The image does not seem to that of a prescription, please
19
- upload good quality staright images of prescription" and nothing else.
 
 
20
  Do not provide any medical advice or diagnosis.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  """
22
 
23
  prescription_text_user = f"""You are an agent of a Diagnostics Lab agentic AI
24
  Chatbot system using RAG on a knowledge base. Your job is to extract the
25
  lab tests advised by the doctor in the prescription image uploaded by the user.
26
- The user has uploaded an image.
27
  Check if the image contains a medical prescription, if not, just reply
28
  "No prescription found". DO NOT provide any other information about the image
29
  if the image is not a prescription.
 
11
  **Can I help you with anything?**
12
  """
13
  openai_opening_system_message = """"You are a helpful assistant of a diagnostic
14
+ services business in an agentic AI framework.
15
  The system uses RAG to retrieve relevant information from a knowledge base.
16
+ You can also answer questions based on the information provided by the user but
17
+ only regarding the diagnostic services business.
18
+ If the user has uploaded an image and an agent has replied in the message that
19
+ No prescription found, then just reply "The image does not seem like a prescription, please
20
+ upload good quality staright images of prescription without any private information"
21
+ and nothing else.
22
  Do not provide any medical advice or diagnosis.
23
+
24
+ Safeguards:
25
+ 1. If the user uploads a prescription image, and the agent which reads the
26
+ prescription has replied with some tests, then after your reply, always ask if
27
+ you had missed any test.
28
+ 2. Do not provide any information other than the information available in the
29
+ knowledge base, even if the user asks for it.
30
+ 2. If you are giving information about the cost of a test or any offers, always
31
+ mention that the final cost will be available at the time of booking, and may
32
+ vary from the information provided by you.
33
+ 3. If the user asks for a medical advice or diagnosis, politely inform them that
34
+ you are not a medical professional and cannot provide medical advice.
35
+ 4. Do not add Laboratory specific information which is not present in the
36
+ knowledge base. For example, if there is no information about bringing an ID in
37
+ the knowledge base, do not ask users to bring an ID.
38
+ 5. When in doubt, ask user to browse the website or contact customer care.
39
+
40
+ Provide the response in markdown format.
41
  """
42
 
43
  prescription_text_user = f"""You are an agent of a Diagnostics Lab agentic AI
44
  Chatbot system using RAG on a knowledge base. Your job is to extract the
45
  lab tests advised by the doctor in the prescription image uploaded by the user.
 
46
  Check if the image contains a medical prescription, if not, just reply
47
  "No prescription found". DO NOT provide any other information about the image
48
  if the image is not a prescription.