Skip to content

Commit

Permalink
Merge pull request #1416 from siiddhantt/fix/sources-pending
Browse files Browse the repository at this point in the history
fix: pending sources even when no sources provided
  • Loading branch information
dartpain authored Nov 6, 2024
2 parents c3e85d7 + ebbd47c commit e027189
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/conversation/conversationSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
'fetchAnswer',
async ({ question }, { dispatch, getState, signal }) => {
let isSourceUpdated = false;
const state = getState() as RootState;
if (state.preference) {
if (API_STREAMING) {
Expand All @@ -36,9 +37,7 @@ export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
(event) => {
const data = JSON.parse(event.data);

// check if the 'end' event has been received
if (data.type === 'end') {
// set status to 'idle'
dispatch(conversationSlice.actions.setStatus('idle'));
getConversations()
.then((fetchedConversations) => {
Expand All @@ -47,13 +46,22 @@ export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
.catch((error) => {
console.error('Failed to fetch conversations: ', error);
});
if (!isSourceUpdated) {
dispatch(
updateStreamingSource({
index: state.conversation.queries.length - 1,
query: { sources: [] },
}),
);
}
} else if (data.type === 'id') {
dispatch(
updateConversationId({
query: { conversationId: data.id },
}),
);
} else if (data.type === 'source') {
isSourceUpdated = true;
dispatch(
updateStreamingSource({
index: state.conversation.queries.length - 1,
Expand Down

0 comments on commit e027189

Please sign in to comment.