moved string prep

pull/130/head
Alex 2 years ago
parent 99ac57c15b
commit 4011398b0c

@ -1,11 +1,24 @@
import { Answer } from './conversationModels'; import { Answer } from './conversationModels';
import { Doc } from '../preferences/preferenceApi';
export function fetchAnswerApi( export function fetchAnswerApi(
question: string, question: string,
apiKey: string, apiKey: string,
selectedDocs: string, selectedDocs: Doc,
): Promise<Answer> { ): Promise<Answer> {
// 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) => { return new Promise((resolve, reject) => {
const activeDocs = 'default'; const activeDocs = 'default';
fetch('https://docsgpt.arc53.com/api/answer', { fetch('https://docsgpt.arc53.com/api/answer', {
@ -18,7 +31,7 @@ export function fetchAnswerApi(
api_key: apiKey, api_key: apiKey,
embeddings_key: apiKey, embeddings_key: apiKey,
history: localStorage.getItem('chatHistory'), history: localStorage.getItem('chatHistory'),
active_docs: selectedDocs, active_docs: docPath,
}), }),
}) })
.then((response) => response.json()) .then((response) => response.json())

@ -14,23 +14,11 @@ export const fetchAnswer = createAsyncThunk<
{ state: RootState } { state: RootState }
>('fetchAnswer', async ({ question }, { getState }) => { >('fetchAnswer', async ({ question }, { getState }) => {
const state = 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( const answer = await fetchAnswerApi(
question, question,
state.preference.apiKey, state.preference.apiKey,
docPath, state.preference.selectedDocs,
); );
return answer; return answer;
}); });

Loading…
Cancel
Save