mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
moved string prep
This commit is contained in:
@@ -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<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) => {
|
||||
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())
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user