Working streaming

This commit is contained in:
Alex
2023-05-31 17:44:20 +01:00
parent 20c877f75b
commit fae3f55010
3 changed files with 50 additions and 34 deletions

View File

@@ -8,22 +8,20 @@ const initialState: ConversationState = {
status: 'idle',
};
const API_STREAMING = import.meta.env.API_STREAMING || false;
const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
'fetchAnswer',
async ({ question }, { dispatch, getState }) => {
const state = getState() as RootState;
if (state.preference) {
if (API_STREAMING) {
fetchAnswerSteaming(
await fetchAnswerSteaming(
question,
state.preference.apiKey,
state.preference.selectedDocs!,
(event) => {
const data = JSON.parse(event.data);
console.log(data);
// check if the 'end' event has been received
if (data.type === 'end') {
@@ -74,7 +72,6 @@ export const conversationSlice = createSlice({
action: PayloadAction<{ index: number; query: Partial<Query> }>,
) {
const index = action.payload.index;
console.log('updating query');
if (action.payload.query.response) {
state.queries[index].response =
(state.queries[index].response || '') + action.payload.query.response;