bat-6's picture
feat: add configuration module, response formatting utilities, and initialized project data structure for recommendation engine
60cb4b3
Raw
History Blame Contribute Delete
3.82 kB
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()