adds api call and introduces model for conversations

This commit is contained in:
ajaythapliyal
2023-03-05 14:25:21 +05:30
parent 54eea0ff04
commit 780f5893de
4 changed files with 40 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
import { Answer } from './conversationModels';
import { Answer, FEEDBACK } from './conversationModels';
import { Doc } from '../preferences/preferenceApi';
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
export function fetchAnswerApi(
question: string,
apiKey: string,
@@ -23,8 +25,6 @@ export function fetchAnswerApi(
selectedDocs.model +
'/';
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
return fetch(apiHost + '/api/answer', {
method: 'POST',
headers: {
@@ -51,8 +51,31 @@ export function fetchAnswerApi(
});
}
function getRandomInt(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
export function sendFeedback(
{
prompt,
response,
}: {
prompt: string;
response: string;
},
feedback: FEEDBACK,
) {
return fetch(`${apiHost}/api/feedback`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
question: prompt,
answer: response,
feedback: feedback,
}),
}).then((response) => {
if (response.ok) {
return Promise.resolve();
} else {
return Promise.reject();
}
});
}