feat: implement core chatbot engine and prompt builder modules for recommendation system
Browse files
src/recommendation_engine/chatbot_engine.py
CHANGED
|
@@ -14,8 +14,8 @@ from src.recommendation_engine.command_handler import (
|
|
| 14 |
from src.recommendation_engine.idea_generator import generate_ideas
|
| 15 |
from src.recommendation_engine.feature_generator import generate_features
|
| 16 |
|
| 17 |
-
from src.recommendation_engine.llm_client import generate_text
|
| 18 |
-
from src.recommendation_engine.prompt_builder import build_chat_prompt
|
| 19 |
from src.recommendation_engine.response_formatter import format_response
|
| 20 |
from src.recommendation_engine.state_manager import update_state
|
| 21 |
from src.recommendation_engine.context_builder import extract_domain, DOMAIN_KEYWORDS
|
|
@@ -605,7 +605,12 @@ def chatbot(user_id: str, user_input: str):
|
|
| 605 |
"state": state
|
| 606 |
})
|
| 607 |
|
| 608 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
|
| 610 |
elif text == "2":
|
| 611 |
|
|
@@ -1223,23 +1228,34 @@ Choose what you want:
|
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
-
if state.get("
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
|
| 1230 |
-
|
|
|
|
|
|
|
| 1231 |
|
| 1232 |
-
|
| 1233 |
-
# Return hardcoded domain list instead of using LLM
|
| 1234 |
-
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys())
|
| 1235 |
-
response = f"Here are the available domains you can choose from:\n\n{domain_list}"
|
| 1236 |
-
|
| 1237 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 1238 |
-
return finalize_response(user_input, response, history, state, user_id)
|
| 1239 |
|
| 1240 |
detected = extract_domain(user_input)
|
| 1241 |
|
| 1242 |
-
if detected:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1243 |
state["waiting_for_domain"] = False
|
| 1244 |
analysis["domain"] = detected
|
| 1245 |
analysis["intent"] = "idea"
|
|
|
|
| 14 |
from src.recommendation_engine.idea_generator import generate_ideas
|
| 15 |
from src.recommendation_engine.feature_generator import generate_features
|
| 16 |
|
| 17 |
+
from src.recommendation_engine.llm_client import generate_text, generate_list
|
| 18 |
+
from src.recommendation_engine.prompt_builder import build_chat_prompt, build_niche_domains_prompt
|
| 19 |
from src.recommendation_engine.response_formatter import format_response
|
| 20 |
from src.recommendation_engine.state_manager import update_state
|
| 21 |
from src.recommendation_engine.context_builder import extract_domain, DOMAIN_KEYWORDS
|
|
|
|
| 605 |
"state": state
|
| 606 |
})
|
| 607 |
|
| 608 |
+
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys())
|
| 609 |
+
return (
|
| 610 |
+
f"🎯 Here are the available domains:\n\n"
|
| 611 |
+
f"{domain_list}\n\n"
|
| 612 |
+
f"If your domain doesn't match any of these, you can choose 'Others'."
|
| 613 |
+
)
|
| 614 |
|
| 615 |
elif text == "2":
|
| 616 |
|
|
|
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
+
if state.get("waiting_for_niche_domain"):
|
| 1232 |
+
domain = user_input.strip()
|
| 1233 |
+
state["waiting_for_niche_domain"] = False
|
| 1234 |
+
analysis["domain"] = domain
|
| 1235 |
+
analysis["intent"] = "idea"
|
| 1236 |
+
if "project_title" in analysis:
|
| 1237 |
+
del analysis["project_title"]
|
| 1238 |
|
| 1239 |
+
elif state.get("waiting_for_domain"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1240 |
|
| 1241 |
detected = extract_domain(user_input)
|
| 1242 |
|
| 1243 |
+
if detected == "Others":
|
| 1244 |
+
state["waiting_for_domain"] = False
|
| 1245 |
+
state["waiting_for_niche_domain"] = True
|
| 1246 |
+
|
| 1247 |
+
niche_domains = generate_list(build_niche_domains_prompt(), task="idea")
|
| 1248 |
+
|
| 1249 |
+
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1250 |
+
response = (
|
| 1251 |
+
f"You selected 'Others'. Here are some highly niche and cutting-edge domain ideas generated just for you:\n\n"
|
| 1252 |
+
f"{domain_list_str}\n\n"
|
| 1253 |
+
f"Which one would you like to explore? (Or type your own!)"
|
| 1254 |
+
)
|
| 1255 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 1256 |
+
return finalize_response(user_input, response, history, state, user_id)
|
| 1257 |
+
|
| 1258 |
+
elif detected:
|
| 1259 |
state["waiting_for_domain"] = False
|
| 1260 |
analysis["domain"] = detected
|
| 1261 |
analysis["intent"] = "idea"
|
src/recommendation_engine/prompt_builder.py
CHANGED
|
@@ -98,6 +98,19 @@ BAD FEATURE EXAMPLES:
|
|
| 98 |
OUTPUT:
|
| 99 |
""".strip()
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def build_idea_prompt(
|
| 102 |
context: Dict[str, Any],
|
| 103 |
count: int = 10,
|
|
|
|
| 98 |
OUTPUT:
|
| 99 |
""".strip()
|
| 100 |
|
| 101 |
+
def build_niche_domains_prompt() -> str:
|
| 102 |
+
return """
|
| 103 |
+
You are an AI innovation consultant.
|
| 104 |
+
Generate 5 highly niche, unusual, and cutting-edge domains for graduation projects.
|
| 105 |
+
Avoid standard domains like: AI, Machine Learning, Healthcare, Finance, Education, CyberSecurity, Cloud, E-Commerce, IoT.
|
| 106 |
+
Give me just the names of the domains, one per line.
|
| 107 |
+
Keep them concise (2-4 words).
|
| 108 |
+
Example:
|
| 109 |
+
- Quantum Cryptography
|
| 110 |
+
- Deep Sea Robotics
|
| 111 |
+
- Cognitive Brain-Computer Interfaces
|
| 112 |
+
""".strip()
|
| 113 |
+
|
| 114 |
def build_idea_prompt(
|
| 115 |
context: Dict[str, Any],
|
| 116 |
count: int = 10,
|