diff --git a/frontend/src/conversation/conversationApi.ts b/frontend/src/conversation/conversationApi.ts index df4dbd1..a252203 100644 --- a/frontend/src/conversation/conversationApi.ts +++ b/frontend/src/conversation/conversationApi.ts @@ -1,11 +1,24 @@ import { Answer } from './conversationModels'; +import { Doc } from '../preferences/preferenceApi'; export function fetchAnswerApi( question: string, apiKey: string, - selectedDocs: string, + selectedDocs: Doc, ): Promise { - // a mock answer generator, this is going to be replaced with real http call + let namePath = selectedDocs.name; + if (selectedDocs.language === namePath) { + namePath = '.project'; + } + + const docPath = + selectedDocs.language + + '/' + + namePath + + '/' + + selectedDocs.version + + '/' + + selectedDocs.model; return new Promise((resolve, reject) => { const activeDocs = 'default'; fetch('https://docsgpt.arc53.com/api/answer', { @@ -18,7 +31,7 @@ export function fetchAnswerApi( api_key: apiKey, embeddings_key: apiKey, history: localStorage.getItem('chatHistory'), - active_docs: selectedDocs, + active_docs: docPath, }), }) .then((response) => response.json()) diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index 609e609..f4dcdb5 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -14,23 +14,11 @@ export const fetchAnswer = createAsyncThunk< { state: RootState } >('fetchAnswer', async ({ question }, { getState }) => { const state = getState(); - let namePath = state.preference.selectedDocs?.name; - if (state.preference.selectedDocs?.language === namePath) { - namePath = '.project'; - } - const docPath = - state.preference.selectedDocs?.language + - '/' + - namePath + - '/' + - state.preference.selectedDocs?.version + - '/' + - state.preference.selectedDocs?.model; const answer = await fetchAnswerApi( question, state.preference.apiKey, - docPath, + state.preference.selectedDocs, ); return answer; });