fix(stream err on changing conversation)

This commit is contained in:
ManishMadan2882
2024-02-07 04:42:39 +05:30
parent 300430e2d5
commit 3c68cbc955
5 changed files with 36 additions and 19 deletions

View File

@@ -16,17 +16,21 @@ const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
'fetchAnswer',
async ({ question }, { dispatch, getState }) => {
async ({ question }, { dispatch, getState, signal }) => {
const state = getState() as RootState;
console.log('signal', signal);
if (state.preference) {
if (API_STREAMING) {
await fetchAnswerSteaming(
question,
signal,
state.preference.apiKey,
state.preference.selectedDocs!,
state.conversation.queries,
state.conversation.conversationId,
state.preference.prompt.id,
(event) => {
const data = JSON.parse(event.data);
@@ -78,6 +82,7 @@ export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
} else {
const answer = await fetchAnswerApi(
question,
signal,
state.preference.apiKey,
state.preference.selectedDocs!,
state.conversation.queries,
@@ -193,6 +198,7 @@ export const conversationSlice = createSlice({
state.status = 'loading';
})
.addCase(fetchAnswer.rejected, (state, action) => {
if(action.meta.aborted)return state; //ignore error
state.status = 'failed';
state.queries[state.queries.length - 1].error =
'Something went wrong. Please try again later.';