ZunairaHawwar commited on
Commit
3d9a7db
·
verified ·
1 Parent(s): 64a99cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -31
app.py CHANGED
@@ -208,17 +208,18 @@ class EnhancedLangChainRAGSystem:
208
  user = st.session_state.get('current_user')
209
  if user:
210
  user_context = f"""
211
- User Profile Context:
212
- - Name: {user.display_name}
213
- - Experience Level: {user.expertise_level}
214
- - Preferred Languages: {', '.join(user.preferred_languages) if user.preferred_languages else 'None specified'}
215
- - Learning Goals: {user.learning_goals or 'None specified'}
216
-
217
- Please tailor your response to match the user's experience level and preferences.
218
- """
219
  else:
220
  user_context = "User profile not available. Provide general guidance."
221
- return f"""You are an expert assistant for iCodeGuru, a programming education platform.
 
222
  {user_context}
223
 
224
  Use the following context to answer the user's question comprehensively and accurately.
@@ -229,30 +230,28 @@ class EnhancedLangChainRAGSystem:
229
  Chat History: {{chat_history}}
230
  Human: {{question}}"""
231
 
232
- # Part 2 of Enhanced App - RAG System Implementation and Features
233
-
234
- PROMPT = PromptTemplate(
235
- template=get_personalized_prompt(),
236
- input_variables=["context", "chat_history", "question"]
 
 
 
 
237
  )
238
 
239
- try:
240
- retriever = self.vectorstore.as_retriever(
241
- search_type="similarity",
242
- search_kwargs={"k": 4}
243
- )
244
-
245
- self.retrieval_chain = ConversationalRetrievalChain.from_llm(
246
- llm=self.llm,
247
- retriever=retriever,
248
- memory=self.memory,
249
- combine_docs_chain_kwargs={"prompt": PROMPT},
250
- return_source_documents=True,
251
- verbose=False
252
- )
253
-
254
- except Exception as e:
255
- self.retrieval_chain = None
256
 
257
  def load_and_process_documents(self) -> List[Document]:
258
  """Load and process JSON documents from the docs directory."""
 
208
  user = st.session_state.get('current_user')
209
  if user:
210
  user_context = f"""
211
+ User Profile Context:
212
+ - Name: {user.display_name}
213
+ - Experience Level: {user.expertise_level}
214
+ - Preferred Languages: {', '.join(user.preferred_languages) if user.preferred_languages else 'None specified'}
215
+ - Learning Goals: {user.learning_goals or 'None specified'}
216
+
217
+ Please tailor your response to match the user's experience level and preferences.
218
+ """
219
  else:
220
  user_context = "User profile not available. Provide general guidance."
221
+
222
+ return f"""You are an expert assistant for iCodeGuru, a programming education platform.
223
  {user_context}
224
 
225
  Use the following context to answer the user's question comprehensively and accurately.
 
230
  Chat History: {{chat_history}}
231
  Human: {{question}}"""
232
 
233
+ PROMPT = PromptTemplate(
234
+ template=get_personalized_prompt(),
235
+ input_variables=["context", "chat_history", "question"]
236
+ )
237
+
238
+ try:
239
+ retriever = self.vectorstore.as_retriever(
240
+ search_type="similarity",
241
+ search_kwargs={"k": 4}
242
  )
243
 
244
+ self.retrieval_chain = ConversationalRetrievalChain.from_llm(
245
+ llm=self.llm,
246
+ retriever=retriever,
247
+ memory=self.memory,
248
+ combine_docs_chain_kwargs={"prompt": PROMPT},
249
+ return_source_documents=True,
250
+ verbose=False
251
+ )
252
+
253
+ except Exception as e:
254
+ self.retrieval_chain = None
 
 
 
 
 
 
255
 
256
  def load_and_process_documents(self) -> List[Document]:
257
  """Load and process JSON documents from the docs directory."""