File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed
Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change 11import { ChatApiResponse , ChatRequest , FeedbackRequest } from "./apiTypes/chatTypes" ;
22import { httpClient } from "../utils/httpClient/httpClient" ;
33
4+ /**
5+ * Chat completion service for sending messages and receiving AI responses
6+ */
47export async function Completion ( request : ChatRequest ) : Promise < ChatApiResponse > {
5- const response : ChatApiResponse = await httpClient . post ( `/chat` , request ) ;
6- return response ;
8+ try {
9+ const response : ChatApiResponse = await httpClient . post ( `/chat` , request ) ;
10+
11+ // Basic validation of response structure
12+ if ( ! response || typeof response . answer !== 'string' ) {
13+ throw new Error ( 'Invalid response format from chat service' ) ;
14+ }
15+
16+ return response ;
17+ } catch ( error ) {
18+ console . error ( 'Chat completion failed:' , error ) ;
19+ throw error ;
20+ }
721}
822
23+ /**
24+ * Submit user feedback for chat responses
25+ */
926export async function PostFeedback ( request : FeedbackRequest ) : Promise < boolean > {
10- const response : boolean = await httpClient . post ( `/api/Chat/Feedback` , request ) ;
11- return response ;
27+ try {
28+ const response : boolean = await httpClient . post ( `/api/Chat/Feedback` , request ) ;
29+ return response ;
30+ } catch ( error ) {
31+ console . error ( 'Feedback submission failed:' , error ) ;
32+ throw error ;
33+ }
1234}
You can’t perform that action at this time.
0 commit comments