mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 09:03:15 +00:00
adds api call and introduces model for conversations
This commit is contained in:
2
frontend/.env.development
Normal file
2
frontend/.env.development
Normal file
@@ -0,0 +1,2 @@
|
||||
# Please put appropriate value
|
||||
VITE_API_HOST = https://dev.docsapi.arc53.com
|
||||
1
frontend/.env.production
Normal file
1
frontend/.env.production
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_HOST = https://docsapi.arc53.com
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export type MESSAGE_TYPE = 'QUESTION' | 'ANSWER' | 'ERROR';
|
||||
export type Status = 'idle' | 'loading' | 'failed';
|
||||
export type FEEDBACK = 'LIKE' | 'DISLIKE';
|
||||
|
||||
export interface Message {
|
||||
text: string;
|
||||
@@ -16,3 +17,9 @@ export interface Answer {
|
||||
query: string;
|
||||
result: string;
|
||||
}
|
||||
|
||||
export interface Query {
|
||||
prompt: string;
|
||||
response?: string;
|
||||
feedback?: FEEDBACK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user