|
|
@@ -0,0 +1,53 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { HttpClient, HttpClientModule } from '@angular/common/http';
|
|
|
+import { MatCardModule } from '@angular/material/card';
|
|
|
+import { MatInputModule } from '@angular/material/input';
|
|
|
+import { MatButtonModule } from '@angular/material/button';
|
|
|
+import { MatListModule } from '@angular/material/list';
|
|
|
+import { webConfig } from '../config';
|
|
|
+
|
|
|
+interface ChatMessage {
|
|
|
+ content: string;
|
|
|
+ sender: 'user' | 'bot';
|
|
|
+}
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-chat',
|
|
|
+ standalone: true,
|
|
|
+ imports: [CommonModule, FormsModule, HttpClientModule, MatCardModule, MatInputModule, MatButtonModule, MatListModule],
|
|
|
+ templateUrl: './chat.component.html',
|
|
|
+ styleUrls: ['./chat.component.css']
|
|
|
+})
|
|
|
+export class ChatComponent {
|
|
|
+ messages: ChatMessage[] = [];
|
|
|
+ inputMessage: string = '';
|
|
|
+ loading = false;
|
|
|
+
|
|
|
+ constructor(private http: HttpClient) {}
|
|
|
+
|
|
|
+ sendMessage() {
|
|
|
+ if (!this.inputMessage.trim()) return;
|
|
|
+
|
|
|
+ const userMessage: ChatMessage = { content: this.inputMessage, sender: 'user' };
|
|
|
+ this.messages.push(userMessage);
|
|
|
+
|
|
|
+ const messageToSend = this.inputMessage;
|
|
|
+ this.inputMessage = '';
|
|
|
+ this.loading = true;
|
|
|
+
|
|
|
+ this.http.post<{ answer: string }>(`${webConfig.exposedUrl}/api/ffb-production/query`, { message: messageToSend })
|
|
|
+ .subscribe({
|
|
|
+ next: (res) => {
|
|
|
+ this.messages.push({ content: res.answer, sender: 'bot' });
|
|
|
+ this.loading = false;
|
|
|
+ },
|
|
|
+ error: (err) => {
|
|
|
+ console.error(err);
|
|
|
+ this.messages.push({ content: 'Error: Could not get response.', sender: 'bot' });
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|