Skip to content

Commit 2470f39

Browse files
authored
Recurring suggestions for AI Chat (#23)
* fix: update suggestion display logic and manage loading states in AI chat component * fix: restore smooth scrolling functionality * fix: ensure smooth scrolling is applied after chat updates * fix: ensure smooth scrolling is triggered after chat suggestions are generated * fix: enhance suggestion handling by improving suggestion structure * fix: enhance suggestion generation accuracy and relevance * fix: streamline suggestion payload by consolidating properties * refactor: var name change
1 parent c49a3db commit 2470f39

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

backend/api/chat_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def get_suggestions():
6060
description=data["description"],
6161
type=data["type"],
6262
requirement=data["requirement"],
63+
suggestions=data["suggestions"],
64+
selectedSuggestion=data["selectedSuggestion"],
6365
)
6466
llm_response = llm_service.call_llm(template, knowledge_base=knowledge_base)
6567

backend/llm/prompts/chat/improve_suggestions.jinja2

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
You are an AI assistant tasked with generating {{n}} creative and practical one-liner suggestions(not more than 5 words) to improve an abstract requirement.
2-
The requirement is not fully detailed and may lack specific context, so your suggestions should be broad, versatile, and aimed at enhancing clarity, feasibility, and overall effectiveness. Consider potential gaps, ambiguities, and areas for innovation.
2+
The requirement is not fully detailed and may lack specific context, so your suggestions should be broad, versatile, and aimed at enhancing clarity, feasibility, and overall effectiveness. Consider potential gaps, ambiguities, and areas for innovation. Ensure the suggestions you generate are accurate, relevant, and aligned with the abstract requirement.
33

44
Application
55
Name: {{name}}
@@ -15,6 +15,16 @@ Suggestion 2:
1515
Suggestion 3:
1616
[Provide a creative one-liner suggestion encouraging innovation and new solutions.]
1717
-----------
18+
Cardinal rule:
19+
Do not repeat suggestions. Here are the suggestions that were already provided and relevant to the Abstract Requirement provided.
20+
{{suggestions}}
21+
Strictly do not provide any one of these.
22+
{% if selectedSuggestion %}
23+
-----------
24+
Improve the suggestions you are going to generate based on the following suggestion since it was selected by the user but quickly rejected by the user:
25+
{{selectedSuggestion}}
26+
-----------
27+
{% endif %}
1828
Output Structure should be a valid JSON: Here is the sample Structure. Follow this exactly. Don't add or change the response JSON:
1929
["Suggestion 1", "Suggestion 2", ... "Suggestion n"]
2030
Output only valid JSON. Do not include ```json ``` on start and end of the response.

backend/schemas/chat_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class ImproveSuggestionSchema(Schema):
1010
description=fields.String(required=True)
1111
type=fields.String(required=True)
1212
requirement=fields.String(required=True)
13+
suggestions=fields.List(fields.String, required=True)
14+
selectedSuggestion=fields.String(required=False)
1315
knowledgeBase=fields.String(required=False)
1416

15-
16-
1717
class ConverseRequirementSchema(Schema):
1818
name=fields.String(required=True)
1919
description=fields.String(required=True)

ui/src/app/components/ai-chat/ai-chat.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
</div>
9494

9595
<!-- Suggestions Area -->
96-
<div *ngIf="chatHistory.length == 0" class="flex-none bg-white px-6 py-4">
96+
<div *ngIf="!responseStatus && !generateLoader" class="flex-none bg-white px-6 py-4">
9797
<!-- Loading State -->
9898
<div *ngIf="loadingChat" class="flex items-start gap-3 mb-3">
9999
<div class="flex-none bg-gray-100 rounded-full flex items-center justify-center w-10 h-10">
@@ -104,7 +104,7 @@
104104

105105
<!-- Suggestions List -->
106106
<div *ngIf="!loadingChat && chatSuggestions.length > 0">
107-
<div class="text-sm text-gray-600 font-medium mb-3">Suggestions to improve:</div>
107+
<div class="text-sm text-gray-600 font-medium mb-3" *ngIf="chatHistory.length == 0">Suggestions to improve:</div>
108108
<ul class="flex flex-wrap gap-2">
109109
<li *ngFor="let suggestion of chatSuggestions"
110110
class="flex items-center gap-2 text-sm py-2 px-4 rounded-full bg-gray-100 shadow-sm hover:shadow-md cursor-pointer transition-shadow duration-200 border border-slate-200"
@@ -151,7 +151,7 @@
151151
placeholder="Chat to add or modify your requirement"
152152
[disabled]="generateLoader"
153153
[(ngModel)]="message"
154-
class="w-full h-14 text-sm bg-transparent text-gray-700 focus:outline-none placeholder:text-gray-500 focus:outline-none focus:right-0 resize-none overflow-x-hidden overflow-y-auto transition-all duration-300 ease-in-out"
154+
class="w-full h-14 text-sm bg-transparent text-gray-700 focus:outline-none placeholder:text-gray-500 focus:right-0 resize-none overflow-x-hidden overflow-y-auto transition-all duration-300 ease-in-out"
155155
></textarea>
156156
</div>
157157

ui/src/app/components/ai-chat/ai-chat.component.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ export class AiChatComponent implements OnInit {
9797
projectId: string = '';
9898
message: string = '';
9999
chatSuggestions: Array<string> = [];
100+
localSuggestions: Array<string> = [];
101+
selectedSuggestion: string = '';
100102
generateLoader: boolean = false;
101103
loadingChat: boolean = false;
104+
responseStatus: boolean = false;
102105
kb: string = '';
103106
isKbActive: boolean = false;
104107

@@ -164,21 +167,32 @@ export class AiChatComponent implements OnInit {
164167
requirement: this.baseContent,
165168
knowledgeBase: this.kb,
166169
};
167-
if (this.chatHistory.length == 0) this.getSuggestion();
170+
this.getSuggestion();
168171
}, 1000);
169172
}
170173

171174
getSuggestion() {
172175
this.loadingChat = true;
176+
const suggestionPayload: suggestionPayload = {
177+
...this.basePayload,
178+
requirement: this.baseContent,
179+
suggestions: this.localSuggestions,
180+
selectedSuggestion: this.selectedSuggestion,
181+
};
173182
this.chatService
174-
.generateSuggestions(this.basePayload).subscribe({
183+
.generateSuggestions(suggestionPayload).subscribe({
175184
next: (response: Array<''>) => {
176185
this.chatSuggestions = response;
186+
this.localSuggestions.push(...response);
177187
this.loadingChat = false;
188+
this.responseStatus = false;
189+
this.smoothScroll();
178190
},
179191
error: (err) => {
180192
this.toastService.showError(ERROR_MESSAGES.GENERATE_SUGGESTIONS_FAILED);
181193
this.loadingChat = false;
194+
this.responseStatus = false;
195+
this.smoothScroll();
182196
}
183197
});
184198
}
@@ -204,7 +218,7 @@ export class AiChatComponent implements OnInit {
204218
this.generateLoader = false;
205219
this.chatHistory = [...this.chatHistory, { assistant: response }];
206220
this.returnChatHistory();
207-
this.smoothScroll();
221+
this.getSuggestion();
208222
});
209223
}
210224

@@ -226,6 +240,7 @@ export class AiChatComponent implements OnInit {
226240
chatHistory: this.chatHistory,
227241
};
228242
this.getContent.emit(data);
243+
this.getSuggestion();
229244
}
230245

231246
returnChatHistory() {
@@ -299,6 +314,9 @@ export class AiChatComponent implements OnInit {
299314
}
300315

301316
converse(message: string) {
317+
this.responseStatus = true;
318+
this.selectedSuggestion = message;
319+
this.chatSuggestions = [];
302320
if (message || this.selectedFiles.length > 0) {
303321
this.generateLoader = true;
304322

@@ -341,6 +359,7 @@ export class AiChatComponent implements OnInit {
341359
this.message = '';
342360
this.selectedFiles = [];
343361
this.selectedFilesContent = '';
362+
this.responseStatus = false;
344363
}
345364
}
346365

@@ -358,9 +377,6 @@ export class AiChatComponent implements OnInit {
358377
knowledgeBase: this.kb
359378
};
360379

361-
// Only refresh suggestions if we're at the initial state
362-
if (this.chatHistory.length === 0) {
363-
this.getSuggestion();
364-
}
380+
this.getSuggestion();
365381
}
366382
}

ui/src/app/model/interfaces/chat.interface.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export interface suggestionPayload {
33
description: string;
44
type: string;
55
requirement: string;
6+
suggestions?: Array<string>;
7+
selectedSuggestion?: string;
68
knowledgeBase?: string;
79
}
810

0 commit comments

Comments
 (0)