31 lines
908 B
TypeScript
31 lines
908 B
TypeScript
import { inject, Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { API_URL } from '../core/tokens/api-urls';
|
|
import { ChatCollection, MessageCollection, MessageResponse, ChatResponse } from './chat.types';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ChatService {
|
|
private http = inject(HttpClient);
|
|
private apiUrl = inject(API_URL);
|
|
|
|
public newChat() {
|
|
return this.http.post<ChatResponse>(`${this.apiUrl}/chats`, {});
|
|
}
|
|
|
|
public sendMessage(id: string, message: string) {
|
|
return this.http.post<MessageResponse>(`${this.apiUrl}/chats/${id}/messages`, {
|
|
prompt: message,
|
|
});
|
|
}
|
|
|
|
public getMessages(id: string, page: number = 1) {
|
|
return this.http.get<MessageCollection>(`${this.apiUrl}/chats/${id}/messages?page=${page}`);
|
|
}
|
|
|
|
public getChats() {
|
|
return this.http.get<ChatCollection>(`${this.apiUrl}/chats`);
|
|
}
|
|
}
|