diff --git a/frontend/src/conversation/conversationApi.ts b/frontend/src/conversation/conversationApi.ts index a252203..dfa5a14 100644 --- a/frontend/src/conversation/conversationApi.ts +++ b/frontend/src/conversation/conversationApi.ts @@ -19,30 +19,31 @@ export function fetchAnswerApi( selectedDocs.version + '/' + selectedDocs.model; - return new Promise((resolve, reject) => { - const activeDocs = 'default'; - fetch('https://docsgpt.arc53.com/api/answer', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - question: question, - api_key: apiKey, - embeddings_key: apiKey, - history: localStorage.getItem('chatHistory'), - active_docs: docPath, - }), + + return fetch('https://docsgpt.arc53.com/api/answer', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + question: question, + api_key: apiKey, + embeddings_key: apiKey, + history: localStorage.getItem('chatHistory'), + active_docs: docPath, + }), + }) + .then((response) => { + if (response.ok) { + return response.json(); + } else { + Promise.reject(response); + } }) - .then((response) => response.json()) - .then((data) => { - const result = data.answer; - resolve({ answer: result, query: question, result }); - }) - .catch((error) => { - reject(); - }); - }); + .then((data) => { + const result = data.answer; + return { answer: result, query: question, result }; + }); } function getRandomInt(min: number, max: number) { diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index f4dcdb5..a822a38 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -18,7 +18,7 @@ export const fetchAnswer = createAsyncThunk< const answer = await fetchAnswerApi( question, state.preference.apiKey, - state.preference.selectedDocs, + state.preference.selectedDocs!, ); return answer; });