Spaces:
Paused
Paused
Commit
·
5fed273
1
Parent(s):
46ecbc8
updated
Browse files
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 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 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 =
|
| 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 |
-
|
| 255 |
-
|
| 256 |
-
|
| 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])
|