| from typing import Dict, Any, List |
|
|
| def unique_items(items: List[str]) -> List[str]: |
|
|
| seen = set() |
|
|
| final = [] |
|
|
| for item in items: |
|
|
| key = str(item).strip().lower() |
|
|
| if not key: |
| continue |
|
|
| if key not in seen: |
| seen.add(key) |
| final.append(str(item).strip()) |
|
|
| return final |
|
|
| def format_list( |
| items: List[str], |
| prefix: str = "- " |
| ) -> str: |
|
|
| items = unique_items(items) |
|
|
| if not items: |
| return "None" |
|
|
| return "\n".join( |
| f"{prefix}{item}" |
| for item in items |
| ) |
|
|
| def clean_text(text: str) -> str: |
|
|
| if not text: |
| return "" |
|
|
| text = str(text).strip() |
|
|
| |
| bad_prefixes = [ |
| "assistant:", |
| "π€ assistant:", |
| "bot:" |
| ] |
|
|
| lower = text.lower() |
|
|
| for prefix in bad_prefixes: |
|
|
| if lower.startswith(prefix): |
|
|
| text = text[len(prefix):].strip() |
|
|
| return text |
|
|
| def divider() -> str: |
| return "ββββββββββββββββββββββ" |
|
|
| def next_step(state: Dict[str, Any]) -> str: |
|
|
| |
| |
| |
| if not state.get("project_title"): |
|
|
| return ( |
| "π Ask for project ideas " |
| "or specify a domain." |
| ) |
|
|
| |
| |
| |
| if not state.get("features"): |
|
|
| return ( |
| "π Next options:\n" |
| "1οΈβ£ Generate features\n" |
| "2οΈβ£ Generate another idea\n" |
| ) |
|
|
| return ( |
| "π Next options:\n" |
| "1οΈβ£ Improve these features\n" |
| "2οΈβ£ Generate full project" |
| ) |
|
|
| def format_full_project(state: Dict[str, Any]) -> str: |
|
|
| title = state.get("project_title", "Not defined") |
|
|
| features = unique_items( |
| state.get("features", []) |
| ) |
|
|
| description = clean_text( |
| state.get("description", "Not generated") |
| ) |
|
|
| technologies = state.get("technologies", []) |
|
|
| originality = state.get( |
| "originality_score", |
| "Unknown" |
| ) |
|
|
| context_strength = state.get( |
| "context_strength", |
| "Unknown" |
| ) |
|
|
| return f""" |
| π¦ Full Project Overview |
| |
| π Project Title: |
| {title} |
| |
| βοΈ Smart Features: |
| {format_list(features)} |
| |
| π Description: |
| {description} |
| |
| π§ Suggested Technologies: |
| {", ".join(technologies) if technologies else "Not defined"} |
| |
| β Originality Score: |
| {originality} |
| |
| π Similarity Context: |
| {context_strength} |
| """.strip() |
|
|
| def format_response( |
| intent: str, |
| raw_response: str, |
| state: Dict[str, Any] |
| ) -> str: |
|
|
| title = state.get("project_title", "") |
|
|
| ideas = unique_items( |
| state.get("ideas", []) |
| ) |
|
|
| features = unique_items( |
| state.get("features", []) |
| ) |
|
|
| description = clean_text( |
| state.get("description", "") |
| ) |
|
|
| |
| |
| |
| if intent == "idea": |
|
|
| if not ideas: |
| return "β οΈ No project ideas generated." |
|
|
| return f""" |
| π‘ Suggested Project Ideas |
| |
| {format_list(ideas)} |
| |
| {divider()} |
| {next_step(state)} |
| """.strip() |
|
|
| |
| |
| |
| if intent == "feature": |
|
|
| if not features: |
| return "β οΈ No features generated." |
|
|
| return f""" |
| βοΈ Smart Features for: |
| {title or "Selected Project"} |
| |
| {format_list(features)} |
| |
| {divider()} |
| {next_step(state)} |
| """.strip() |
|
|
| |
| |
| |
| if intent == "description": |
|
|
| return f""" |
| π Project Description |
| |
| π {title or "Your Project"} |
| |
| {description} |
| |
| {divider()} |
| {next_step(state)} |
| """.strip() |
|
|
| |
| |
| |
| if intent == "full_project": |
|
|
| return f""" |
| {format_full_project(state)} |
| |
| {divider()} |
| π You can continue improving the project. |
| """.strip() |
|
|
| |
| |
| |
| cleaned = clean_text(raw_response) |
|
|
| return f""" |
| π¬ Project Assistant |
| |
| {cleaned} |
| |
| {divider()} |
| π Current Project: |
| {title or "Not defined"} |
| |
| {divider()} |
| {next_step(state)} |
| """.strip() |
|
|