File size: 3,820 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
60cb4b3
 
 
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
4552666
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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()