mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 16:16:48 +00:00
9 files changed
+80
-37
No files matched your search
+4
-2
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
|
|
||||||
import dotenv
|
import dotenv
|
||||||
import requests
|
import requests
|
||||||
@@ -86,7 +87,6 @@ def api_answer():
|
|||||||
|
|
||||||
# use try and except to check for exception
|
# use try and except to check for exception
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# check if the vectorstore is set
|
# check if the vectorstore is set
|
||||||
if "active_docs" in data:
|
if "active_docs" in data:
|
||||||
vectorstore = "vectors/" + data["active_docs"]
|
vectorstore = "vectors/" + data["active_docs"]
|
||||||
@@ -144,6 +144,8 @@ def api_answer():
|
|||||||
# }
|
# }
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# print whole traceback
|
||||||
|
traceback.print_exc()
|
||||||
print(str(e))
|
print(str(e))
|
||||||
return bad_request(500,str(e))
|
return bad_request(500,str(e))
|
||||||
|
|
||||||
@@ -185,4 +187,4 @@ def after_request(response):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True, port=5001)
|
||||||
Generated
+7
-7
@@ -37,7 +37,7 @@
|
|||||||
"prettier-plugin-tailwindcss": "^0.2.2",
|
"prettier-plugin-tailwindcss": "^0.2.2",
|
||||||
"tailwindcss": "^3.2.4",
|
"tailwindcss": "^3.2.4",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"vite": "^4.1.0"
|
"vite": "^4.1.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ampproject/remapping": {
|
"node_modules/@ampproject/remapping": {
|
||||||
@@ -5678,9 +5678,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-4.1.4.tgz",
|
||||||
"integrity": "sha512-LM9WWea8vsxhr782r9ntg+bhSFS06FJgCvvB0+8hf8UWtvaiDagKYWXndjfX6kGl74keHJUcpzrQliDXZlF5yg==",
|
"integrity": "sha512-3knk/HsbSTKEin43zHu7jTwYWv81f8kgAL99G5NWBcA1LKvtvcVAC4JjBH1arBunO9kQka+1oGbrMKOjk4ZrBg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.16.14",
|
"esbuild": "^0.16.14",
|
||||||
@@ -9724,9 +9724,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"vite": {
|
"vite": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-4.1.4.tgz",
|
||||||
"integrity": "sha512-LM9WWea8vsxhr782r9ntg+bhSFS06FJgCvvB0+8hf8UWtvaiDagKYWXndjfX6kGl74keHJUcpzrQliDXZlF5yg==",
|
"integrity": "sha512-3knk/HsbSTKEin43zHu7jTwYWv81f8kgAL99G5NWBcA1LKvtvcVAC4JjBH1arBunO9kQka+1oGbrMKOjk4ZrBg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"esbuild": "^0.16.14",
|
"esbuild": "^0.16.14",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default function App() {
|
|||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className={`transition-all duration-200 ${
|
className={`transition-all duration-200 ${
|
||||||
navState === 'ACTIVE' ? 'ml-0 md:ml-72 lg:ml-60' : ' ml-0 md:ml-16'
|
navState === 'ACTIVE' ? 'ml-0 md:ml-72 lg:ml-60' : 'ml-0 md:ml-16'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Routes>
|
<Routes>
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ export default function Navigation({
|
|||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`${
|
className={`${
|
||||||
navState === 'INACTIVE' && '-ml-96 md:-ml-[14rem] lg:-ml-80'
|
navState === 'INACTIVE' && '-ml-96 md:-ml-[14rem]'
|
||||||
} fixed z-20 flex h-full w-72 flex-col border-r-2 bg-gray-50 transition-all duration-200 lg:w-60`}
|
} duration-20 fixed z-20 flex h-full w-72 flex-col border-r-2 bg-gray-50 transition-all`}
|
||||||
>
|
>
|
||||||
<div className={'h-16 w-full border-b-2'}>
|
<div className={'h-16 w-full border-b-2'}>
|
||||||
<button
|
<button
|
||||||
@@ -80,7 +80,7 @@ export default function Navigation({
|
|||||||
<div className="flex flex-grow flex-col-reverse border-b-2">
|
<div className="flex flex-grow flex-col-reverse border-b-2">
|
||||||
<div className="relative my-4 px-6">
|
<div className="relative my-4 px-6">
|
||||||
<div
|
<div
|
||||||
className="flex h-12 w-full cursor-pointer justify-between rounded-md border-2"
|
className="flex h-12 w-full cursor-pointer justify-between rounded-md border-2 bg-white"
|
||||||
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
||||||
>
|
>
|
||||||
{selectedDocs && (
|
{selectedDocs && (
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default function Conversation() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center p-6">
|
<div className="flex justify-center p-6">
|
||||||
<div className="flex mt-20 w-10/12 flex-col transition-all md:w-1/2">
|
<div className="mt-20 flex w-10/12 flex-col transition-all md:w-1/2">
|
||||||
{messages.map((message, index) => {
|
{messages.map((message, index) => {
|
||||||
return (
|
return (
|
||||||
<ConversationBubble
|
<ConversationBubble
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ export const fetchAnswer = createAsyncThunk<
|
|||||||
{ state: RootState }
|
{ state: RootState }
|
||||||
>('fetchAnswer', async ({ question }, { getState }) => {
|
>('fetchAnswer', async ({ question }, { getState }) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const answer = await fetchAnswerApi(question, state.preference.apiKey);
|
|
||||||
|
const answer = await fetchAnswerApi(
|
||||||
|
question,
|
||||||
|
state.preference.apiKey,
|
||||||
|
state.preference.selectedDocs!,
|
||||||
|
);
|
||||||
return answer;
|
return answer;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -46,4 +46,20 @@ export function setLocalApiKey(key: string): void {
|
|||||||
|
|
||||||
export function setLocalRecentDocs(doc: Doc): void {
|
export function setLocalRecentDocs(doc: Doc): void {
|
||||||
localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc));
|
localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc));
|
||||||
|
let namePath = doc.name;
|
||||||
|
if (doc.language === namePath) {
|
||||||
|
namePath = '.project';
|
||||||
|
}
|
||||||
|
|
||||||
|
const docPath =
|
||||||
|
doc.language + '/' + namePath + '/' + doc.version + '/' + doc.model;
|
||||||
|
fetch('https://docsgpt.arc53.com/api/docs_check', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
docs: docPath,
|
||||||
|
}),
|
||||||
|
}).then((response) => response.json());
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
})
|
});
|
||||||
Reference in new issue
Block a user