diff --git a/frontend/.env.development b/frontend/.env.development new file mode 100644 index 00000000..d728457f --- /dev/null +++ b/frontend/.env.development @@ -0,0 +1,2 @@ +# Please put appropriate value +VITE_API_HOST = https://dev.docsapi.arc53.com \ No newline at end of file diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 00000000..46e738b1 --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1 @@ +VITE_API_HOST = https://docsapi.arc53.com \ No newline at end of file diff --git a/frontend/src/conversation/conversationApi.ts b/frontend/src/conversation/conversationApi.ts index e48d8368..a7a136c8 100644 --- a/frontend/src/conversation/conversationApi.ts +++ b/frontend/src/conversation/conversationApi.ts @@ -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(); + } + }); } diff --git a/frontend/src/conversation/conversationModels.ts b/frontend/src/conversation/conversationModels.ts index c30977d1..17a3bd13 100644 --- a/frontend/src/conversation/conversationModels.ts +++ b/frontend/src/conversation/conversationModels.ts @@ -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; +}