diff --git a/application/app.py b/application/app.py index a509ed63..73f860ea 100644 --- a/application/app.py +++ b/application/app.py @@ -1,5 +1,6 @@ import os import json +import traceback import dotenv import requests @@ -86,7 +87,6 @@ def api_answer(): # use try and except to check for exception try: - # check if the vectorstore is set if "active_docs" in data: vectorstore = "vectors/" + data["active_docs"] @@ -144,6 +144,8 @@ def api_answer(): # } return result except Exception as e: + # print whole traceback + traceback.print_exc() print(str(e)) return bad_request(500,str(e)) @@ -185,4 +187,4 @@ def after_request(response): if __name__ == "__main__": - app.run(debug=True) + app.run(debug=True, port=5001) diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index c9845638..3dc49f31 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -30,7 +30,7 @@ export default function Conversation() { return (
-
+
{messages.map((message, index) => { return ( { // a mock answer generator, this is going to be replaced with real http call return new Promise((resolve, reject) => { - setTimeout(() => { - let result = ''; - const characters = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - const charactersLength = characters.length; - let counter = 0; - while (counter < 5) { - result += characters.charAt( - Math.floor(Math.random() * charactersLength), - ); - counter += 1; - } - const randNum = getRandomInt(0, 10); - randNum < 5 - ? reject() - : resolve({ answer: result, query: question, result }); - }, 3000); + const activeDocs = 'default'; + 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: selectedDocs, + }), + }) + .then((response) => response.json()) + .then((data) => { + const result = data.answer; + resolve({ answer: result, query: question, result }); + }) + .catch((error) => { + reject(); + }); }); } diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index bd6929e8..609e609b 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -14,7 +14,24 @@ export const fetchAnswer = createAsyncThunk< { state: RootState } >('fetchAnswer', async ({ question }, { getState }) => { const state = getState(); - const answer = await fetchAnswerApi(question, state.preference.apiKey); + 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, + ); return answer; });