ng-implementation/sae-csc/src/app/pages/testing-api/testing-api.ts
2025-10-01 16:58:05 +02:00

118 lines
2.9 KiB
TypeScript

import {Component} from '@angular/core';
import {MainButton} from 'sae-lib/buttons/main-button/main-button';
import {FormsModule} from '@angular/forms';
import {BotTalks} from 'sae-lib/chatbot/bot-talks/bot-talks';
let defaultHeaders = {
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
'Access-Control-Allow-Methods': 'OPTIONS,POST',
'Access-Control-Allow-Origin': '*'
};
@Component({
selector: 'app-testing-api',
imports: [
MainButton,
FormsModule,
BotTalks
],
templateUrl: './testing-api.html',
styleUrl: './testing-api.scss'
})
export class TestingApi {
protected response: string = "(pas de réponse pour le moment)";
protected backend: string = "localhost";
protected input: string = "bonjour le backend";
protected message: string = "salut, ici le backend";
protected conversationID: string = "1234";
constructor() {
}
login() {
fetch(`http://${this.backend}/login`, {})
.then(response => response.json())
.then(data => {
console.log(data);
this.response = JSON.stringify(data);
}
)
.catch(error => console.error('Error:', error));
}
sendMessage() {
const dataBody = JSON.stringify({
question: "What are the main causes of engine failures in Boeing 737?",
conversationId: "uuid-optional",
databases: [
"Incident Reports", "Academic Papers",
"General Reports", "Patent Files",
"Press Articles", "Safety Directives"
],
search_engines: [
"Google Search", "Google Patents", "Google Scholar"
],
qualification_tag: "auto"
// / "specific_question" / "structured_list" / "conv_continuation"
})
fetch(`http://${this.backend}/api/v1/messages`, {
method: "POST",
mode: "cors",
body: dataBody,
headers: defaultHeaders
})
.then(response => response.json())
.then(data => {
console.log(data);
this.response = JSON.stringify(data);
}
)
.catch(error => console.error('Error:', error));
}
sendFeedback() {
const dataBody = JSON.stringify({
feedback: "This response was very helpful and accurate"
})
fetch(`http://${this.backend}/api/v1/${this.conversationID}/feedback`, {
method: "POST",
mode: "cors",
body: dataBody
})
.then(response => response.json())
.then(data => {
console.log(data);
this.response = JSON.stringify(data);
}
)
.catch(error => console.error('Error:', error));
}
sendFile() {
console.log('sendFile TODO')
}
deleteConversation() {
console.log('sendFile TODO')
}
getLastAnswer() {
console.log('getLastAnswer TODO')
}
getHistory() {
console.log('getHistory TODO')
}
getUserConversations() {
console.log('getUserConversations TODO')
}
}