Spaces:
Runtime error
Runtime error
feat: add configuration module, response formatting utilities, and initialized project data structure for recommendation engine
Browse files- models/metadata.parquet +2 -2
- src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/config.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc +0 -0
- src/recommendation_engine/chatbot_engine.py +127 -1715
- src/recommendation_engine/config.py +1 -1
- src/recommendation_engine/llm_router.py +99 -38
- src/recommendation_engine/response_formatter.py +5 -8
- src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc +0 -0
models/metadata.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:174627835ae0ebeb76cefa31db3c248d9279d872d2c22798d5dee1dff45f074d
|
| 3 |
+
size 784530
|
src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc and b/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/config.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/config.cpython-313.pyc and b/src/recommendation_engine/__pycache__/config.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc and b/src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc and b/src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc differ
|
|
|
src/recommendation_engine/chatbot_engine.py
CHANGED
|
@@ -88,37 +88,12 @@ REASON: <one sentence why>
|
|
| 88 |
|
| 89 |
|
| 90 |
def extract_number(text: str, default=5):
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
nums = re.findall(r"\d+", text)
|
| 93 |
-
|
| 94 |
return min(int(nums[0]), 20) if nums else default
|
| 95 |
|
| 96 |
-
def classify_input_context(user_input: str) -> str:
|
| 97 |
-
prompt = f"""
|
| 98 |
-
You are an advanced AI assistant classifying user input for a graduation project recommendation engine.
|
| 99 |
-
Analyze the user's input and classify its intent and context into exactly ONE of the following categories:
|
| 100 |
-
|
| 101 |
-
1. greeting: A greeting like "hello", "hi", "hey".
|
| 102 |
-
2. confirmation_yes: A positive response/agreement like "yes", "yeah", "yep", "sure".
|
| 103 |
-
3. confirmation_no: A negative response/disagreement like "no", "nope", "not really", "la".
|
| 104 |
-
4. idea_request: Asking to suggest, recommend, or generate project ideas (e.g., "give me AI ideas", "ideas for healthcare").
|
| 105 |
-
5. feature_request: Asking to generate or suggest features for a project (e.g., "generate features", "suggest features").
|
| 106 |
-
6. full_project_request: Asking to generate a full project specification or complete project (e.g., "generate full project", "complete project").
|
| 107 |
-
7. project_title: Providing a potential graduation project title to start or evaluate (e.g., "Smart hospital system", "AI-based library portal").
|
| 108 |
-
8. general_chat: General questions, questions about coding, concepts, general knowledge, or any explanation requests that are NOT a project title (e.g., "what is front end", "what is graduation project", "explain blockchain", "tell me about world cup", "i want know what is graduation project").
|
| 109 |
-
|
| 110 |
-
User input: "{user_input}"
|
| 111 |
-
|
| 112 |
-
Return ONLY the classification name as a single word from: greeting, confirmation_yes, confirmation_no, idea_request, feature_request, full_project_request, project_title, general_chat.
|
| 113 |
-
Do not include any other text or punctuation.
|
| 114 |
-
"""
|
| 115 |
-
try:
|
| 116 |
-
res = generate_text(prompt, task="intent").strip().lower()
|
| 117 |
-
res = res.split()[0].strip().replace(".", "").replace(",", "")
|
| 118 |
-
return res
|
| 119 |
-
except Exception as e:
|
| 120 |
-
return "general_chat"
|
| 121 |
-
|
| 122 |
def validate_and_format_domain(domain: str) -> str:
|
| 123 |
# 1. Quick local validation for standard domains
|
| 124 |
extracted = extract_domain(domain)
|
|
@@ -511,741 +486,161 @@ def is_general_question_or_unrelated_chat(text: str) -> bool:
|
|
| 511 |
|
| 512 |
return False
|
| 513 |
|
| 514 |
-
def chatbot(user_id: str, user_input: str):
|
| 515 |
|
|
|
|
| 516 |
text = user_input.lower().strip()
|
| 517 |
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
explicit_idea_requests = [
|
| 522 |
-
"idea",
|
| 523 |
-
"new idea",
|
| 524 |
-
"another idea",
|
| 525 |
-
"project idea",
|
| 526 |
-
"give me idea",
|
| 527 |
-
"i want idea",
|
| 528 |
-
"suggest idea",
|
| 529 |
-
"generate idea",
|
| 530 |
-
"generate ideas",
|
| 531 |
-
"give me ideas",
|
| 532 |
-
"i need idea",
|
| 533 |
-
"ideas"
|
| 534 |
-
]
|
| 535 |
-
|
| 536 |
-
memory = get_user_memory(user_id)
|
| 537 |
-
current_state = memory.get("state") or default_state()
|
| 538 |
-
|
| 539 |
-
is_explicit_idea = False
|
| 540 |
-
if text in explicit_idea_requests or text in ["change domain", "new domain", "reset domain", "reset", "restart"]:
|
| 541 |
-
is_explicit_idea = True
|
| 542 |
-
elif any(x in text for x in explicit_idea_requests) and len(text.split()) <= 3 and not current_state.get("project_chat_mode"):
|
| 543 |
-
is_explicit_idea = True
|
| 544 |
-
|
| 545 |
-
if is_explicit_idea:
|
| 546 |
-
if not current_state.get("waiting_for_niche_domain"):
|
| 547 |
-
state = default_state()
|
| 548 |
-
state["waiting_for_domain"] = True
|
| 549 |
-
|
| 550 |
-
save_user_memory(user_id, {
|
| 551 |
-
"history": get_user_memory(user_id).get("history", []),
|
| 552 |
-
"state": state
|
| 553 |
-
})
|
| 554 |
-
|
| 555 |
-
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys() if d != "Others")
|
| 556 |
-
return (
|
| 557 |
-
f"Which domain is your project in? 📚\n\n"
|
| 558 |
-
f"{domain_list}\n\n"
|
| 559 |
-
f"💡 Just type one of the domains above (e.g. **AI** or **Healthcare**)\n"
|
| 560 |
-
f"If your domain isn't listed, type **Others** to see more options."
|
| 561 |
-
)
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
if text in {"1", "2", "3"}:
|
| 567 |
-
pass
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
if is_gibberish_text(text):
|
| 572 |
-
|
| 573 |
-
return (
|
| 574 |
-
"Hmm, I didn't quite catch that 🤔\n\n"
|
| 575 |
-
"Here are some things you can try:\n"
|
| 576 |
-
"- Type **idea** → get graduation project ideas\n"
|
| 577 |
-
"- Type your project title → get smart features\n"
|
| 578 |
-
"- Type **generate full project** → complete project spec\n\n"
|
| 579 |
-
"💡 Tip: Start with **idea** if you're not sure!"
|
| 580 |
-
)
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
if is_command(user_input):
|
| 585 |
return handle_command(user_input)
|
| 586 |
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
memory = get_user_memory(user_id)
|
| 591 |
-
|
| 592 |
history = memory.get("history", [])
|
| 593 |
-
|
| 594 |
state = memory.get("state") or default_state()
|
| 595 |
|
| 596 |
-
#
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
}
|
| 606 |
-
if any(w.lower() in INAPPROPRIATE_KEYWORDS_QUICK for w in words):
|
| 607 |
-
return (
|
| 608 |
-
"I can only help with graduation project topics 🎓\n\n"
|
| 609 |
-
"Please keep it academic! Type **idea** to get started."
|
| 610 |
-
)
|
| 611 |
-
|
| 612 |
-
# Early rejection of unrelated single-word inputs (like 'dia', 'diea') when not in an active flow
|
| 613 |
-
is_in_active_flow = (
|
| 614 |
-
state.get("waiting_for_domain") or
|
| 615 |
-
state.get("waiting_for_niche_domain") or
|
| 616 |
-
state.get("waiting_for_full_project_domain") or
|
| 617 |
-
state.get("waiting_for_full_project_selection") or
|
| 618 |
-
state.get("waiting_for_feature_title") or
|
| 619 |
-
state.get("waiting_for_title_confirmation") or
|
| 620 |
-
state.get("waiting_for_project_idea_confirm") or
|
| 621 |
-
state.get("weak_title_candidate")
|
| 622 |
-
)
|
| 623 |
|
| 624 |
-
if
|
| 625 |
-
if
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
"idea", "ideas", "suggest", "generate", "others", "other",
|
| 630 |
-
"exit", "quit", "clear", "reset", "restart", "change", "new", "discuss", "features", "feature", "chat",
|
| 631 |
-
"1", "2", "3"
|
| 632 |
-
}
|
| 633 |
-
for d, d_words in DOMAIN_KEYWORDS.items():
|
| 634 |
-
allowed_single_words.add(d.lower())
|
| 635 |
-
for w in d_words:
|
| 636 |
-
allowed_single_words.update(w.lower().split())
|
| 637 |
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
"📝 Your project title seems too short!\n\n"
|
| 648 |
-
"A good graduation project title should be descriptive. For example:\n"
|
| 649 |
-
"- AI-powered smart library recommendation system\n"
|
| 650 |
-
"- Smart hospital emergency response platform\n"
|
| 651 |
-
"- Blockchain-secured academic certificate verification\n\n"
|
| 652 |
-
"Please enter a more descriptive title.\n\n"
|
| 653 |
-
"💡 Or type **idea** to browse ready-made project ideas!"
|
| 654 |
-
)
|
| 655 |
-
|
| 656 |
-
state.setdefault("waiting_for_title_confirmation", False)
|
| 657 |
-
state.setdefault("pending_title", None)
|
| 658 |
-
|
| 659 |
-
context = classify_input_context(user_input)
|
| 660 |
-
|
| 661 |
-
# Intercept general questions / unrelated chat if no project is active yet
|
| 662 |
-
is_in_domain_or_selection_state = (
|
| 663 |
-
state.get("waiting_for_domain") or
|
| 664 |
-
state.get("waiting_for_niche_domain") or
|
| 665 |
-
state.get("waiting_for_full_project_domain") or
|
| 666 |
-
state.get("waiting_for_full_project_selection") or
|
| 667 |
-
state.get("waiting_for_feature_title") or
|
| 668 |
-
state.get("weak_title_candidate")
|
| 669 |
-
)
|
| 670 |
-
|
| 671 |
-
if not state.get("project_title") and not state.get("waiting_for_title_confirmation"):
|
| 672 |
-
should_intercept = False
|
| 673 |
-
if is_general_question_or_unrelated_chat(user_input):
|
| 674 |
-
should_intercept = True
|
| 675 |
-
elif context == "general_chat" and not is_in_domain_or_selection_state:
|
| 676 |
-
should_intercept = True
|
| 677 |
-
|
| 678 |
-
if should_intercept:
|
| 679 |
-
if context not in ["greeting", "confirmation_yes", "confirmation_no", "idea_request", "feature_request", "full_project_request"]:
|
| 680 |
-
# ── Content Safety Pre-Filter ──────────────────────────────────
|
| 681 |
-
# Reject clearly inappropriate/vulgar inputs before asking confirmation
|
| 682 |
-
INAPPROPRIATE_KEYWORDS = {
|
| 683 |
-
"fuck", "shit", "bitch", "ass", "dick", "cock", "pussy",
|
| 684 |
-
"porn", "sex", "naked", "nude", "rape", "kill", "murder",
|
| 685 |
-
"bastard", "whore", "slut", "cunt", "nigga", "nigger",
|
| 686 |
-
"idiot", "stupid", "dumb", "hate"
|
| 687 |
-
}
|
| 688 |
-
input_words = set(user_input.lower().split())
|
| 689 |
-
if input_words & INAPPROPRIATE_KEYWORDS:
|
| 690 |
-
save_user_memory(user_id, {
|
| 691 |
-
"history": history,
|
| 692 |
-
"state": state
|
| 693 |
-
})
|
| 694 |
-
return (
|
| 695 |
-
"I can only help with graduation project topics 🎓\n\n"
|
| 696 |
-
"Please keep it academic! Try:\n"
|
| 697 |
-
"- Type **idea** to browse project ideas\n"
|
| 698 |
-
"- Type a real project title to get features"
|
| 699 |
-
)
|
| 700 |
-
# ──────────────────────────────────────────────────────────────
|
| 701 |
-
state["waiting_for_title_confirmation"] = True
|
| 702 |
-
state["pending_title"] = user_input.strip()
|
| 703 |
-
save_user_memory(user_id, {
|
| 704 |
-
"history": history,
|
| 705 |
-
"state": state
|
| 706 |
-
})
|
| 707 |
-
return (
|
| 708 |
-
f"Just to confirm — is this your graduation project title?\n\n"
|
| 709 |
-
f"📝 \"{user_input.strip()}\"\n\n"
|
| 710 |
-
"Reply **yes** to continue with it, or **no** to go back."
|
| 711 |
-
)
|
| 712 |
-
|
| 713 |
-
YES_WORDS = {"yes", "yep", "yeah", "sure", "y", "ok", "okay", "correct", "right", "yup", "of course", "absolutely"}
|
| 714 |
-
NO_WORDS = {"no", "nope", "n", "nah", "not really", "la", "negative"}
|
| 715 |
-
|
| 716 |
-
# ── Handle: User confirms the generated project idea ──────────────────────
|
| 717 |
-
if state.get("waiting_for_project_idea_confirm"):
|
| 718 |
-
raw_lower = user_input.strip().lower()
|
| 719 |
-
is_yes = context == "confirmation_yes" or raw_lower in YES_WORDS
|
| 720 |
-
is_no = context == "confirmation_no" or raw_lower in NO_WORDS
|
| 721 |
-
|
| 722 |
-
state["waiting_for_project_idea_confirm"] = False
|
| 723 |
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
title = state.get("project_title", "")
|
| 731 |
-
abstract = state.get("abstract", "")
|
| 732 |
-
|
| 733 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 734 |
-
|
| 735 |
-
validation = validate_and_categorize_project(title, abstract)
|
| 736 |
-
|
| 737 |
-
if validation["is_valid"]:
|
| 738 |
-
domain = validation.get("domain")
|
| 739 |
-
if domain:
|
| 740 |
-
state["domain"] = domain
|
| 741 |
-
state["category"] = domain
|
| 742 |
-
domain_line = f"📂 Domain: **{domain}**" if domain else "📂 Domain: (could not classify — please specify)"
|
| 743 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 744 |
-
return (
|
| 745 |
-
f"✅ Great choice! Your project idea has been validated and categorized.\n\n"
|
| 746 |
-
f"📌 Title: {title}\n"
|
| 747 |
-
f"{domain_line}\n\n"
|
| 748 |
-
f"What would you like to do next?\n"
|
| 749 |
-
f"1️⃣ Generate features\n\n"
|
| 750 |
-
f"👉 You can also say:\n"
|
| 751 |
-
f"- generate features"
|
| 752 |
-
)
|
| 753 |
else:
|
| 754 |
-
reason = validation.get("reason", "")
|
| 755 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 756 |
-
return (
|
| 757 |
-
f"❌ Hmm, this doesn't seem like a valid graduation project idea.\n\n"
|
| 758 |
-
f"{'Reason: ' + reason + chr(10) + chr(10) if reason else ''}"
|
| 759 |
-
f"💡 Try typing **idea** to browse real project ideas, or enter a proper project title."
|
| 760 |
-
)
|
| 761 |
-
|
| 762 |
-
elif is_no:
|
| 763 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 764 |
-
return (
|
| 765 |
-
"No problem! 😊\n\n"
|
| 766 |
-
"Type **idea** to start fresh with new project ideas, or paste a different project title anytime."
|
| 767 |
-
)
|
| 768 |
-
|
| 769 |
-
else:
|
| 770 |
-
# Re-ask
|
| 771 |
-
state["waiting_for_project_idea_confirm"] = True
|
| 772 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 773 |
-
return (
|
| 774 |
-
f"Just checking — would you like to use this as your graduation project idea?\n\n"
|
| 775 |
-
f"📌 \"{state.get('project_title')}\"\n\n"
|
| 776 |
-
"Reply **yes** to confirm and categorize it, or **no** to try something else."
|
| 777 |
-
)
|
| 778 |
-
|
| 779 |
-
if state.get("waiting_for_title_confirmation"):
|
| 780 |
-
raw_lower = user_input.strip().lower()
|
| 781 |
-
|
| 782 |
-
# Reliable raw-text check first — don't fully trust LLM classification for yes/no
|
| 783 |
-
is_yes = context == "confirmation_yes" or raw_lower in YES_WORDS
|
| 784 |
-
is_no = context == "confirmation_no" or raw_lower in NO_WORDS
|
| 785 |
-
|
| 786 |
-
if is_yes:
|
| 787 |
-
project_title = state.get("pending_title", "")
|
| 788 |
-
state["waiting_for_title_confirmation"] = False
|
| 789 |
-
state["pending_title"] = None
|
| 790 |
-
|
| 791 |
-
# Validate the title is actually a real graduation project idea
|
| 792 |
-
validation = validate_and_categorize_project(project_title)
|
| 793 |
-
|
| 794 |
-
if not validation["is_valid"]:
|
| 795 |
-
reason = validation.get("reason", "")
|
| 796 |
-
state["waiting_for_title_confirmation"] = False
|
| 797 |
-
save_user_memory(user_id, {
|
| 798 |
-
"history": history,
|
| 799 |
-
"state": state
|
| 800 |
-
})
|
| 801 |
-
return (
|
| 802 |
-
f"❌ That doesn't look like a valid graduation project title.\n\n"
|
| 803 |
-
f"{'Reason: ' + reason + chr(10) + chr(10) if reason else ''}"
|
| 804 |
-
f"💡 Try typing **idea** to browse real project ideas, or enter a proper project title like:\n"
|
| 805 |
-
f" AI-powered smart library recommendation system"
|
| 806 |
-
)
|
| 807 |
-
|
| 808 |
-
domain = validation.get("domain")
|
| 809 |
-
state = default_state()
|
| 810 |
-
state["project_title"] = project_title
|
| 811 |
-
state["waiting_for_project_action"] = True
|
| 812 |
-
if domain:
|
| 813 |
state["domain"] = domain
|
| 814 |
-
state["
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
f"
|
| 824 |
-
f"{
|
| 825 |
-
"
|
| 826 |
-
"
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
"- generate features\n"
|
| 830 |
-
"- generate full project"
|
| 831 |
-
)
|
| 832 |
-
|
| 833 |
-
elif is_no:
|
| 834 |
-
state["waiting_for_title_confirmation"] = False
|
| 835 |
-
state["pending_title"] = None
|
| 836 |
-
save_user_memory(user_id, {
|
| 837 |
-
"history": history,
|
| 838 |
-
"state": state
|
| 839 |
-
})
|
| 840 |
-
return (
|
| 841 |
-
"No problem! 😊\n\n"
|
| 842 |
-
"I'm here to help with graduation projects. Try:\n"
|
| 843 |
-
"- Type **idea** to get project ideas\n"
|
| 844 |
-
"- Paste your project title to get features\n"
|
| 845 |
-
"- Type **generate full project** for a complete spec"
|
| 846 |
-
)
|
| 847 |
|
| 848 |
-
|
| 849 |
-
state["waiting_for_title_confirmation"] = False
|
| 850 |
-
state["pending_title"] = None
|
| 851 |
-
|
| 852 |
-
else:
|
| 853 |
-
# Still waiting — re-ask clearly
|
| 854 |
-
pending = state.get("pending_title", "")
|
| 855 |
-
save_user_memory(user_id, {
|
| 856 |
-
"history": history,
|
| 857 |
-
"state": state
|
| 858 |
-
})
|
| 859 |
-
return (
|
| 860 |
-
f"Just to confirm — is this your graduation project title?\n\n"
|
| 861 |
-
f"📝 \"{pending}\"\n\n"
|
| 862 |
-
"Reply **yes** to continue with it, or **no** to go back."
|
| 863 |
-
)
|
| 864 |
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
state.setdefault("project_chat_mode", False)
|
| 871 |
-
state.setdefault("last_action", None)
|
| 872 |
-
state.setdefault("domain", None)
|
| 873 |
-
state.setdefault("weak_title_candidate", None)
|
| 874 |
-
state.setdefault("waiting_for_feature_title", False)
|
| 875 |
-
state.setdefault("waiting_for_full_project_domain", False)
|
| 876 |
-
state.setdefault("waiting_for_full_project_selection", False)
|
| 877 |
-
state.setdefault("suggested_domains", [])
|
| 878 |
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
save_user_memory(user_id, {
|
| 885 |
-
"history": history,
|
| 886 |
-
"state": state
|
| 887 |
-
})
|
| 888 |
-
|
| 889 |
-
return (
|
| 890 |
-
"👋 Welcome! I'm your Graduation Project Assistant 🎓\n\n"
|
| 891 |
-
"Here's how to get started:\n"
|
| 892 |
-
"1️⃣ Type **idea** → I'll suggest graduation project ideas by domain\n"
|
| 893 |
-
"2️⃣ Type your project title → I'll generate smart features for it\n"
|
| 894 |
-
"3️⃣ Type **generate full project** → get a complete project specification\n\n"
|
| 895 |
-
"✨ Not sure? Just type **idea** and I'll guide you step by step!"
|
| 896 |
)
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
if any(x in text for x in [
|
| 901 |
-
|
| 902 |
-
"generate full project",
|
| 903 |
-
"final project",
|
| 904 |
-
"complete project",
|
| 905 |
-
"full graduation project",
|
| 906 |
-
"all fields",
|
| 907 |
-
"fields"
|
| 908 |
|
| 909 |
-
|
| 910 |
|
|
|
|
|
|
|
|
|
|
| 911 |
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
feature_result = generate_features(
|
| 920 |
-
|
| 921 |
-
title=state.get("project_title"),
|
| 922 |
-
|
| 923 |
-
description=state.get("description", ""),
|
| 924 |
-
|
| 925 |
-
features=[],
|
| 926 |
-
|
| 927 |
-
previous_generated_features=[],
|
| 928 |
-
|
| 929 |
-
top_k=8
|
| 930 |
-
)
|
| 931 |
-
|
| 932 |
-
state["features"] = feature_result.get(
|
| 933 |
-
"recommended_features",
|
| 934 |
-
[]
|
| 935 |
-
)
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
result = generate_full_project(
|
| 939 |
-
|
| 940 |
-
title=state.get("project_title"),
|
| 941 |
-
|
| 942 |
-
features=state.get("features", []),
|
| 943 |
-
|
| 944 |
-
description=state.get("description", ""),
|
| 945 |
-
|
| 946 |
-
abstract=state.get("abstract", "")
|
| 947 |
-
)
|
| 948 |
-
|
| 949 |
-
state = update_state(
|
| 950 |
-
state,
|
| 951 |
-
result,
|
| 952 |
-
mode="merge"
|
| 953 |
-
)
|
| 954 |
-
if state.get("domain"):
|
| 955 |
-
state["category"] = state.get("domain")
|
| 956 |
-
|
| 957 |
-
state["waiting_for_project_idea_confirm"] = True
|
| 958 |
-
state["from_full_project_generation"] = True
|
| 959 |
-
|
| 960 |
-
response = f"""
|
| 961 |
-
📦 Full Project Generated
|
| 962 |
-
|
| 963 |
-
📌 Project Title:
|
| 964 |
-
{state.get("project_title")}
|
| 965 |
-
|
| 966 |
-
📂 Category:
|
| 967 |
-
{state.get("category")}
|
| 968 |
-
|
| 969 |
-
🛠 Technologies:
|
| 970 |
-
{", ".join(state.get("technologies", []))}
|
| 971 |
-
|
| 972 |
-
📄 Abstract:
|
| 973 |
-
{state.get("abstract")}
|
| 974 |
-
|
| 975 |
-
📄 Detailed Description:
|
| 976 |
-
{state.get("description")}
|
| 977 |
-
|
| 978 |
-
❗ Problem Statement:
|
| 979 |
-
{state.get("problem_statement")}
|
| 980 |
-
|
| 981 |
-
💡 Proposed Solution:
|
| 982 |
-
{state.get("proposed_solution")}
|
| 983 |
|
| 984 |
-
|
| 985 |
-
|
| 986 |
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
"""
|
| 991 |
|
|
|
|
| 992 |
return finalize_response(
|
| 993 |
user_input,
|
| 994 |
-
|
| 995 |
history,
|
| 996 |
state,
|
| 997 |
user_id
|
| 998 |
)
|
| 999 |
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
state["waiting_for_full_project_domain"] = True
|
| 1004 |
-
|
| 1005 |
-
save_user_memory(user_id, {
|
| 1006 |
-
"history": history,
|
| 1007 |
-
"state": state
|
| 1008 |
-
})
|
| 1009 |
-
|
| 1010 |
-
return (
|
| 1011 |
-
"🎯 What domain should the full project be in?\n\n"
|
| 1012 |
-
"Just type one, for example:\n"
|
| 1013 |
-
"- AI\n"
|
| 1014 |
-
"- Healthcare\n"
|
| 1015 |
-
"- Education\n"
|
| 1016 |
-
"- Fintech\n"
|
| 1017 |
-
"- Cybersecurity"
|
| 1018 |
-
)
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
if state.get("menu_mode"):
|
| 1023 |
-
|
| 1024 |
-
if text in ["1", "2", "3"]:
|
| 1025 |
-
|
| 1026 |
-
state["menu_mode"] = False
|
| 1027 |
-
state["selected_option"] = text
|
| 1028 |
-
|
| 1029 |
-
if text == "1":
|
| 1030 |
-
|
| 1031 |
-
state["waiting_for_domain"] = True
|
| 1032 |
-
|
| 1033 |
-
save_user_memory(user_id, {
|
| 1034 |
-
"history": history,
|
| 1035 |
-
"state": state
|
| 1036 |
-
})
|
| 1037 |
-
|
| 1038 |
-
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys() if d != "Others")
|
| 1039 |
-
return (
|
| 1040 |
-
f"Which domain is your project in? 📚\n\n"
|
| 1041 |
-
f"{domain_list}\n\n"
|
| 1042 |
-
f"💡 Just type one of the domains above (e.g. **AI** or **Healthcare**)\n"
|
| 1043 |
-
f"If your domain isn't listed, type **Others** to see more options."
|
| 1044 |
-
)
|
| 1045 |
-
|
| 1046 |
-
elif text == "2":
|
| 1047 |
-
|
| 1048 |
-
if not state.get("project_title"):
|
| 1049 |
-
|
| 1050 |
-
state["waiting_for_feature_title"] = True
|
| 1051 |
-
|
| 1052 |
-
save_user_memory(user_id, {
|
| 1053 |
-
"history": history,
|
| 1054 |
-
"state": state
|
| 1055 |
-
})
|
| 1056 |
-
|
| 1057 |
-
return (
|
| 1058 |
-
"I need a project title first! 📝\n\n"
|
| 1059 |
-
"Type your project title and I'll generate features for it.\n"
|
| 1060 |
-
"Example:\n"
|
| 1061 |
-
" AI-powered smart library recommendation system\n\n"
|
| 1062 |
-
"💡 Or type **idea** if you'd like me to suggest one!"
|
| 1063 |
-
)
|
| 1064 |
-
|
| 1065 |
-
save_user_memory(user_id, {
|
| 1066 |
-
"history": history,
|
| 1067 |
-
"state": state
|
| 1068 |
-
})
|
| 1069 |
-
|
| 1070 |
-
return chatbot(user_id, "generate features")
|
| 1071 |
-
|
| 1072 |
-
elif text == "3":
|
| 1073 |
-
|
| 1074 |
-
if not state.get("project_title"):
|
| 1075 |
-
|
| 1076 |
-
return (
|
| 1077 |
-
"⚠️ Please generate or provide "
|
| 1078 |
-
"a project idea first."
|
| 1079 |
-
)
|
| 1080 |
-
|
| 1081 |
-
state["project_chat_mode"] = True
|
| 1082 |
-
|
| 1083 |
-
save_user_memory(user_id, {
|
| 1084 |
-
"history": history,
|
| 1085 |
-
"state": state
|
| 1086 |
-
})
|
| 1087 |
-
|
| 1088 |
-
return (
|
| 1089 |
-
f"💬 Project discussion mode enabled for:\n"
|
| 1090 |
-
f"{state.get('project_title')}"
|
| 1091 |
-
)
|
| 1092 |
-
|
| 1093 |
-
state["menu_mode"] = False
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
|
| 1097 |
-
|
| 1098 |
-
if state.get("waiting_for_project_action"):
|
| 1099 |
-
|
| 1100 |
-
feature_words = [
|
| 1101 |
-
"1",
|
| 1102 |
-
"feature",
|
| 1103 |
-
"features",
|
| 1104 |
-
"generate features",
|
| 1105 |
-
"add features",
|
| 1106 |
-
"create features"
|
| 1107 |
-
]
|
| 1108 |
-
|
| 1109 |
-
chat_words = [
|
| 1110 |
-
"chat",
|
| 1111 |
-
"talk",
|
| 1112 |
-
"discussion",
|
| 1113 |
-
"discuss",
|
| 1114 |
-
"improve",
|
| 1115 |
-
"improve idea",
|
| 1116 |
-
"talk about project"
|
| 1117 |
-
]
|
| 1118 |
-
|
| 1119 |
-
full_project_words = [
|
| 1120 |
-
"2",
|
| 1121 |
-
"full project",
|
| 1122 |
-
"generate full project",
|
| 1123 |
-
"complete project",
|
| 1124 |
-
"final project"
|
| 1125 |
-
]
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
if any(w in text for w in feature_words):
|
| 1131 |
-
|
| 1132 |
-
state["waiting_for_project_action"] = False
|
| 1133 |
-
|
| 1134 |
-
save_user_memory(user_id, {
|
| 1135 |
-
"history": history,
|
| 1136 |
-
"state": state
|
| 1137 |
-
})
|
| 1138 |
-
|
| 1139 |
-
return chatbot(user_id, "generate features")
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
elif any(w in text for w in chat_words):
|
| 1145 |
-
|
| 1146 |
-
state["waiting_for_project_action"] = False
|
| 1147 |
-
|
| 1148 |
-
state["project_chat_mode"] = True
|
| 1149 |
-
|
| 1150 |
-
save_user_memory(user_id, {
|
| 1151 |
-
"history": history,
|
| 1152 |
-
"state": state
|
| 1153 |
-
})
|
| 1154 |
-
|
| 1155 |
-
return (
|
| 1156 |
-
f"💬 Let's talk about your project!\n\n"
|
| 1157 |
-
f"📌 {state.get('project_title')}\n\n"
|
| 1158 |
-
"Ask me anything — how to improve it, what technologies to use,\n"
|
| 1159 |
-
"or any questions about the idea. I'm here to help! 🚀"
|
| 1160 |
-
)
|
| 1161 |
-
|
| 1162 |
-
|
| 1163 |
-
|
| 1164 |
-
|
| 1165 |
-
if any(w in text for w in feature_words):
|
| 1166 |
-
|
| 1167 |
-
state["waiting_for_project_action"] = False
|
| 1168 |
-
|
| 1169 |
-
save_user_memory(user_id, {
|
| 1170 |
-
"history": history,
|
| 1171 |
-
"state": state
|
| 1172 |
-
})
|
| 1173 |
-
|
| 1174 |
-
return chatbot(user_id, "generate features")
|
| 1175 |
-
|
| 1176 |
-
|
| 1177 |
-
|
| 1178 |
-
|
| 1179 |
-
elif any(w in text for w in chat_words):
|
| 1180 |
-
|
| 1181 |
-
state["waiting_for_project_action"] = False
|
| 1182 |
-
|
| 1183 |
-
state["project_chat_mode"] = True
|
| 1184 |
|
| 1185 |
-
|
| 1186 |
-
|
| 1187 |
-
|
| 1188 |
-
|
|
|
|
| 1189 |
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
-
|
| 1195 |
-
|
|
|
|
| 1196 |
|
|
|
|
| 1197 |
|
| 1198 |
-
|
| 1199 |
-
|
| 1200 |
-
|
| 1201 |
-
|
| 1202 |
-
state["waiting_for_project_action"] = False
|
| 1203 |
-
|
| 1204 |
-
|
| 1205 |
-
if not state.get("features"):
|
| 1206 |
-
|
| 1207 |
-
feature_result = generate_features(
|
| 1208 |
-
|
| 1209 |
-
title=state.get("project_title"),
|
| 1210 |
-
|
| 1211 |
-
description=state.get("description", ""),
|
| 1212 |
-
|
| 1213 |
-
features=[],
|
| 1214 |
-
|
| 1215 |
-
previous_generated_features=[],
|
| 1216 |
-
|
| 1217 |
-
top_k=8
|
| 1218 |
-
)
|
| 1219 |
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
[]
|
| 1223 |
-
)
|
| 1224 |
|
|
|
|
|
|
|
|
|
|
| 1225 |
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
title=state.get("project_title"),
|
| 1229 |
-
|
| 1230 |
-
features=state.get("features", []),
|
| 1231 |
-
|
| 1232 |
description=state.get("description", ""),
|
| 1233 |
-
|
| 1234 |
-
|
|
|
|
| 1235 |
)
|
|
|
|
| 1236 |
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
)
|
| 1242 |
-
|
| 1243 |
-
state["category"] = state.get("domain")
|
| 1244 |
|
| 1245 |
-
|
| 1246 |
-
|
|
|
|
| 1247 |
|
| 1248 |
-
|
| 1249 |
📦 Full Project Generated
|
| 1250 |
|
| 1251 |
📌 Project Title:
|
|
@@ -1272,1005 +667,22 @@ Reply **yes** to validate & categorize it, or **no** to explore other ideas.
|
|
| 1272 |
🎯 Objectives:
|
| 1273 |
{chr(10).join("- " + x for x in state.get("objectives", []))}
|
| 1274 |
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
Reply **yes** to validate & categorize it, or **no** to explore other ideas.
|
| 1278 |
"""
|
| 1279 |
-
|
| 1280 |
-
return finalize_response(
|
| 1281 |
-
user_input,
|
| 1282 |
-
response,
|
| 1283 |
-
history,
|
| 1284 |
-
state,
|
| 1285 |
-
user_id
|
| 1286 |
-
)
|
| 1287 |
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
-
if state.get("waiting_for_feature_title"):
|
| 1297 |
-
|
| 1298 |
-
state["waiting_for_feature_title"] = False
|
| 1299 |
-
|
| 1300 |
-
possible_title = user_input.strip()
|
| 1301 |
-
|
| 1302 |
-
if not looks_like_real_project_title(possible_title):
|
| 1303 |
-
state["waiting_for_title_confirmation"] = True
|
| 1304 |
-
state["pending_title"] = possible_title
|
| 1305 |
-
save_user_memory(user_id, {
|
| 1306 |
-
"history": history,
|
| 1307 |
-
"state": state
|
| 1308 |
-
})
|
| 1309 |
-
return (
|
| 1310 |
-
f"Just to confirm — is this your graduation project title?\n\n"
|
| 1311 |
-
f"📝 \"{possible_title}\"\n\n"
|
| 1312 |
-
"Reply **yes** to continue with it, or **no** to type a different title."
|
| 1313 |
-
)
|
| 1314 |
-
|
| 1315 |
-
if is_weak_project_title(possible_title):
|
| 1316 |
-
|
| 1317 |
-
state["weak_title_candidate"] = possible_title
|
| 1318 |
-
|
| 1319 |
-
save_user_memory(user_id, {
|
| 1320 |
-
"history": history,
|
| 1321 |
-
"state": state
|
| 1322 |
-
})
|
| 1323 |
-
|
| 1324 |
-
return (
|
| 1325 |
-
"⚠️ Your project title is too short or unclear.\n\n"
|
| 1326 |
-
"Examples:\n"
|
| 1327 |
-
"- AI-powered smart library recommendation system\n"
|
| 1328 |
-
"- Smart hospital emergency response platform\n\n"
|
| 1329 |
-
"Please enter a more descriptive title."
|
| 1330 |
-
)
|
| 1331 |
-
|
| 1332 |
-
|
| 1333 |
-
state["project_title"] = possible_title
|
| 1334 |
-
|
| 1335 |
-
save_user_memory(user_id, {
|
| 1336 |
-
"history": history,
|
| 1337 |
-
"state": state
|
| 1338 |
-
})
|
| 1339 |
-
|
| 1340 |
-
return chatbot(user_id, "generate features")
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
feature_patterns = [
|
| 1346 |
-
|
| 1347 |
-
"generate features for",
|
| 1348 |
-
"generate feature for",
|
| 1349 |
-
"features for",
|
| 1350 |
-
"feature for",
|
| 1351 |
-
"create features for",
|
| 1352 |
-
"suggest features for",
|
| 1353 |
-
|
| 1354 |
-
|
| 1355 |
-
"give me features for",
|
| 1356 |
-
"show features for",
|
| 1357 |
-
"i need features for",
|
| 1358 |
-
"can you generate features for",
|
| 1359 |
-
"can you suggest features for",
|
| 1360 |
-
|
| 1361 |
-
|
| 1362 |
-
"add features to",
|
| 1363 |
-
"improve features for",
|
| 1364 |
-
"feature ideas for",
|
| 1365 |
-
"smart features for",
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
"features:",
|
| 1369 |
-
"project:",
|
| 1370 |
-
"idea:",
|
| 1371 |
-
|
| 1372 |
-
|
| 1373 |
-
"gen features for",
|
| 1374 |
-
"generate faetures for",
|
| 1375 |
-
"fetures for",
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
"make features for",
|
| 1379 |
-
"build features for",
|
| 1380 |
-
"what features for",
|
| 1381 |
-
"best features for",
|
| 1382 |
-
|
| 1383 |
-
|
| 1384 |
-
"i have project",
|
| 1385 |
-
"my project is",
|
| 1386 |
-
"project title is",
|
| 1387 |
-
]
|
| 1388 |
-
|
| 1389 |
-
analysis = None
|
| 1390 |
-
|
| 1391 |
-
for pattern in feature_patterns:
|
| 1392 |
-
|
| 1393 |
-
if text.startswith(pattern + " "):
|
| 1394 |
-
|
| 1395 |
-
extracted_title = user_input.split(
|
| 1396 |
-
pattern, 1
|
| 1397 |
-
)[1].strip()
|
| 1398 |
-
|
| 1399 |
-
if (
|
| 1400 |
-
extracted_title
|
| 1401 |
-
and not is_generic_project_reference(extracted_title)
|
| 1402 |
-
):
|
| 1403 |
-
|
| 1404 |
-
analysis = {
|
| 1405 |
-
"intent": "feature",
|
| 1406 |
-
"project_title": extracted_title
|
| 1407 |
-
}
|
| 1408 |
-
|
| 1409 |
-
break
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
if analysis is None:
|
| 1415 |
-
|
| 1416 |
-
blocked_starts = (
|
| 1417 |
-
"how ",
|
| 1418 |
-
"what ",
|
| 1419 |
-
"why ",
|
| 1420 |
-
"when ",
|
| 1421 |
-
"where ",
|
| 1422 |
-
"can ",
|
| 1423 |
-
"could ",
|
| 1424 |
-
"should ",
|
| 1425 |
-
"is ",
|
| 1426 |
-
"are ",
|
| 1427 |
-
"do ",
|
| 1428 |
-
"does ",
|
| 1429 |
-
"help ",
|
| 1430 |
-
)
|
| 1431 |
-
action_words = {
|
| 1432 |
-
"generate",
|
| 1433 |
-
"create",
|
| 1434 |
-
"suggest",
|
| 1435 |
-
"give",
|
| 1436 |
-
"show",
|
| 1437 |
-
"make",
|
| 1438 |
-
"build",
|
| 1439 |
-
"improve",
|
| 1440 |
-
"discuss",
|
| 1441 |
-
"help",
|
| 1442 |
-
"recommend",
|
| 1443 |
-
"need"
|
| 1444 |
-
}
|
| 1445 |
-
|
| 1446 |
-
command_phrases = {
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
"new idea",
|
| 1450 |
-
"another idea",
|
| 1451 |
-
"generate idea",
|
| 1452 |
-
"generate ideas",
|
| 1453 |
-
"project ideas",
|
| 1454 |
-
"more ideas",
|
| 1455 |
-
"idea",
|
| 1456 |
-
|
| 1457 |
-
|
| 1458 |
-
"generate features",
|
| 1459 |
-
"generate feature",
|
| 1460 |
-
"more features",
|
| 1461 |
-
"features",
|
| 1462 |
-
|
| 1463 |
-
|
| 1464 |
-
"generate full project",
|
| 1465 |
-
"full project",
|
| 1466 |
-
"complete project",
|
| 1467 |
-
|
| 1468 |
-
|
| 1469 |
-
"another",
|
| 1470 |
-
"again",
|
| 1471 |
-
"more",
|
| 1472 |
-
"chat",
|
| 1473 |
-
"help",
|
| 1474 |
-
"menu",
|
| 1475 |
-
"discuss",
|
| 1476 |
-
"discuss project"
|
| 1477 |
-
}
|
| 1478 |
-
|
| 1479 |
-
clean_text = text.strip()
|
| 1480 |
-
|
| 1481 |
-
|
| 1482 |
-
words = clean_text.lower().split()
|
| 1483 |
-
|
| 1484 |
-
if (
|
| 1485 |
-
2 <= len(words) <= 8
|
| 1486 |
-
and not clean_text.endswith("?")
|
| 1487 |
-
and not clean_text.startswith(blocked_starts)
|
| 1488 |
-
and clean_text.lower() not in command_phrases
|
| 1489 |
-
and not any(
|
| 1490 |
-
w in action_words
|
| 1491 |
-
for w in words
|
| 1492 |
-
)
|
| 1493 |
-
):
|
| 1494 |
-
|
| 1495 |
-
analysis = {
|
| 1496 |
-
"intent": "project_title",
|
| 1497 |
-
"project_title": user_input.strip()
|
| 1498 |
-
}
|
| 1499 |
-
|
| 1500 |
-
else:
|
| 1501 |
-
analysis = analyze_user_input(user_input, state)
|
| 1502 |
-
|
| 1503 |
-
|
| 1504 |
-
|
| 1505 |
-
|
| 1506 |
-
existing_ideas = state.get("ideas", [])
|
| 1507 |
-
|
| 1508 |
-
normalized_input = text.strip().lower()
|
| 1509 |
-
|
| 1510 |
-
for idea in existing_ideas:
|
| 1511 |
-
|
| 1512 |
-
idea_norm = idea.strip().lower()
|
| 1513 |
-
|
| 1514 |
-
input_words = set(normalized_input.split())
|
| 1515 |
-
|
| 1516 |
-
|
| 1517 |
-
if len(input_words) < 2:
|
| 1518 |
-
continue
|
| 1519 |
-
|
| 1520 |
-
idea_words = set(idea_norm.split())
|
| 1521 |
-
|
| 1522 |
-
overlap = input_words & idea_words
|
| 1523 |
-
|
| 1524 |
-
overlap_ratio = (
|
| 1525 |
-
len(overlap) / max(1, len(input_words))
|
| 1526 |
-
)
|
| 1527 |
-
|
| 1528 |
-
if (
|
| 1529 |
-
normalized_input == idea_norm
|
| 1530 |
-
or normalized_input in idea_norm
|
| 1531 |
-
or overlap_ratio >= 0.6
|
| 1532 |
-
):
|
| 1533 |
-
|
| 1534 |
-
state["project_title"] = idea
|
| 1535 |
-
|
| 1536 |
-
state["waiting_for_project_action"] = True
|
| 1537 |
-
|
| 1538 |
-
state["project_chat_mode"] = False
|
| 1539 |
-
|
| 1540 |
-
state["waiting_for_full_project_selection"] = False
|
| 1541 |
-
|
| 1542 |
-
save_user_memory(user_id, {
|
| 1543 |
-
"history": history,
|
| 1544 |
-
"state": state
|
| 1545 |
-
})
|
| 1546 |
-
|
| 1547 |
-
return finalize_response(
|
| 1548 |
-
|
| 1549 |
-
user_input,
|
| 1550 |
-
|
| 1551 |
-
f"""📌 Project Selected:
|
| 1552 |
-
|
| 1553 |
-
{idea}
|
| 1554 |
-
|
| 1555 |
-
Choose what you want:
|
| 1556 |
-
|
| 1557 |
-
1️⃣ Generate Features
|
| 1558 |
-
2️⃣ Generate Full Project
|
| 1559 |
-
|
| 1560 |
-
👉 You can also type:
|
| 1561 |
-
- features
|
| 1562 |
-
- full project
|
| 1563 |
-
""",
|
| 1564 |
-
|
| 1565 |
-
history,
|
| 1566 |
-
state,
|
| 1567 |
-
user_id
|
| 1568 |
-
)
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
state["project_title"] = idea
|
| 1574 |
-
state["waiting_for_project_action"] = True
|
| 1575 |
-
state["project_chat_mode"] = False
|
| 1576 |
-
|
| 1577 |
-
save_user_memory(user_id, {
|
| 1578 |
-
"history": history,
|
| 1579 |
-
"state": state
|
| 1580 |
-
})
|
| 1581 |
-
return (
|
| 1582 |
-
f"📌 Project selected:\n"
|
| 1583 |
-
f"{idea}\n\n"
|
| 1584 |
-
"Choose what you want next:\n"
|
| 1585 |
-
"1️⃣ Generate features\n\n"
|
| 1586 |
-
"👉 You can also say:\n"
|
| 1587 |
-
"- generate features"
|
| 1588 |
-
)
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
|
| 1593 |
-
if any(w in text for w in FOLLOWUP_WORDS):
|
| 1594 |
-
|
| 1595 |
-
|
| 1596 |
-
if state.get("last_action") == "idea":
|
| 1597 |
-
|
| 1598 |
-
analysis["intent"] = "idea"
|
| 1599 |
-
analysis["domain"] = state.get("domain")
|
| 1600 |
-
|
| 1601 |
-
|
| 1602 |
-
elif state.get("last_action") == "feature":
|
| 1603 |
-
|
| 1604 |
-
analysis["intent"] = "feature"
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
|
| 1608 |
-
|
| 1609 |
-
if state.get("waiting_for_niche_domain"):
|
| 1610 |
-
text_lower = user_input.strip().lower()
|
| 1611 |
-
general_keywords = {"general", "general domain", "other", "others", "random", "anything", "whatever", "surprise me", "any", "mixed"}
|
| 1612 |
-
|
| 1613 |
-
if text_lower in general_keywords:
|
| 1614 |
-
state["waiting_for_domain"] = False
|
| 1615 |
-
state["waiting_for_niche_domain"] = False
|
| 1616 |
-
state["suggested_domains"] = []
|
| 1617 |
-
analysis["domain"] = "general"
|
| 1618 |
-
analysis["intent"] = "idea"
|
| 1619 |
-
if "project_title" in analysis:
|
| 1620 |
-
del analysis["project_title"]
|
| 1621 |
-
else:
|
| 1622 |
-
more_words = ["more", "another", "different", "none", "generate more"]
|
| 1623 |
-
if any(w in text_lower for w in more_words) and len(text_lower.split()) < 5:
|
| 1624 |
-
previous_domains = state.get("suggested_domains", [])
|
| 1625 |
-
niche_domains = generate_list(build_niche_domains_prompt(previous_domains), task="idea")
|
| 1626 |
-
|
| 1627 |
-
state["suggested_domains"] = previous_domains + niche_domains
|
| 1628 |
-
|
| 1629 |
-
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1630 |
-
response = (
|
| 1631 |
-
f"Here are some MORE niche and cutting-edge domain ideas:\n\n"
|
| 1632 |
-
f"{domain_list_str}\n\n"
|
| 1633 |
-
f"Which one would you like to explore? (Or type your own!)"
|
| 1634 |
-
)
|
| 1635 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 1636 |
-
return finalize_response(user_input, response, history, state, user_id)
|
| 1637 |
-
else:
|
| 1638 |
-
domain = user_input.strip()
|
| 1639 |
-
validated_domain = validate_and_format_domain(domain)
|
| 1640 |
-
if not validated_domain:
|
| 1641 |
-
return (
|
| 1642 |
-
"⚠️ That does not seem to be a valid technology or academic domain.\n\n"
|
| 1643 |
-
"Please enter a valid domain (e.g. AI, Healthcare, Fintech, or 'Others')."
|
| 1644 |
-
)
|
| 1645 |
-
state["waiting_for_niche_domain"] = False
|
| 1646 |
-
state["suggested_domains"] = []
|
| 1647 |
-
analysis["domain"] = validated_domain
|
| 1648 |
-
analysis["intent"] = "idea"
|
| 1649 |
-
if "project_title" in analysis:
|
| 1650 |
-
del analysis["project_title"]
|
| 1651 |
-
|
| 1652 |
-
elif state.get("waiting_for_domain"):
|
| 1653 |
-
text_lower = user_input.strip().lower()
|
| 1654 |
-
general_keywords = {"general", "general domain", "random", "anything", "whatever", "surprise me", "any", "mixed"}
|
| 1655 |
-
|
| 1656 |
-
if text_lower in general_keywords:
|
| 1657 |
-
state["waiting_for_domain"] = False
|
| 1658 |
-
state["waiting_for_niche_domain"] = False
|
| 1659 |
-
analysis["domain"] = "general"
|
| 1660 |
-
analysis["intent"] = "idea"
|
| 1661 |
-
if "project_title" in analysis:
|
| 1662 |
-
del analysis["project_title"]
|
| 1663 |
-
else:
|
| 1664 |
-
detected = extract_domain(user_input)
|
| 1665 |
-
|
| 1666 |
-
if detected.lower() == "others":
|
| 1667 |
-
state["waiting_for_domain"] = False
|
| 1668 |
-
state["waiting_for_niche_domain"] = True
|
| 1669 |
-
|
| 1670 |
-
niche_domains = generate_list(build_niche_domains_prompt([]), task="idea")
|
| 1671 |
-
state["suggested_domains"] = niche_domains
|
| 1672 |
-
|
| 1673 |
-
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1674 |
-
response = (
|
| 1675 |
-
f"Great choice! Here are some cutting-edge niche domains to explore 🚀\n\n"
|
| 1676 |
-
f"{domain_list_str}\n\n"
|
| 1677 |
-
f"💡 Pick one from the list above, or type any domain you have in mind!"
|
| 1678 |
-
)
|
| 1679 |
-
save_user_memory(user_id, {"history": history, "state": state})
|
| 1680 |
-
return finalize_response(user_input, response, history, state, user_id)
|
| 1681 |
-
|
| 1682 |
-
elif detected:
|
| 1683 |
-
state["waiting_for_domain"] = False
|
| 1684 |
-
analysis["domain"] = detected
|
| 1685 |
-
analysis["intent"] = "idea"
|
| 1686 |
-
if "project_title" in analysis:
|
| 1687 |
-
del analysis["project_title"]
|
| 1688 |
-
else:
|
| 1689 |
-
validated_domain = validate_and_format_domain(user_input.strip())
|
| 1690 |
-
if validated_domain:
|
| 1691 |
-
state["waiting_for_domain"] = False
|
| 1692 |
-
analysis["domain"] = validated_domain
|
| 1693 |
-
analysis["intent"] = "idea"
|
| 1694 |
-
if "project_title" in analysis:
|
| 1695 |
-
del analysis["project_title"]
|
| 1696 |
-
else:
|
| 1697 |
-
return (
|
| 1698 |
-
"⚠️ Please enter a valid domain "
|
| 1699 |
-
"(AI, healthcare, fintech...)"
|
| 1700 |
-
)
|
| 1701 |
-
|
| 1702 |
-
intent = analysis.get("intent", "chat")
|
| 1703 |
-
|
| 1704 |
-
domain = analysis.get("domain")
|
| 1705 |
-
|
| 1706 |
-
user_project = analysis.get("project_title")
|
| 1707 |
-
|
| 1708 |
-
if state.get("project_chat_mode"):
|
| 1709 |
-
user_project = None
|
| 1710 |
-
exact_cmds = {"idea", "ideas", "menu", "exit", "quit", "generate features", "features", "generate full project"}
|
| 1711 |
-
if user_input.strip().lower() not in exact_cmds:
|
| 1712 |
-
intent = "chat"
|
| 1713 |
-
|
| 1714 |
-
# Override intent using the LLM-derived semantic context when no project is active yet
|
| 1715 |
-
if not state.get("project_title") and not is_in_domain_or_selection_state:
|
| 1716 |
-
if context == "idea_request":
|
| 1717 |
-
intent = "idea"
|
| 1718 |
-
elif context == "feature_request":
|
| 1719 |
-
intent = "feature"
|
| 1720 |
-
elif context in ["general_chat", "project_title"]:
|
| 1721 |
-
intent = "chat"
|
| 1722 |
-
user_project = user_input.strip()
|
| 1723 |
-
|
| 1724 |
-
|
| 1725 |
-
|
| 1726 |
-
|
| 1727 |
-
if state.get("waiting_for_full_project_domain"):
|
| 1728 |
-
|
| 1729 |
-
domain = extract_domain(user_input)
|
| 1730 |
-
|
| 1731 |
-
if not domain:
|
| 1732 |
-
|
| 1733 |
-
return (
|
| 1734 |
-
"⚠️ Please enter valid domain.\n\n"
|
| 1735 |
-
"Example:\n"
|
| 1736 |
-
"- AI\n"
|
| 1737 |
-
"- healthcare\n"
|
| 1738 |
-
"- education"
|
| 1739 |
-
)
|
| 1740 |
-
|
| 1741 |
-
state["waiting_for_full_project_domain"] = False
|
| 1742 |
-
|
| 1743 |
-
result = generate_ideas(
|
| 1744 |
-
domain=domain,
|
| 1745 |
-
top_k=5
|
| 1746 |
-
)
|
| 1747 |
-
|
| 1748 |
-
ideas = result.get("final_ideas", [])
|
| 1749 |
-
|
| 1750 |
-
state["ideas"] = ideas
|
| 1751 |
-
|
| 1752 |
-
state["waiting_for_full_project_selection"] = True
|
| 1753 |
-
|
| 1754 |
-
save_user_memory(user_id, {
|
| 1755 |
-
"history": history,
|
| 1756 |
-
"state": state
|
| 1757 |
-
})
|
| 1758 |
-
|
| 1759 |
-
return (
|
| 1760 |
-
"💡 Choose one project title:\n\n"
|
| 1761 |
-
+ "\n".join(
|
| 1762 |
-
f"- {idea}"
|
| 1763 |
-
for idea in ideas
|
| 1764 |
-
)
|
| 1765 |
-
)
|
| 1766 |
-
|
| 1767 |
-
|
| 1768 |
-
|
| 1769 |
-
if not domain:
|
| 1770 |
-
domain = extract_domain(text)
|
| 1771 |
-
|
| 1772 |
-
|
| 1773 |
-
|
| 1774 |
-
|
| 1775 |
-
full_project_commands = [
|
| 1776 |
-
"fill all",
|
| 1777 |
-
"fill all columns",
|
| 1778 |
-
"fill all fields",
|
| 1779 |
-
"full project",
|
| 1780 |
-
"final project",
|
| 1781 |
-
"complete project",
|
| 1782 |
-
"generate full project",
|
| 1783 |
-
"generate final project",
|
| 1784 |
-
"generate all details",
|
| 1785 |
-
"project specification",
|
| 1786 |
-
"complete details"
|
| 1787 |
-
]
|
| 1788 |
-
|
| 1789 |
-
if (
|
| 1790 |
-
domain
|
| 1791 |
-
and domain.lower() != "others"
|
| 1792 |
-
and intent == "chat"
|
| 1793 |
-
and len(text.split()) <= 3
|
| 1794 |
-
and not any(cmd in text for cmd in full_project_commands)
|
| 1795 |
-
):
|
| 1796 |
-
intent = "idea"
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
if (
|
| 1801 |
-
not user_project
|
| 1802 |
-
and intent == "chat"
|
| 1803 |
-
and 3 <= len(text.split()) <= 12
|
| 1804 |
-
):
|
| 1805 |
-
idea_request_patterns = [
|
| 1806 |
-
|
| 1807 |
-
"new idea",
|
| 1808 |
-
"generate idea",
|
| 1809 |
-
"generate ideas",
|
| 1810 |
-
"project ideas",
|
| 1811 |
-
"idea for",
|
| 1812 |
-
"ideas for",
|
| 1813 |
-
"i need idea",
|
| 1814 |
-
"i need ideas",
|
| 1815 |
-
"need idea",
|
| 1816 |
-
"need ideas",
|
| 1817 |
-
"another idea",
|
| 1818 |
-
"more ideas",
|
| 1819 |
-
|
| 1820 |
-
]
|
| 1821 |
-
|
| 1822 |
-
blocked_starts = (
|
| 1823 |
-
"how ",
|
| 1824 |
-
"what ",
|
| 1825 |
-
"why ",
|
| 1826 |
-
"when ",
|
| 1827 |
-
"where ",
|
| 1828 |
-
"can ",
|
| 1829 |
-
"could ",
|
| 1830 |
-
"should ",
|
| 1831 |
-
"is ",
|
| 1832 |
-
"are ",
|
| 1833 |
-
"do ",
|
| 1834 |
-
"does ",
|
| 1835 |
-
"help ",
|
| 1836 |
-
)
|
| 1837 |
-
|
| 1838 |
-
if text.endswith("?"):
|
| 1839 |
-
pass
|
| 1840 |
-
|
| 1841 |
-
elif text.startswith(blocked_starts):
|
| 1842 |
-
pass
|
| 1843 |
-
|
| 1844 |
-
else:
|
| 1845 |
-
|
| 1846 |
-
command_phrases = {
|
| 1847 |
-
"generate features",
|
| 1848 |
-
"generate feature",
|
| 1849 |
-
"generate ideas",
|
| 1850 |
-
"generate idea",
|
| 1851 |
-
"more",
|
| 1852 |
-
"another",
|
| 1853 |
-
"again",
|
| 1854 |
-
"discuss project",
|
| 1855 |
-
"chat",
|
| 1856 |
-
"help",
|
| 1857 |
-
"menu"
|
| 1858 |
-
}
|
| 1859 |
-
|
| 1860 |
-
if (
|
| 1861 |
-
text not in command_phrases
|
| 1862 |
-
and not any(
|
| 1863 |
-
p in text
|
| 1864 |
-
for p in idea_request_patterns
|
| 1865 |
-
)
|
| 1866 |
-
):
|
| 1867 |
-
|
| 1868 |
-
|
| 1869 |
-
user_project = user_input.strip()
|
| 1870 |
-
|
| 1871 |
-
|
| 1872 |
-
|
| 1873 |
-
if user_project:
|
| 1874 |
-
|
| 1875 |
-
if not looks_like_real_project_title(user_project):
|
| 1876 |
-
state["waiting_for_title_confirmation"] = True
|
| 1877 |
-
state["pending_title"] = user_project
|
| 1878 |
-
save_user_memory(user_id, {
|
| 1879 |
-
"history": history,
|
| 1880 |
-
"state": state
|
| 1881 |
-
})
|
| 1882 |
-
return "Is that a project title?"
|
| 1883 |
-
|
| 1884 |
-
if is_weak_project_title(user_project):
|
| 1885 |
-
|
| 1886 |
-
state["weak_title_candidate"] = user_project
|
| 1887 |
-
|
| 1888 |
-
save_user_memory(user_id, {
|
| 1889 |
-
"history": history,
|
| 1890 |
-
"state": state
|
| 1891 |
-
})
|
| 1892 |
-
|
| 1893 |
-
return (
|
| 1894 |
-
"⚠️ Your project title is too short or unclear.\n\n"
|
| 1895 |
-
"Examples:\n"
|
| 1896 |
-
"- AI-powered smart library recommendation system\n"
|
| 1897 |
-
"- Smart hospital emergency response platform\n"
|
| 1898 |
-
"- Blockchain-secured academic certificate verification system\n\n"
|
| 1899 |
-
"Please enter a more descriptive title."
|
| 1900 |
-
)
|
| 1901 |
-
|
| 1902 |
-
state = default_state()
|
| 1903 |
-
|
| 1904 |
-
state["project_title"] = user_project
|
| 1905 |
-
state["waiting_for_project_action"] = True
|
| 1906 |
-
|
| 1907 |
-
save_user_memory(user_id, {
|
| 1908 |
-
"history": history,
|
| 1909 |
-
"state": state
|
| 1910 |
-
})
|
| 1911 |
-
|
| 1912 |
-
return (
|
| 1913 |
-
f"📌 Project detected:\n"
|
| 1914 |
-
f"{user_project}\n\n"
|
| 1915 |
-
"Choose what you want next:\n"
|
| 1916 |
-
"1️⃣ Generate features\n"
|
| 1917 |
-
"2️⃣ Generate full project\n\n"
|
| 1918 |
-
"👉 You can also say:\n"
|
| 1919 |
-
"- generate features\n"
|
| 1920 |
-
"- generate full project"
|
| 1921 |
-
)
|
| 1922 |
-
|
| 1923 |
-
|
| 1924 |
-
|
| 1925 |
-
feature_request_phrases = [
|
| 1926 |
-
"generate features",
|
| 1927 |
-
"generate feature",
|
| 1928 |
-
"i need features",
|
| 1929 |
-
"feature ideas",
|
| 1930 |
-
"add features",
|
| 1931 |
-
"create features",
|
| 1932 |
-
"suggest features",
|
| 1933 |
-
"improve my project",
|
| 1934 |
-
"improve project",
|
| 1935 |
-
"improve my idea",
|
| 1936 |
-
"enhance my project",
|
| 1937 |
-
"discuss my project",
|
| 1938 |
-
"talk about my project",
|
| 1939 |
-
"help my project",
|
| 1940 |
-
"improve"
|
| 1941 |
-
]
|
| 1942 |
-
|
| 1943 |
-
if (
|
| 1944 |
-
any(p in text for p in feature_request_phrases)
|
| 1945 |
-
and not state.get("project_title")
|
| 1946 |
-
and not analysis.get("project_title")
|
| 1947 |
-
):
|
| 1948 |
-
|
| 1949 |
-
return (
|
| 1950 |
-
"I need a project title to generate features! 📝\n\n"
|
| 1951 |
-
"Type your project title and I'll handle the rest.\n"
|
| 1952 |
-
"Example:\n"
|
| 1953 |
-
" AI-powered smart library recommendation system\n\n"
|
| 1954 |
-
"💡 Don't have a title yet? Type **idea** to browse project ideas first!"
|
| 1955 |
-
)
|
| 1956 |
-
|
| 1957 |
-
|
| 1958 |
-
|
| 1959 |
-
if intent == "idea":
|
| 1960 |
-
|
| 1961 |
-
if not domain:
|
| 1962 |
-
|
| 1963 |
-
state["waiting_for_domain"] = True
|
| 1964 |
-
|
| 1965 |
-
save_user_memory(user_id, {
|
| 1966 |
-
"history": history,
|
| 1967 |
-
"state": state
|
| 1968 |
-
})
|
| 1969 |
-
|
| 1970 |
-
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys() if d != "Others")
|
| 1971 |
-
return (
|
| 1972 |
-
f"Which domain is your project in? 📚\n\n"
|
| 1973 |
-
f"{domain_list}\n\n"
|
| 1974 |
-
f"💡 Just type one of the domains above (e.g. **AI** or **Healthcare**)\n"
|
| 1975 |
-
f"If your domain isn't listed, type **Others** to see more options."
|
| 1976 |
-
)
|
| 1977 |
-
|
| 1978 |
-
top_k = analysis.get("number") or extract_number(
|
| 1979 |
-
user_input,
|
| 1980 |
-
5
|
| 1981 |
-
)
|
| 1982 |
-
|
| 1983 |
-
result = generate_ideas(
|
| 1984 |
-
domain=domain,
|
| 1985 |
-
top_k=top_k,
|
| 1986 |
-
previous_generated_ideas=state.get("ideas", [])
|
| 1987 |
-
)
|
| 1988 |
-
|
| 1989 |
-
ideas = result.get("final_ideas", [])
|
| 1990 |
-
|
| 1991 |
-
state["ideas"] = ideas
|
| 1992 |
-
state["domain"] = domain
|
| 1993 |
-
state["last_action"] = "idea"
|
| 1994 |
-
|
| 1995 |
-
# Clear project-specific keys to switch back to ideas stage
|
| 1996 |
-
state["project_title"] = ""
|
| 1997 |
-
state["features"] = []
|
| 1998 |
-
state["description"] = ""
|
| 1999 |
-
state["abstract"] = ""
|
| 2000 |
-
state["technologies"] = []
|
| 2001 |
-
state["originality_score"] = None
|
| 2002 |
-
state["context_strength"] = None
|
| 2003 |
-
state["problem_statement"] = ""
|
| 2004 |
-
state["proposed_solution"] = ""
|
| 2005 |
-
state["keywords"] = []
|
| 2006 |
-
state["ai_summary"] = ""
|
| 2007 |
-
state["category"] = ""
|
| 2008 |
-
|
| 2009 |
-
response = format_response("idea", "", state)
|
| 2010 |
-
|
| 2011 |
-
return finalize_response(
|
| 2012 |
-
user_input,
|
| 2013 |
-
response,
|
| 2014 |
-
history,
|
| 2015 |
-
state,
|
| 2016 |
-
user_id
|
| 2017 |
-
)
|
| 2018 |
-
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
|
| 2022 |
-
elif intent == "feature":
|
| 2023 |
-
|
| 2024 |
-
|
| 2025 |
-
|
| 2026 |
-
|
| 2027 |
-
if analysis.get("project_title"):
|
| 2028 |
-
|
| 2029 |
-
state["project_title"] = (
|
| 2030 |
-
analysis["project_title"]
|
| 2031 |
-
)
|
| 2032 |
-
|
| 2033 |
-
if not state.get("project_title"):
|
| 2034 |
-
|
| 2035 |
-
return (
|
| 2036 |
-
"I need a project title to generate features! 📝\n\n"
|
| 2037 |
-
"Just type your project title and I'll generate smart features for it.\n"
|
| 2038 |
-
"💡 No title yet? Type **idea** to get suggestions first!"
|
| 2039 |
-
)
|
| 2040 |
-
|
| 2041 |
-
top_k = analysis.get("number") or extract_number(
|
| 2042 |
-
user_input,
|
| 2043 |
-
5
|
| 2044 |
-
)
|
| 2045 |
-
|
| 2046 |
-
result = generate_features(
|
| 2047 |
-
title=state.get("project_title"),
|
| 2048 |
-
description=state.get("description", ""),
|
| 2049 |
-
features=[],
|
| 2050 |
-
previous_generated_features=[],
|
| 2051 |
-
top_k=top_k
|
| 2052 |
-
)
|
| 2053 |
-
|
| 2054 |
-
features = result.get(
|
| 2055 |
-
"recommended_features",
|
| 2056 |
-
[]
|
| 2057 |
-
)
|
| 2058 |
-
|
| 2059 |
-
|
| 2060 |
-
|
| 2061 |
-
state["features"] = features
|
| 2062 |
-
|
| 2063 |
-
state["last_action"] = "feature"
|
| 2064 |
-
|
| 2065 |
-
response = format_response("feature", "", state)
|
| 2066 |
-
return finalize_response(
|
| 2067 |
-
user_input,
|
| 2068 |
-
response,
|
| 2069 |
-
history,
|
| 2070 |
-
state,
|
| 2071 |
-
user_id
|
| 2072 |
-
)
|
| 2073 |
-
|
| 2074 |
|
| 2075 |
-
|
| 2076 |
-
|
| 2077 |
-
|
| 2078 |
-
|
| 2079 |
-
|
| 2080 |
-
"fill all",
|
| 2081 |
-
"fill all columns",
|
| 2082 |
-
"fill all fields",
|
| 2083 |
-
"full project",
|
| 2084 |
-
"final project",
|
| 2085 |
-
"complete project",
|
| 2086 |
-
"generate full project",
|
| 2087 |
-
"generate final project",
|
| 2088 |
-
"generate all details",
|
| 2089 |
-
"project specification",
|
| 2090 |
-
"complete details"
|
| 2091 |
-
|
| 2092 |
-
]):
|
| 2093 |
-
|
| 2094 |
-
if not state.get("project_title"):
|
| 2095 |
-
|
| 2096 |
-
return (
|
| 2097 |
-
"Let's get started! Please provide a project title or type **idea** to pick one first. 💡"
|
| 2098 |
-
)
|
| 2099 |
-
|
| 2100 |
-
if not state.get("features"):
|
| 2101 |
-
|
| 2102 |
-
return (
|
| 2103 |
-
"Before generating the full project, I need to know what features it has. 📋\n\n"
|
| 2104 |
-
"Type **generate features** to create them quickly!"
|
| 2105 |
-
)
|
| 2106 |
-
|
| 2107 |
-
result = generate_full_project(
|
| 2108 |
-
|
| 2109 |
-
title=state.get("project_title"),
|
| 2110 |
-
|
| 2111 |
-
features=state.get("features", []),
|
| 2112 |
-
|
| 2113 |
-
description=state.get("description", ""),
|
| 2114 |
-
|
| 2115 |
-
abstract=state.get("abstract", "")
|
| 2116 |
-
)
|
| 2117 |
-
|
| 2118 |
-
state = update_state(
|
| 2119 |
-
state,
|
| 2120 |
-
result,
|
| 2121 |
-
mode="merge"
|
| 2122 |
-
)
|
| 2123 |
-
if state.get("domain"):
|
| 2124 |
-
state["category"] = state.get("domain")
|
| 2125 |
-
|
| 2126 |
-
state["waiting_for_project_idea_confirm"] = True
|
| 2127 |
-
state["from_full_project_generation"] = True
|
| 2128 |
-
|
| 2129 |
-
response = f"""
|
| 2130 |
-
📦 Project Specification Ready!
|
| 2131 |
-
|
| 2132 |
-
📌 Title: {state.get("project_title")}
|
| 2133 |
-
📂 Category: {state.get("category")}
|
| 2134 |
-
|
| 2135 |
-
🛠 Technologies: {", ".join(state.get("technologies", []))}
|
| 2136 |
-
|
| 2137 |
-
📄 Abstract:
|
| 2138 |
-
{state.get("abstract")}
|
| 2139 |
-
|
| 2140 |
-
📄 Description:
|
| 2141 |
-
{state.get("description")}
|
| 2142 |
-
|
| 2143 |
-
❗ Problem Statement:
|
| 2144 |
-
{state.get("problem_statement")}
|
| 2145 |
-
|
| 2146 |
-
💡 Proposed Solution:
|
| 2147 |
-
{state.get("proposed_solution")}
|
| 2148 |
-
|
| 2149 |
-
🎯 Objectives:
|
| 2150 |
-
{chr(10).join("- " + x for x in state.get("objectives", []))}
|
| 2151 |
-
|
| 2152 |
-
──────────────────────
|
| 2153 |
-
📍 Would you like to use this as your graduation project idea?
|
| 2154 |
-
Reply **yes** to validate & categorize it, or **no** to explore other ideas.
|
| 2155 |
-
"""
|
| 2156 |
-
|
| 2157 |
-
return finalize_response(
|
| 2158 |
-
user_input,
|
| 2159 |
-
response,
|
| 2160 |
-
history,
|
| 2161 |
-
state,
|
| 2162 |
-
user_id
|
| 2163 |
-
)
|
| 2164 |
-
|
| 2165 |
-
|
| 2166 |
-
|
| 2167 |
-
|
| 2168 |
-
elif (
|
| 2169 |
-
state.get("project_title")
|
| 2170 |
-
and len(text.split()) >= 3
|
| 2171 |
-
and not any(w in text for w in FOLLOWUP_WORDS)
|
| 2172 |
-
):
|
| 2173 |
-
|
| 2174 |
-
current_title = (
|
| 2175 |
-
state.get("project_title", "")
|
| 2176 |
-
.lower()
|
| 2177 |
-
.split()
|
| 2178 |
-
)
|
| 2179 |
-
|
| 2180 |
-
new_input_words = text.split()
|
| 2181 |
-
|
| 2182 |
-
overlap = set(current_title) & set(new_input_words)
|
| 2183 |
-
|
| 2184 |
-
overlap_ratio = (
|
| 2185 |
-
len(overlap)
|
| 2186 |
-
/ max(1, len(new_input_words))
|
| 2187 |
-
)
|
| 2188 |
-
|
| 2189 |
|
| 2190 |
-
if (
|
| 2191 |
-
overlap_ratio < 0.2
|
| 2192 |
-
and analysis.get("intent") == "chat"
|
| 2193 |
-
):
|
| 2194 |
-
|
| 2195 |
-
return (
|
| 2196 |
-
)
|
| 2197 |
-
|
| 2198 |
-
full_prompt = f"""
|
| 2199 |
-
{system_prompt}
|
| 2200 |
-
|
| 2201 |
-
Conversation:
|
| 2202 |
-
{formatted_history}
|
| 2203 |
-
|
| 2204 |
-
User:
|
| 2205 |
-
{user_input}
|
| 2206 |
-
"""
|
| 2207 |
-
|
| 2208 |
-
raw = generate_text(
|
| 2209 |
-
full_prompt,
|
| 2210 |
-
task="chat"
|
| 2211 |
-
)
|
| 2212 |
-
|
| 2213 |
-
response = format_response(
|
| 2214 |
-
"chat",
|
| 2215 |
-
raw,
|
| 2216 |
-
state
|
| 2217 |
-
)
|
| 2218 |
-
return finalize_response(
|
| 2219 |
-
user_input,
|
| 2220 |
-
response,
|
| 2221 |
-
history,
|
| 2222 |
-
state,
|
| 2223 |
-
user_id
|
| 2224 |
-
)
|
| 2225 |
-
|
| 2226 |
-
|
| 2227 |
-
|
| 2228 |
-
if not is_project_related(text) and not state.get("project_title"):
|
| 2229 |
-
|
| 2230 |
-
return (
|
| 2231 |
-
"I'm designed specifically for graduation projects 🎓\n\n"
|
| 2232 |
-
"Here's what I can help with:\n"
|
| 2233 |
-
"- Type **idea** → browse project ideas by domain\n"
|
| 2234 |
-
"- Type your project title → get smart features\n"
|
| 2235 |
-
"- Type **generate full project** → complete project specification\n\n"
|
| 2236 |
-
"💡 Start by typing **idea** — it's quick and easy!"
|
| 2237 |
-
)
|
| 2238 |
-
|
| 2239 |
-
|
| 2240 |
-
|
| 2241 |
else:
|
| 2242 |
-
|
| 2243 |
-
system_prompt = build_chat_prompt(state)
|
| 2244 |
-
|
| 2245 |
-
formatted_history = "\n".join([
|
| 2246 |
-
f"{m['role']}: {m['content']}"
|
| 2247 |
-
for m in history[-6:]
|
| 2248 |
-
])
|
| 2249 |
-
|
| 2250 |
-
full_prompt = f"""
|
| 2251 |
-
{system_prompt}
|
| 2252 |
-
|
| 2253 |
-
Conversation:
|
| 2254 |
-
{formatted_history}
|
| 2255 |
-
|
| 2256 |
-
User:
|
| 2257 |
-
{user_input}
|
| 2258 |
-
"""
|
| 2259 |
-
|
| 2260 |
-
raw = generate_text(
|
| 2261 |
-
full_prompt,
|
| 2262 |
-
task="chat"
|
| 2263 |
-
)
|
| 2264 |
-
|
| 2265 |
-
response = format_response(
|
| 2266 |
-
"chat",
|
| 2267 |
-
raw,
|
| 2268 |
-
state
|
| 2269 |
-
)
|
| 2270 |
-
return finalize_response(
|
| 2271 |
-
user_input,
|
| 2272 |
-
response,
|
| 2273 |
-
history,
|
| 2274 |
-
state,
|
| 2275 |
-
user_id
|
| 2276 |
-
)
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
def extract_number(text: str, default=5):
|
| 91 |
+
cleaned = str(text).strip()
|
| 92 |
+
if cleaned in ["1", "2"]:
|
| 93 |
+
return default
|
| 94 |
nums = re.findall(r"\d+", text)
|
|
|
|
| 95 |
return min(int(nums[0]), 20) if nums else default
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
def validate_and_format_domain(domain: str) -> str:
|
| 98 |
# 1. Quick local validation for standard domains
|
| 99 |
extracted = extract_domain(domain)
|
|
|
|
| 486 |
|
| 487 |
return False
|
| 488 |
|
|
|
|
| 489 |
|
| 490 |
+
def chatbot(user_id: str, user_input: str):
|
| 491 |
text = user_input.lower().strip()
|
| 492 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
if is_command(user_input):
|
| 494 |
return handle_command(user_input)
|
| 495 |
|
|
|
|
|
|
|
|
|
|
| 496 |
memory = get_user_memory(user_id)
|
|
|
|
| 497 |
history = memory.get("history", [])
|
|
|
|
| 498 |
state = memory.get("state") or default_state()
|
| 499 |
|
| 500 |
+
# The Orchestrator handles all context and validation
|
| 501 |
+
from src.recommendation_engine.llm_router import analyze_user_input
|
| 502 |
+
analysis = analyze_user_input(user_input, state)
|
| 503 |
+
|
| 504 |
+
action = analysis.get("action", "reply_directly")
|
| 505 |
+
reply_text = analysis.get("reply_text")
|
| 506 |
+
domain = analysis.get("domain")
|
| 507 |
+
project_title = analysis.get("project_title")
|
| 508 |
+
number = analysis.get("number")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
|
| 510 |
+
if action == "reply_directly":
|
| 511 |
+
if project_title and not state.get("project_title"):
|
| 512 |
+
state["project_title"] = project_title
|
| 513 |
+
if domain and not state.get("domain"):
|
| 514 |
+
state["domain"] = domain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 517 |
+
|
| 518 |
+
return finalize_response(
|
| 519 |
+
user_input,
|
| 520 |
+
reply_text or "I didn't quite catch that. Can you clarify?",
|
| 521 |
+
history,
|
| 522 |
+
state,
|
| 523 |
+
user_id
|
| 524 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
+
elif action == "trigger_idea_generation":
|
| 527 |
+
if domain:
|
| 528 |
+
domain_lower = domain.lower()
|
| 529 |
+
if domain_lower in ["other", "others", "general", "any"]:
|
| 530 |
+
state["domain"] = "general"
|
| 531 |
+
state["waiting_for_domain"] = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
state["domain"] = domain
|
| 534 |
+
state["waiting_for_domain"] = False
|
| 535 |
+
elif user_input.lower().strip() == "idea":
|
| 536 |
+
state["domain"] = None
|
| 537 |
+
|
| 538 |
+
if not state.get("domain"):
|
| 539 |
+
state["waiting_for_domain"] = True
|
| 540 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 541 |
+
domain_list = "\n".join(f"- {d}" for d in DOMAIN_KEYWORDS.keys() if d != "Others")
|
| 542 |
+
response = (
|
| 543 |
+
f"Which domain is your project in? 📚\n\n"
|
| 544 |
+
f"{domain_list}\n\n"
|
| 545 |
+
f"💡 Just type one of the domains above (e.g. **AI** or **Healthcare**)\n"
|
| 546 |
+
f"If your domain isn't listed, type **Others** to see more options."
|
| 547 |
+
)
|
| 548 |
+
return finalize_response(user_input, response, history, state, user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
+
top_k = number or extract_number(user_input, 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
|
| 552 |
+
all_past_ideas = state.get("all_generated_ideas", [])
|
| 553 |
+
if state.get("ideas"):
|
| 554 |
+
for i in state["ideas"]:
|
| 555 |
+
if i not in all_past_ideas:
|
| 556 |
+
all_past_ideas.append(i)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
+
result = generate_ideas(
|
| 559 |
+
domain=state.get("domain"),
|
| 560 |
+
top_k=top_k,
|
| 561 |
+
previous_generated_ideas=all_past_ideas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
+
ideas = result.get("final_ideas", [])
|
| 565 |
|
| 566 |
+
state["all_generated_ideas"] = all_past_ideas + ideas
|
| 567 |
+
state["ideas"] = ideas
|
| 568 |
+
state["last_action"] = "idea"
|
| 569 |
|
| 570 |
+
state["project_title"] = ""
|
| 571 |
+
state["features"] = []
|
| 572 |
+
state["all_generated_features"] = []
|
| 573 |
+
state["description"] = ""
|
| 574 |
+
state["abstract"] = ""
|
| 575 |
+
state["technologies"] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
|
| 577 |
+
response = format_response("idea", "", state)
|
| 578 |
+
return finalize_response(user_input, response, history, state, user_id)
|
| 579 |
|
| 580 |
+
elif action == "trigger_feature_generation":
|
| 581 |
+
if project_title:
|
| 582 |
+
state["project_title"] = project_title
|
|
|
|
| 583 |
|
| 584 |
+
if not state.get("project_title"):
|
| 585 |
return finalize_response(
|
| 586 |
user_input,
|
| 587 |
+
"I need a project title to generate features! 📝\nJust type your project title.",
|
| 588 |
history,
|
| 589 |
state,
|
| 590 |
user_id
|
| 591 |
)
|
| 592 |
|
| 593 |
+
top_k = number or extract_number(user_input, 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 594 |
|
| 595 |
+
all_past_features = state.get("all_generated_features", [])
|
| 596 |
+
if state.get("features"):
|
| 597 |
+
for f in state["features"]:
|
| 598 |
+
if f not in all_past_features:
|
| 599 |
+
all_past_features.append(f)
|
| 600 |
|
| 601 |
+
result = generate_features(
|
| 602 |
+
title=state.get("project_title"),
|
| 603 |
+
description=state.get("description", ""),
|
| 604 |
+
features=[],
|
| 605 |
+
previous_generated_features=all_past_features,
|
| 606 |
+
top_k=top_k
|
| 607 |
+
)
|
| 608 |
|
| 609 |
+
new_features = result.get("recommended_features", [])
|
| 610 |
|
| 611 |
+
state["all_generated_features"] = all_past_features + new_features
|
| 612 |
+
state["features"] = new_features
|
| 613 |
+
state["last_action"] = "feature"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
|
| 615 |
+
response = format_response("feature", "", state)
|
| 616 |
+
return finalize_response(user_input, response, history, state, user_id)
|
|
|
|
|
|
|
| 617 |
|
| 618 |
+
elif action == "trigger_full_project_generation":
|
| 619 |
+
if project_title:
|
| 620 |
+
state["project_title"] = project_title
|
| 621 |
|
| 622 |
+
if not state.get("features"):
|
| 623 |
+
feature_result = generate_features(
|
| 624 |
title=state.get("project_title"),
|
|
|
|
|
|
|
|
|
|
| 625 |
description=state.get("description", ""),
|
| 626 |
+
features=[],
|
| 627 |
+
previous_generated_features=[],
|
| 628 |
+
top_k=8
|
| 629 |
)
|
| 630 |
+
state["features"] = feature_result.get("recommended_features", [])
|
| 631 |
|
| 632 |
+
result = generate_full_project(
|
| 633 |
+
title=state.get("project_title"),
|
| 634 |
+
features=state.get("features", []),
|
| 635 |
+
description=state.get("description", ""),
|
| 636 |
+
abstract=state.get("abstract", "")
|
| 637 |
+
)
|
|
|
|
| 638 |
|
| 639 |
+
state = update_state(state, result, mode="merge")
|
| 640 |
+
if state.get("domain"):
|
| 641 |
+
state["category"] = state.get("domain")
|
| 642 |
|
| 643 |
+
response = f"""
|
| 644 |
📦 Full Project Generated
|
| 645 |
|
| 646 |
📌 Project Title:
|
|
|
|
| 667 |
🎯 Objectives:
|
| 668 |
{chr(10).join("- " + x for x in state.get("objectives", []))}
|
| 669 |
|
| 670 |
+
━━━━━━━━━━━━━━━━━━━━━━
|
| 671 |
+
👉 Do you want to submit this project? (Yes/No)
|
|
|
|
| 672 |
"""
|
| 673 |
+
return finalize_response(user_input, response, history, state, user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
|
| 675 |
+
elif action == "confirmation_yes":
|
| 676 |
+
state["waiting_for_project_idea_confirm"] = False
|
| 677 |
+
state["waiting_for_title_confirmation"] = False
|
| 678 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 679 |
+
return finalize_response(user_input, "Great! Confirmed. Let's move on.", history, state, user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
| 681 |
+
elif action == "confirmation_no":
|
| 682 |
+
state["waiting_for_project_idea_confirm"] = False
|
| 683 |
+
state["waiting_for_title_confirmation"] = False
|
| 684 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 685 |
+
return finalize_response(user_input, "No problem! Let's try something else.", history, state, user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 686 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
else:
|
| 688 |
+
return finalize_response(user_input, "I am not sure how to handle that.", history, state, user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/recommendation_engine/config.py
CHANGED
|
@@ -34,7 +34,7 @@ INTENT_TEMPERATURE = float(os.getenv("INTENT_TEMPERATURE", 0.0))
|
|
| 34 |
IDEA_MAX_TOKENS = int(os.getenv("IDEA_MAX_TOKENS", 800))
|
| 35 |
FEATURE_MAX_TOKENS = int(os.getenv("FEATURE_MAX_TOKENS", 600))
|
| 36 |
CHAT_MAX_TOKENS = int(os.getenv("CHAT_MAX_TOKENS", 700))
|
| 37 |
-
INTENT_MAX_TOKENS = int(os.getenv("INTENT_MAX_TOKENS",
|
| 38 |
|
| 39 |
TOP_P = float(os.getenv("TOP_P", 0.95))
|
| 40 |
TOP_K = int(os.getenv("TOP_K", 40))
|
|
|
|
| 34 |
IDEA_MAX_TOKENS = int(os.getenv("IDEA_MAX_TOKENS", 800))
|
| 35 |
FEATURE_MAX_TOKENS = int(os.getenv("FEATURE_MAX_TOKENS", 600))
|
| 36 |
CHAT_MAX_TOKENS = int(os.getenv("CHAT_MAX_TOKENS", 700))
|
| 37 |
+
INTENT_MAX_TOKENS = int(os.getenv("INTENT_MAX_TOKENS", 300))
|
| 38 |
|
| 39 |
TOP_P = float(os.getenv("TOP_P", 0.95))
|
| 40 |
TOP_K = int(os.getenv("TOP_K", 40))
|
src/recommendation_engine/llm_router.py
CHANGED
|
@@ -1,7 +1,13 @@
|
|
| 1 |
import re
|
|
|
|
| 2 |
from src.recommendation_engine.context_builder import extract_domain
|
|
|
|
| 3 |
|
| 4 |
def word_to_number(text: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
mapping = {
|
| 6 |
"one": 1, "two": 2, "three": 3, "four": 4, "five": 5,
|
| 7 |
"six": 6, "seven": 7, "eight": 8, "nine": 9, "ten": 10
|
|
@@ -20,45 +26,100 @@ def word_to_number(text: str):
|
|
| 20 |
return None
|
| 21 |
|
| 22 |
def analyze_user_input(user_input: str, state: dict) -> dict:
|
| 23 |
-
|
| 24 |
text = user_input.lower()
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
if any(w in text for w in ["idea", "project", "suggest", "recommend"]):
|
| 30 |
-
intent = "idea"
|
| 31 |
-
|
| 32 |
-
elif "feature" in text:
|
| 33 |
-
intent = "feature"
|
| 34 |
-
|
| 35 |
-
elif "describe" in text or "description" in text:
|
| 36 |
-
intent = "description"
|
| 37 |
-
|
| 38 |
-
else:
|
| 39 |
-
intent = "chat"
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
domain = extract_domain(text)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
number = word_to_number(text)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
+
import json
|
| 3 |
from src.recommendation_engine.context_builder import extract_domain
|
| 4 |
+
from src.recommendation_engine.llm_client import generate_text
|
| 5 |
|
| 6 |
def word_to_number(text: str):
|
| 7 |
+
cleaned = text.strip()
|
| 8 |
+
if cleaned in ["1", "2"]:
|
| 9 |
+
return None
|
| 10 |
+
|
| 11 |
mapping = {
|
| 12 |
"one": 1, "two": 2, "three": 3, "four": 4, "five": 5,
|
| 13 |
"six": 6, "seven": 7, "eight": 8, "nine": 9, "ten": 10
|
|
|
|
| 26 |
return None
|
| 27 |
|
| 28 |
def analyze_user_input(user_input: str, state: dict) -> dict:
|
|
|
|
| 29 |
text = user_input.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
number = word_to_number(text)
|
| 32 |
|
| 33 |
+
prompt = f"""
|
| 34 |
+
You are the brain of a graduation project assistant. Your job is to evaluate the user's input, manage the conversational state, and decide the next backend action.
|
| 35 |
+
|
| 36 |
+
Current Conversational State:
|
| 37 |
+
- Waiting for domain: {state.get('waiting_for_domain', False)}
|
| 38 |
+
- Waiting for project action (features/full project): {state.get('waiting_for_project_action', False)}
|
| 39 |
+
- Active project title: {state.get('project_title', 'None')}
|
| 40 |
+
- Project chat mode: {state.get('project_chat_mode', False)}
|
| 41 |
+
|
| 42 |
+
User Input: "{user_input}"
|
| 43 |
+
|
| 44 |
+
Evaluate the input and choose exactly ONE action from the following list:
|
| 45 |
+
|
| 46 |
+
1. "reply_directly": Choose this if you want to answer the user directly with conversational text.
|
| 47 |
+
- Use this for general questions (e.g. "what is frontend?", "act as gemini").
|
| 48 |
+
- Use this if the user provides a vague or invalid project title (e.g. "My Project", "Test") and you need to ask them to be more specific.
|
| 49 |
+
- Use this to answer greetings, generic chit-chat, or isolated vague words (e.g. "general", "other", "others"). When answering greetings or vague statements, just ask the user what they mean or how you can help. Do NOT preemptively ask them to select a domain unless they specifically ask for project ideas. Do NOT choose "trigger_idea_generation" for isolated words unless you are actively waiting for a domain.
|
| 50 |
+
- CRITICAL: Use this if the user provides a descriptive project title but DOES NOT explicitly ask to generate features or generate a full project. If they just give a title, put this in "reply_text": "Great project title! Would you like me to 1️⃣ Generate features for it, or 2️⃣ Generate the full project specification?". Also extract the title into "extracted_title".
|
| 51 |
+
- If you choose this, put your conversational response in the "reply_text" field.
|
| 52 |
+
|
| 53 |
+
2. "trigger_idea_generation": Choose this if the user explicitly asks for project ideas, recommendations, or to explore projects.
|
| 54 |
+
- Example: "Explore AI project ideas", "give me an idea", "Recommend a FinTech project".
|
| 55 |
+
- If they specify a domain (like "AI" or "FinTech"), extract it into "extracted_domain".
|
| 56 |
+
- CRITICAL: If they ask for ideas but do NOT provide a domain (e.g. just "idea"), you MUST STILL choose "trigger_idea_generation". Do NOT choose "reply_directly" to ask for a domain. The system backend will handle asking them.
|
| 57 |
+
- CRITICAL: If `Waiting for domain: True` and the user provides a domain or field (e.g. "Data science", "AI", "other"), you MUST choose "trigger_idea_generation" and extract the domain. Do NOT choose "reply_directly".
|
| 58 |
+
|
| 59 |
+
3. "trigger_feature_generation": Choose this if the user explicitly asks for features generated AND they have provided a valid, descriptive project title.
|
| 60 |
+
- Example: "Generate features for AI-based library portal", or "1" (if selecting option 1 to improve/generate features).
|
| 61 |
+
- If they ask for features but the title is vague, just a brand name (like "Fixy", "App"), or lacking technical context (like "My Project"), choose "reply_directly" instead. Explain that a brand name isn't enough, and ask for a descriptive, technical title that explains what the project actually does.
|
| 62 |
+
|
| 63 |
+
4. "trigger_full_project_generation": Choose this if the user wants to generate the complete project specification.
|
| 64 |
+
- Example: "generate full project", "fill all fields", or "2" (if selecting option 2 to generate the full project).
|
| 65 |
+
|
| 66 |
+
5. "confirmation_yes": Choose this if the user is saying yes/confirming a prompt.
|
| 67 |
+
6. "confirmation_no": Choose this if the user is saying no/declining.
|
| 68 |
+
|
| 69 |
+
CRITICAL INSTRUCTIONS:
|
| 70 |
+
- You are the orchestrator. If a request is invalid, missing context, or vague, use "reply_directly" to ask the user to clarify. Do NOT trigger a generation task if the input is bad.
|
| 71 |
+
- NEVER choose "trigger_feature_generation" if the project title is just a single word, a brand name, or lacks technical description (e.g. "Fixy", "My Project", "Test"). You MUST choose "reply_directly" and ask the user to provide a descriptive technical title that explains what the system actually does.
|
| 72 |
+
- Return ONLY a valid JSON object. Do NOT include markdown blocks.
|
| 73 |
+
|
| 74 |
+
JSON Format:
|
| 75 |
+
{{
|
| 76 |
+
"action": "exact_action_name",
|
| 77 |
+
"reply_text": "text to reply to the user (ONLY if action is reply_directly, otherwise null)",
|
| 78 |
+
"extracted_domain": "extract_domain_if_mentioned_else_null",
|
| 79 |
+
"extracted_title": "extract_project_title_if_mentioned_else_null"
|
| 80 |
+
}}
|
| 81 |
+
"""
|
| 82 |
+
try:
|
| 83 |
+
raw_response = generate_text(prompt, task="intent").strip()
|
| 84 |
+
|
| 85 |
+
# Remove markdown code blocks if present
|
| 86 |
+
if raw_response.startswith("```"):
|
| 87 |
+
lines = raw_response.splitlines()
|
| 88 |
+
if lines[0].startswith("```"):
|
| 89 |
+
lines = lines[1:]
|
| 90 |
+
if lines[-1].startswith("```"):
|
| 91 |
+
lines = lines[:-1]
|
| 92 |
+
raw_response = "\n".join(lines).strip()
|
| 93 |
+
|
| 94 |
+
parsed = json.loads(raw_response)
|
| 95 |
+
import logging
|
| 96 |
+
logging.info(f"DEBUG LLM ROUTER PARSED: {parsed}")
|
| 97 |
+
|
| 98 |
+
action = parsed.get("action", "reply_directly")
|
| 99 |
+
reply_text = parsed.get("reply_text")
|
| 100 |
+
domain = parsed.get("extracted_domain") or extract_domain(text)
|
| 101 |
+
project_title = parsed.get("extracted_title")
|
| 102 |
+
|
| 103 |
+
return {
|
| 104 |
+
"action": action,
|
| 105 |
+
"reply_text": reply_text,
|
| 106 |
+
"domain": domain,
|
| 107 |
+
"project_title": project_title,
|
| 108 |
+
"number": number
|
| 109 |
+
}
|
| 110 |
+
except Exception as e:
|
| 111 |
+
import logging
|
| 112 |
+
logging.error(f"DEBUG LLM ROUTER EXCEPTION: {e}")
|
| 113 |
+
# Fallback
|
| 114 |
+
domain = extract_domain(text)
|
| 115 |
+
action = "reply_directly"
|
| 116 |
+
reply_text = None
|
| 117 |
+
project_title = None
|
| 118 |
+
|
| 119 |
+
return {
|
| 120 |
+
"action": action,
|
| 121 |
+
"reply_text": reply_text,
|
| 122 |
+
"domain": domain,
|
| 123 |
+
"project_title": project_title,
|
| 124 |
+
"number": number
|
| 125 |
+
}
|
src/recommendation_engine/response_formatter.py
CHANGED
|
@@ -84,14 +84,11 @@ def next_step(state: Dict[str, Any]) -> str:
|
|
| 84 |
"2️⃣ Generate another idea\n"
|
| 85 |
)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
|
| 96 |
def format_full_project(state: Dict[str, Any]) -> str:
|
| 97 |
|
|
|
|
| 84 |
"2️⃣ Generate another idea\n"
|
| 85 |
)
|
| 86 |
|
| 87 |
+
return (
|
| 88 |
+
"👉 Next options:\n"
|
| 89 |
+
"1️⃣ Improve these features\n"
|
| 90 |
+
"2️⃣ Generate full project"
|
| 91 |
+
)
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
def format_full_project(state: Dict[str, Any]) -> str:
|
| 94 |
|
src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc and b/src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc and b/src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc differ
|
|
|