Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update history method changes #295

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions ClientAdvisor/App/frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,31 +201,47 @@ export const selectUser = async (options: ClientIdRequest): Promise<Response> =>
return new Response(null, { status: 500, statusText: 'Internal Server Error' });
}
};

function isLastObjectNotEmpty(arr:any)
{
if (arr.length === 0) return false;
// Handle empty array case
const lastObj = arr[arr.length - 1];
return Object.keys(lastObj).length > 0;
}
export const historyUpdate = async (messages: ChatMessage[], convId: string): Promise<Response> => {
const response = await fetch('/history/update', {
method: 'POST',
body: JSON.stringify({
conversation_id: convId,
messages: messages
}),
headers: {
'Content-Type': 'application/json'
}
})
.then(async res => {
return res
if(isLastObjectNotEmpty(messages)){
const response = await fetch('/history/update', {
method: 'POST',
body: JSON.stringify({
conversation_id: convId,
messages: messages
}),
headers: {
'Content-Type': 'application/json'
}
})
.catch(_err => {
console.error('There was an issue fetching your data.')
.then(async res => {
return res
})
.catch(_err => {
console.error('There was an issue fetching your data.')
const errRes: Response = {
...new Response(),
ok: false,
status: 500
}
return errRes
})
return response
}
else{
const errRes: Response = {
...new Response(),
ok: false,
status: 500
}
return errRes
})
return response
return errRes
}
}

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

// const data = await response.text();
// console.log('Response:', data);
// };
// };