Sangyog10 commited on
Commit
339f42a
·
1 Parent(s): f0e36ad

Fixed the RAG with openrouter

Browse files
features/rag_chatbot/rag_pipeline.py CHANGED
@@ -86,11 +86,31 @@ Respond with only the category name (COMPANY, CYBERSECURITY, or OFF_TOPIC):"""
86
  prompt=router_prompt
87
  )
88
 
89
- # Company QA Chain
90
- company_qa_chain = load_qa_chain(llm, chain_type="stuff")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  # Cybersecurity Chain
93
- cybersecurity_template = """You are a cybersecurity expert. Answer the following cybersecurity question based on your knowledge without claiming yourself as expert:
 
 
 
94
 
95
  Question: {question}
96
 
@@ -170,8 +190,11 @@ def route_and_process_query(query: str):
170
  "route": "COMPANY"
171
  }
172
 
173
- # Run the QA chain
174
- answer = company_qa_chain.run(input_documents=docs, question=query)
 
 
 
175
  sources = list(set([doc.metadata.get("source", "Unknown") for doc in docs]))
176
 
177
  return {
 
86
  prompt=router_prompt
87
  )
88
 
89
+ # Custom Company QA Chain with natural prompt
90
+ company_qa_template = """You are a helpful assistant for CyberAlertNepal. Answer the following question about our company using the information provided and links if only available. Give a natural, direct and polite response .
91
+
92
+ Question: {question}
93
+
94
+ Information:
95
+ {context}
96
+
97
+ Answer:"""
98
+
99
+ company_qa_prompt = PromptTemplate(
100
+ input_variables=["question", "context"],
101
+ template=company_qa_template
102
+ )
103
+
104
+ company_qa_chain = LLMChain(
105
+ llm=llm,
106
+ prompt=company_qa_prompt
107
+ )
108
 
109
  # Cybersecurity Chain
110
+ cybersecurity_template = """You are a cybersecurity professional. Answer the following question truthfully and concisely.
111
+ If you are not 100% sure about the answer, simply respond with: "I am not sure about the answer."
112
+ Do not add extra explanations or assumptions. Do not provide false or speculative information.
113
+
114
 
115
  Question: {question}
116
 
 
190
  "route": "COMPANY"
191
  }
192
 
193
+ # Combine document content for context
194
+ context = "\n\n".join([doc.page_content for doc in docs])
195
+
196
+ # Run the custom QA chain
197
+ answer = company_qa_chain.run(question=query, context=context)
198
  sources = list(set([doc.metadata.get("source", "Unknown") for doc in docs]))
199
 
200
  return {