-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intelligence Service MVP Chat Interface #169
Merged
FelixTJDietrich
merged 53 commits into
feature/java-chat-mvp-intelligence-service
from
feature/interface-chat-mvp-intelligence-service
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
723d3d3
Add mocked chat interface
milesha a767111
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha aee2967
Change header design
milesha 4da1bec
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha ae650a7
Add session history
milesha c7d9c01
Add autoscrolling
milesha 404fa8b
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 6992fad
Add session card
milesha 8e6518e
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha e3d7af9
Add infromation fetching
milesha fc41a8a
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 8ada388
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 0c18b83
Update creation prop
milesha ee20325
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 9cead8f
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha b73becf
Update icon
milesha 8e561bb
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 0a3d017
Update AI mentor button
milesha 20f555c
Add dynamic session list
milesha e186137
Add data fetching
milesha d8d04ba
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 9eca357
Add backend connection
milesha 82ac250
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 9b8c3f0
Improve layout
milesha 338843f
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha b3a661a
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 46d1f0c
Fix prettier issues
milesha 7daf291
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 30b64a9
Change access roles
milesha a1470a7
Add storybook
milesha 20d1eb0
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha e4af9f6
Imrove bot usability
milesha ae370be
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha b959388
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 91007bc
Update prettier version
milesha 7f3e20b
Delete angular analytics setting
milesha 7aefd9d
Delete console log
milesha 6b602fa
Improve code quality
milesha 67d66c4
change bot icon
milesha c419390
Reverse session order and update selected session on success
milesha 219090f
Add enter key functionality to send message in chat input
milesha ce1f95b
Clear message input after sending with a slight delay
milesha c7ba180
improve layout
milesha 7ef9a41
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha f7c41d5
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 3ef7b80
update dark mode color
milesha 3acd54c
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha ee21f79
update naming
milesha 74a72fc
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 5dfe8bc
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha 2faceb2
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
milesha f2b5d4c
Fix formating
milesha f150136
Merge branch 'feature/java-chat-mvp-intelligence-service' into featur…
FelixTJDietrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@if (isLoading()) { | ||
<div class="h-[calc(100vh-100px)] self-auto p-4 flex-1 flex items-center justify-center"> | ||
<hlm-spinner></hlm-spinner> | ||
</div> | ||
} @else { | ||
<div class="grid grid-cols-1 gap-x-5 md:grid-cols-4 md:h-[calc(100vh-100px)]"> | ||
@if (sessions().length === 0) { | ||
<div class="col-span-4 h-[calc(100vh-100px)]"> | ||
<app-first-session-card (createSession)="handleCreateSession()"></app-first-session-card> | ||
</div> | ||
} @else { | ||
<app-sessions-card | ||
[sessions]="sessions()" | ||
[activeSessionId]="selectedSession()?.id ?? null" | ||
(sessionSelected)="handleSessionSelect($event)" | ||
(createSession)="handleCreateSession()" | ||
class="h-full overflow-auto" | ||
></app-sessions-card> | ||
|
||
@if (selectedSession()) { | ||
<div class="flex flex-col h-[calc(100vh-100px)] md:col-span-3"> | ||
<app-messages [messageHistory]="messageHistory()" class="flex-1 overflow-y-auto p-4 space-y-4"></app-messages> | ||
<app-chat-input (messageSent)="handleSendMessage($event)" class="border-t pt-4 px-4"></app-chat-input> | ||
</div> | ||
} | ||
} | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { Component, inject, signal } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { lastValueFrom } from 'rxjs'; | ||
import { injectMutation, injectQuery } from '@tanstack/angular-query-experimental'; | ||
import { SessionsCardComponent } from '../sessions-card/sessions-card.component'; | ||
import { MessagesComponent } from '../messages/messages.component'; | ||
import { InputComponent } from '../input/input.component'; | ||
import { SecurityStore } from '@app/core/security/security-store.service'; | ||
import { Message, Session } from '@app/core/modules/openapi'; | ||
import { MessageService, SessionService } from '@app/core/modules/openapi'; | ||
import { HlmButtonModule } from '@spartan-ng/ui-button-helm'; | ||
import { HlmSpinnerComponent } from '@spartan-ng/ui-spinner-helm'; | ||
import { FirstSessionCardComponent } from '../first-session-card/first-session-card.component'; | ||
|
||
@Component({ | ||
selector: 'app-chat', | ||
templateUrl: './chat.component.html', | ||
standalone: true, | ||
imports: [CommonModule, FirstSessionCardComponent, HlmSpinnerComponent, SessionsCardComponent, MessagesComponent, InputComponent, HlmButtonModule] | ||
}) | ||
export class ChatComponent { | ||
securityStore = inject(SecurityStore); | ||
messageService = inject(MessageService); | ||
sessionService = inject(SessionService); | ||
|
||
signedIn = this.securityStore.signedIn; | ||
user = this.securityStore.loadedUser; | ||
|
||
messageHistory = signal<Message[]>([]); | ||
selectedSession = signal<Session | null>(null); | ||
sessions = signal<Session[]>([]); | ||
isLoading = signal(true); | ||
|
||
latestMessageContent = ''; | ||
|
||
protected query_sessions = injectQuery(() => ({ | ||
enabled: this.signedIn(), | ||
queryKey: ['sessions', { login: this.user()?.username }], | ||
queryFn: async () => { | ||
const username = this.user()?.username; | ||
if (!username) { | ||
throw new Error('User is not logged in or username is undefined.'); | ||
} | ||
const sessions = await lastValueFrom(this.sessionService.getSessions(username)); | ||
if (sessions.length > 0 && this.selectedSession() == null) { | ||
this.selectedSession.set(sessions.slice(-1)[0]); | ||
} | ||
this.sessions.set(sessions.reverse()); | ||
this.isLoading.set(false); | ||
return sessions; | ||
} | ||
})); | ||
|
||
handleSessionSelect(sessionId: number): void { | ||
const session = this.sessions().find((s) => s.id === sessionId); | ||
if (session) { | ||
this.selectedSession.set(session); | ||
this.query_sessions.refetch(); | ||
} | ||
} | ||
|
||
handleCreateSession(): void { | ||
this.createSession.mutate(); | ||
} | ||
|
||
protected createSession = injectMutation(() => ({ | ||
mutationFn: async () => { | ||
const username = this.user()?.username; | ||
if (!username) { | ||
throw new Error('User is not logged in or username is undefined.'); | ||
} | ||
await lastValueFrom(this.sessionService.createSession(username)); | ||
}, | ||
onSuccess: async () => { | ||
await this.query_sessions.refetch(); | ||
const sessions = this.sessions(); | ||
if (sessions.length > 0) { | ||
const newSession = sessions[0]; | ||
this.selectedSession.set(newSession); | ||
} | ||
} | ||
})); | ||
|
||
protected query_messages = injectQuery(() => ({ | ||
enabled: !!this.selectedSession, | ||
queryKey: ['messages', { sessionId: this.selectedSession()?.id }], | ||
queryFn: async () => { | ||
const selectedSessionId = this.selectedSession()?.id; | ||
if (selectedSessionId == null) { | ||
throw new Error('No session selected!'); | ||
} | ||
const loadedMessages = await lastValueFrom(this.messageService.getMessages(selectedSessionId)); | ||
this.messageHistory.set(loadedMessages); | ||
return loadedMessages; | ||
} | ||
})); | ||
|
||
protected sendMessage = injectMutation(() => ({ | ||
queryKey: ['messages', 'create'], | ||
mutationFn: async ({ sessionId }: { sessionId: number }) => { | ||
if (!this.selectedSession) { | ||
throw new Error('No session selected!'); | ||
} | ||
await lastValueFrom(this.messageService.createMessage(sessionId, this.latestMessageContent)); | ||
}, | ||
onSuccess: () => { | ||
this.query_messages.refetch(); | ||
} | ||
})); | ||
|
||
handleSendMessage(content: string): void { | ||
if (!this.selectedSession) { | ||
console.error('No session selected!'); | ||
return; | ||
} | ||
|
||
const selectedSessionId = this.selectedSession()?.id; | ||
if (selectedSessionId == null) { | ||
console.error('No session selected!'); | ||
return; | ||
} else { | ||
// show the user message directly after sending | ||
const userMessage: Message = { | ||
id: Math.random(), // temporary id until the message is sent | ||
sessionId: selectedSessionId, | ||
sender: 'USER', | ||
content: content, | ||
sentAt: new Date().toISOString() | ||
}; | ||
|
||
this.messageHistory.set([...this.messageHistory(), userMessage]); | ||
|
||
this.latestMessageContent = content; | ||
this.sendMessage.mutate({ sessionId: selectedSessionId }); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
webapp/src/app/chat/first-session-card/first-session-card.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="flex flex-col items-center justify-center h-full space-y-6"> | ||
<div class="w-20 h-20 bg-transparent border-cyan-500 rounded-full flex items-center justify-center" style="border-width: 3px"> | ||
<lucide-angular [img]="BotMessageSquare" class="size-10 text-cyan-500" style="stroke-width: 1.5"></lucide-angular> | ||
</div> | ||
|
||
<h2 class="text-center text-xl text-gray-700 font-semibold max-w-3xl dark:text-white"> | ||
Meet Your Personal AI Mentor – designed to help you grow faster through focused and reflective learning sessions. Click below to begin! | ||
</h2> | ||
|
||
<a hlmBtn aria-describedby="Start First Session" class="bg-cyan-500 text-white p-4 rounded-lg hover:bg-cyan-600 cursor-pointer" (click)="handleCreateSession()" | ||
>Start First Session</a | ||
> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
webapp/src/app/chat/first-session-card/first-session-card.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Component, output } from '@angular/core'; | ||
import { LucideAngularModule, Plus, BotMessageSquare } from 'lucide-angular'; | ||
import { HlmButtonModule } from '@spartan-ng/ui-button-helm'; | ||
|
||
@Component({ | ||
selector: 'app-first-session-card', | ||
standalone: true, | ||
templateUrl: './first-session-card.component.html', | ||
imports: [LucideAngularModule, HlmButtonModule] | ||
}) | ||
export class FirstSessionCardComponent { | ||
protected Plus = Plus; | ||
protected BotMessageSquare = BotMessageSquare; | ||
|
||
createSession = output<void>(); | ||
|
||
handleCreateSession(): void { | ||
this.createSession.emit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="flex items-start space-x-3"> | ||
<textarea | ||
[(ngModel)]="messageText" | ||
placeholder="Message AI Mentor" | ||
style="resize: none" | ||
(keydown.enter)="onSend()" | ||
class="flex-1 bg-transparent px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring focus:ring-cyan-200" | ||
></textarea> | ||
<a | ||
hlmBtn | ||
hlmTooltipTrigger | ||
hlmTooltipContentClass="bg-cyan-500 text-white" | ||
aria-describedby="Send Message" | ||
(click)="onSend()" | ||
class="bg-cyan-500 text-white p-2 rounded-lg hover:bg-cyan-600" | ||
variant="default" | ||
size="icon" | ||
> | ||
<lucide-angular [img]="Send" class="size-6"></lucide-angular> | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Component, output } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { HlmCardModule } from '@spartan-ng/ui-card-helm'; | ||
|
||
import { HlmButtonModule } from '@spartan-ng/ui-button-helm'; | ||
import { LucideAngularModule, Send } from 'lucide-angular'; | ||
|
||
@Component({ | ||
selector: 'app-chat-input', | ||
templateUrl: './input.component.html', | ||
standalone: true, | ||
imports: [CommonModule, HlmButtonModule, FormsModule, HlmCardModule, LucideAngularModule] | ||
}) | ||
export class InputComponent { | ||
protected Send = Send; | ||
|
||
messageSent = output<string>(); | ||
messageText = ''; | ||
|
||
onSend() { | ||
if (this.messageText.trim() !== '') { | ||
milesha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.messageSent.emit(this.messageText); | ||
setTimeout(() => { | ||
this.messageText = ''; | ||
}, 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { argsToTemplate, type Meta, type StoryObj } from '@storybook/angular'; | ||
import { InputComponent } from './input.component'; | ||
|
||
const meta: Meta<InputComponent> = { | ||
component: InputComponent, | ||
tags: ['autodocs'], | ||
args: { | ||
messageText: '' | ||
} | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<InputComponent>; | ||
|
||
export const Default: Story = { | ||
render: (args) => ({ | ||
props: args, | ||
template: `<app-chat-input ${argsToTemplate(args)} />` | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div #chatMessagesContainer class="messages space-y-4 overflow-y-auto" style="max-height: 100%"> | ||
@for (message of messageHistory(); track message.id) { | ||
<div class="flex w-full" [ngClass]="{ 'justify-end': message.sender === 'USER', 'justify-start': message.sender === 'LLM' }"> | ||
<div class="flex space-x-2 md:w-3/5" [ngClass]="{ 'flex-row-reverse': message.sender === 'USER' }"> | ||
@if (message.sender === 'USER') { | ||
<div class="ml-2 flex flex-col"> | ||
<hlm-avatar> | ||
<img [src]="'https://github.com/' + user()!.username + '.png'" [alt]="user()?.name + '\'s avatar'" hlmAvatarImage /> | ||
<span hlmAvatarFallback> | ||
{{ user()?.name?.slice(0, 2)?.toUpperCase() ?? '?' }} | ||
</span> | ||
</hlm-avatar> | ||
</div> | ||
} | ||
|
||
@if (message.sender === 'LLM') { | ||
<div class="mr-2 flex flex-col"> | ||
<div class="w-10 h-10 bg-transparent border-2 border-cyan-500 rounded-full flex items-center justify-center"> | ||
<lucide-angular [img]="BotMessageSquare" class="size-6 text-cyan-500"></lucide-angular> | ||
</div> | ||
</div> | ||
} | ||
|
||
<div class="flex flex-col space-y-2" [ngClass]="{ 'items-end': message.sender === 'USER', 'items-start': message.sender === 'LLM' }"> | ||
<div | ||
[ngClass]="{ | ||
'bg-cyan-500 text-white': message.sender === 'USER', | ||
'bg-gray-200 text-black': message.sender === 'LLM' | ||
}" | ||
class="p-3 rounded-lg inline-block" | ||
style="width: fit-content" | ||
> | ||
<p>{{ message.content }}</p> | ||
</div> | ||
<span class="text-xs text-gray-500"> {{ message.sender === 'USER' ? 'You' : 'AI Mentor' }} · {{ message.sentAt | date: 'shortTime' }} </span> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Component, inject, input, OnInit, AfterViewChecked, ElementRef, ViewChild } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { LucideAngularModule, BotMessageSquare } from 'lucide-angular'; | ||
import { HlmAvatarModule } from '@spartan-ng/ui-avatar-helm'; | ||
import { SecurityStore } from '@app/core/security/security-store.service'; | ||
import { Message } from '@app/core/modules/openapi'; | ||
|
||
@Component({ | ||
selector: 'app-messages', | ||
templateUrl: './messages.component.html', | ||
standalone: true, | ||
imports: [CommonModule, LucideAngularModule, HlmAvatarModule] | ||
}) | ||
export class MessagesComponent implements OnInit, AfterViewChecked { | ||
protected BotMessageSquare = BotMessageSquare; | ||
|
||
securityStore = inject(SecurityStore); | ||
user = this.securityStore.loadedUser; | ||
signedIn = this.securityStore.signedIn; | ||
|
||
messageHistory = input<Message[]>([]); | ||
|
||
@ViewChild('chatMessagesContainer') private chatMessagesContainer!: ElementRef; | ||
|
||
ngOnInit() { | ||
this.scrollToBottom(); | ||
} | ||
|
||
ngAfterViewChecked() { | ||
this.scrollToBottom(); | ||
} | ||
|
||
private scrollToBottom(): void { | ||
try { | ||
if (this.chatMessagesContainer) { | ||
this.chatMessagesContainer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollHeight; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other components we try to go for Skeletons instead of Spinners since they are much easier on the eye in terms of layout shifts.
Try to integrate Skeletons in here too. You can pass the "loading"-state down to the individual components, which can then handle it themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GODrums
Sure, was thinking of it too - the only problem in this case is that i am not sure what I need to create a Skeleton for in this case: we have one view which is shown if there are no sessions yet and a completely different one for the actual chat interface. What should I then make a Skeleton for when in is "undecided", which view to show (the number of user sessions is loading)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I see your point here. I was a little confused about how the whole "fetching"-logic is fully contained in the
ChatComponent
.I would have thought of it this way (inspired by the way https://chatgpt.com/ works):
Maybe I'm overengineering this a little though, I think your approach is fine too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GODrums good idea! I would make an extra issue for this frontend improvement and come back to it in another PR then 👍🏼