|
|
@ -1,29 +1,49 @@
|
|
|
|
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: Doc,
|
|
|
|
): Promise<Answer> {
|
|
|
|
): Promise<Answer> {
|
|
|
|
// a mock answer generator, this is going to be replaced with real http call
|
|
|
|
let namePath = selectedDocs.name;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
if (selectedDocs.language === namePath) {
|
|
|
|
setTimeout(() => {
|
|
|
|
namePath = '.project';
|
|
|
|
let result = '';
|
|
|
|
}
|
|
|
|
const characters =
|
|
|
|
|
|
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
const docPath =
|
|
|
|
const charactersLength = characters.length;
|
|
|
|
selectedDocs.language +
|
|
|
|
let counter = 0;
|
|
|
|
'/' +
|
|
|
|
while (counter < 5) {
|
|
|
|
namePath +
|
|
|
|
result += characters.charAt(
|
|
|
|
'/' +
|
|
|
|
Math.floor(Math.random() * charactersLength),
|
|
|
|
selectedDocs.version +
|
|
|
|
);
|
|
|
|
'/' +
|
|
|
|
counter += 1;
|
|
|
|
selectedDocs.model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const randNum = getRandomInt(0, 10);
|
|
|
|
})
|
|
|
|
randNum < 5
|
|
|
|
.then((data) => {
|
|
|
|
? reject()
|
|
|
|
const result = data.answer;
|
|
|
|
: resolve({ answer: result, query: question, result });
|
|
|
|
return { answer: result, query: question, result };
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getRandomInt(min: number, max: number) {
|
|
|
|
function getRandomInt(min: number, max: number) {
|
|
|
|