husseinelsaadi commited on
Commit
5fed273
·
1 Parent(s): 46ecbc8
Files changed (1) hide show
  1. backend/services/codingo_chatbot.py +23 -12
backend/services/codingo_chatbot.py CHANGED
@@ -177,13 +177,16 @@ def _build_prompt(query: str, context: str) -> str:
177
  Returns:
178
  A formatted string prompt ready for submission to the Groq LLM.
179
  """
180
- system_prompt = (
181
- "You are LUNA, the friendly AI assistant for the Codingo recruitment "
182
- "platform. You only answer questions using the information provided "
183
- "in the context below. If the context does not contain the answer, "
184
- "respond politely that you don't know. Keep your answers concise and "
185
- "helpful."
186
- )
 
 
 
187
 
188
  if context:
189
  return (
@@ -203,7 +206,7 @@ def _build_prompt(query: str, context: str) -> str:
203
  )
204
 
205
 
206
- def get_response(query: str, k: int = 3, score_threshold: float = 1.5) -> str:
207
  """
208
  Generate a response to the user's query using the shared Groq LLM and the
209
  chatbot's knowledge base. The function retrieves relevant context
@@ -251,10 +254,18 @@ def get_response(query: str, k: int = 3, score_threshold: float = 1.5) -> str:
251
 
252
  # If no relevant context is found, politely admit ignorance
253
  if not relevant:
254
- return (
255
- "I'm sorry, I don't know the answer to that question based on my knowledge. "
256
- "Could you ask something else about Codingo or its services?"
257
- )
 
 
 
 
 
 
 
 
258
 
259
  # Concatenate the most relevant passages for context (use top 2)
260
  context = "\n\n".join(relevant[:2])
 
177
  Returns:
178
  A formatted string prompt ready for submission to the Groq LLM.
179
  """
180
+ system_prompt = """
181
+ You are LUNA, the official AI assistant of Codingo, an AI-powered recruitment platform.
182
+ You must:
183
+ - Answer questions using ONLY the provided context.
184
+ - Be concise, clear, and professional.
185
+ - If the context does not have the answer, politely say you do not know.
186
+ - Never make up features or information not in the context.
187
+ - Always focus on Codingo’s platform, services, and functionality.
188
+ """
189
+
190
 
191
  if context:
192
  return (
 
206
  )
207
 
208
 
209
+ def get_response(query: str, k: int = 3, score_threshold: float = 2.0) -> str:
210
  """
211
  Generate a response to the user's query using the shared Groq LLM and the
212
  chatbot's knowledge base. The function retrieves relevant context
 
254
 
255
  # If no relevant context is found, politely admit ignorance
256
  if not relevant:
257
+ try:
258
+ with open(CHATBOT_TXT_PATH, encoding="utf-8") as f:
259
+ full_context = f.read()
260
+ context = full_context
261
+ except FileNotFoundError:
262
+ return (
263
+ "I'm sorry, I don't know the answer to that question based on my knowledge. "
264
+ "Could you ask something else about Codingo or its services?"
265
+ )
266
+ else:
267
+ context = "\n\n".join(relevant[:2])
268
+
269
 
270
  # Concatenate the most relevant passages for context (use top 2)
271
  context = "\n\n".join(relevant[:2])