Skip to content

Commit 2adf389

Browse files
update history method changes (#295)
1 parent a582ee1 commit 2adf389

File tree

1 file changed

+35
-19
lines changed
  • ClientAdvisor/App/frontend/src/api

1 file changed

+35
-19
lines changed

ClientAdvisor/App/frontend/src/api/api.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,31 +201,47 @@ export const selectUser = async (options: ClientIdRequest): Promise<Response> =>
201201
return new Response(null, { status: 500, statusText: 'Internal Server Error' });
202202
}
203203
};
204-
204+
function isLastObjectNotEmpty(arr:any)
205+
{
206+
if (arr.length === 0) return false;
207+
// Handle empty array case
208+
const lastObj = arr[arr.length - 1];
209+
return Object.keys(lastObj).length > 0;
210+
}
205211
export const historyUpdate = async (messages: ChatMessage[], convId: string): Promise<Response> => {
206-
const response = await fetch('/history/update', {
207-
method: 'POST',
208-
body: JSON.stringify({
209-
conversation_id: convId,
210-
messages: messages
211-
}),
212-
headers: {
213-
'Content-Type': 'application/json'
214-
}
215-
})
216-
.then(async res => {
217-
return res
212+
if(isLastObjectNotEmpty(messages)){
213+
const response = await fetch('/history/update', {
214+
method: 'POST',
215+
body: JSON.stringify({
216+
conversation_id: convId,
217+
messages: messages
218+
}),
219+
headers: {
220+
'Content-Type': 'application/json'
221+
}
218222
})
219-
.catch(_err => {
220-
console.error('There was an issue fetching your data.')
223+
.then(async res => {
224+
return res
225+
})
226+
.catch(_err => {
227+
console.error('There was an issue fetching your data.')
228+
const errRes: Response = {
229+
...new Response(),
230+
ok: false,
231+
status: 500
232+
}
233+
return errRes
234+
})
235+
return response
236+
}
237+
else{
221238
const errRes: Response = {
222239
...new Response(),
223240
ok: false,
224241
status: 500
225242
}
226-
return errRes
227-
})
228-
return response
243+
return errRes
244+
}
229245
}
230246

231247
export const historyDelete = async (convId: string): Promise<Response> => {
@@ -425,4 +441,4 @@ export const historyMessageFeedback = async (messageId: string, feedback: string
425441

426442
// const data = await response.text();
427443
// console.log('Response:', data);
428-
// };
444+
// };

0 commit comments

Comments
 (0)