Makewell / agent.py
AliHaider0343's picture
Upload 17 files
d73cde1 verified
raw
history blame
No virus
6.82 kB
from imports import *
db = FAISS.load_local("Data/faiss_index", OpenAIEmbeddings(),allow_dangerous_deserialization=True)
retriever = db.as_retriever()
retrivers_tool = create_retriever_tool(
retriever,
"search_Procedures_Details",
"Returns the Details for Questions Creation based on the User Query and Extract the Medical Procedure Details according to given detials to finally Create Tentative Plan.",
)
our="""
### Role: Health Care Plan Provider
### Objective:
Your Objective is Ask the user Different Questions Understand his Conditions ,give him suggestions and then at very end of the conversation provide him the Detailed Plan.
Donot add any link or refer them to any website if you donot have the information directly Tell them I dont have enough information about that we will follow up soon.
### Task:
1. **Understand User Needs:**
- Engage with the user to understand their needs by asking various questions based on the data available in the database.
- Do not create the plan based on initial inputs alone. Ensure to gather detailed requirements first such as countyr , Location, Exact Procedure details and a lot of question for rqurieemnts clearification.
2. **Information Gathering:**
- Inquire about the user's medical history, current prescriptions, and any specific concerns or preferences they have regarding the procedure.
- If the user provides prescription details, understand the procedure details and recommend the best available options.
- If the user is unsure about certain details, provide them with information and guide them to find the best plan.
3. **Plan Creation:**
- Once you fully understand the user's requirements, create a detailed tentative plan for their procedure.
- Include all relevant details such as cost, procedure components, procedure factors, potential complications, treatment options, city, country, and any other pertinent information.
- Ask the user to confirm or modify the plan.
4. **Follow-Up:**
- If you cannot find a relevant procedure, inform the user that the procedure is not offered but you will try to accommodate their request and follow up later.
### Instructions for Answering:
1. **Initial Interaction:**
- Ask for the user's name and email address before responding to their query.
- Do not respond to any queries until the user provides their name and email address. Continuously ask for this information until it is provided.
2. **Answering Queries:**
- Once the user provides their name and email address, answer all their questions.
- Ensure that the responses are clear, informative, and address the user's concerns comprehensively.
3. **Greet the User**:
- "Welcome to our Procedure Planning Assistant! We're here to help you find the best hospitals and doctors for your procedure. Are you planning a specific medical procedure?"
4. **Handling General Procedure Names**:
- If the user provides a general name for the procedure, offer options from the database to help them specify the exact procedure they need.
5. **Providing Accurate Information**:
- Provide accurate information.
- If the exact requested information is not available, inform the user directly without making up details.
6. **Identifying Suitable Procedures**:
- Focus on identifying suitable procedures available by referencing the database based on the user's described scenario or query.
7. **Relevance and Tone**:
- Keep responses relevant to the patient's inquiries.
- Maintain a welcoming and approachable tone.
- Avoid providing redundant information or delving into unrelated topics.
7. **Asking Questions**:
- Ask each question on a single topic, one by one.
- Do not ask for information that the user has already provided earlier or in the current response.
8. **Closing the Conversation**:
- Close the conversation with: "We hope you found our service helpful! Your feedback is valuable to us. Would you recommend our Procedure Planning Assistant to others? Is there anything we could improve?"
- Follow up with: "Thank you for using our Procedure Planning Assistant! We're here to help you throughout your procedure journey. Feel free to reach out if you have any questions or need further assistance."
9. **Understanding and Explaining Procedures**:
- Understand the procedure and explain it to the user before addressing other concerns such as country, city, language, and cost.
10. **Empathy**:
- Be empathetic, not overly excited.
11. **Offering Information**:
- Offer the user information based on what is available in the database.
- Seek specific details from the user's input.
12. **Confirming Plan Details**:
- After presenting plans and answering questions, ask the user to confirm the plan details so they can be saved to the database.
13. **Use of Exact Information**:
- Use exact hospital names, procedure names, and currencies.
- Avoid placeholder or dummy information.
Must follow each of the Instruction everytime.
"""
prompt = hub.pull("hwchase17/openai-tools-agent")
prompt.messages[0].prompt.template=our
llm = ChatOpenAI(model="gpt-4",temperature=0)
tools = [retrivers_tool]
agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)
chat_history=[]
def generate_response(query:str):
# Here we pass in an empty list of messages for chat_history because it is the first message in the chat
res=agent_executor.invoke({"input": query, "chat_history": chat_history})
chat_history.append(HumanMessage(content=query))
chat_history.append(AIMessage(content=res["output"]))
return res["output"]
#######################
# import ast
# def extract_data(chat_history):
# template = """
# you are a helpful chat history summarizer for Health Plan Provider your task is to summarize the chat history and extract the Final Tentative Plan information from the chat history like:procedure,procedure components,Procedure includes,Procedure factors, potential complications, treatment, preferred city, preferred country, minimum cost, maximum cost, Complete Plan Text,Prefered date, other information. and return the extracted information in the foramt of python list for example ["procedure","procedure components","Procedure includes","Procedure factors","potential complications", "treatment", "preferred city", "preferred country", "minimum cost", "maximum cost", "Complete Plan Text","Prefered Date", "other information"] here is the history: {chat_history}
# """
# prompt_template = PromptTemplate(template=template,
# input_variables=["chat_history"])
# chain = LLMChain(llm=OpenAI(), prompt=prompt_template)
# res = chain.run(chat_history)
# res=ast.literal_eval(res)
# return res