-
Notifications
You must be signed in to change notification settings - Fork 1
/
llama.service.ts
50 lines (47 loc) · 1.94 KB
/
llama.service.ts
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
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LlamaResponseResult } from '../../models/llama-response.interface';
import { BehaviorSubject, Observable, of, tap } from 'rxjs';
import { LlamaResponseMock } from '../../mocks/LlamaResponse.mock';
import { FEEDBACK } from 'src/app/models/feedback.enum';
@Injectable({
providedIn: 'root'
})
export class LlamaService {
private httpClient = inject(HttpClient);
private lastQuestionAsked = new BehaviorSubject('');
private lastResults = new BehaviorSubject<LlamaResponseResult>({} as LlamaResponseResult);
askQuestion(question: string, userId: string): Observable<LlamaResponseResult> {
console.log('endpoint: /askQuestion');
console.log('body', { question, userId });
// return of(LlamaResponseMock).pipe(
// tap(data => {
// this.lastResults.next(data);
// this.lastQuestionAsked.next(question);
// })
// );
return this.httpClient.post<LlamaResponseResult>('http://127.0.0.1:8000/askQuestion/', { question, userId }).pipe(
tap(data => {
this.lastResults.next(data);
this.lastQuestionAsked.next(question);
})
);
}
sendFeedback(feedback: FEEDBACK, userId: string): Observable<boolean> {
console.log('endpoint: /sendFeedback');
console.log('body', {
feedback,
userId,
question: this.lastQuestionAsked.getValue(),
results: this.lastResults.getValue()
});
// return of(true);
return this.httpClient.post<boolean>('http://127.0.0.1:8000/sendFeedback/'
, {
feedback,
userId,
previousQuestion: this.lastQuestionAsked.getValue(),
previousResults: this.lastResults.getValue()
});
}
}