mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
Merge pull request #513 from akshay11298/mock-backend-server
Mock backend server
This commit is contained in:
22
docker-compose-mock.yaml
Normal file
22
docker-compose-mock.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
frontend:
|
||||
build: ./frontend
|
||||
environment:
|
||||
- VITE_API_HOST=http://localhost:7091
|
||||
- VITE_API_STREAMING=$VITE_API_STREAMING
|
||||
ports:
|
||||
- "5173:5173"
|
||||
depends_on:
|
||||
- mock-backend
|
||||
|
||||
mock-backend:
|
||||
build: ./mock-backend
|
||||
ports:
|
||||
- "7091:7091"
|
||||
|
||||
redis:
|
||||
image: redis:6-alpine
|
||||
ports:
|
||||
- 6379:6379
|
||||
11
mock-backend/Dockerfile
Normal file
11
mock-backend/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM node:20.6.1-bullseye-slim
|
||||
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
|
||||
EXPOSE 7091
|
||||
|
||||
CMD [ "npm", "run", "start"]
|
||||
1300
mock-backend/package-lock.json
generated
Normal file
1300
mock-backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
mock-backend/package.json
Normal file
21
mock-backend/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "mock-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node src/server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"json-server": "^0.17.4",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/json-server": "^0.14.5"
|
||||
}
|
||||
}
|
||||
232
mock-backend/src/mocks/db.json
Normal file
232
mock-backend/src/mocks/db.json
Normal file
@@ -0,0 +1,232 @@
|
||||
{
|
||||
"combine": [
|
||||
{
|
||||
"date": "default",
|
||||
"description": "default",
|
||||
"docLink": "default",
|
||||
"fullName": "default",
|
||||
"language": "default",
|
||||
"location": "local",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "default",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"date": "13/02/2023",
|
||||
"description": "Serverless Framework, the serverless application framework for building web, mobile and IoT applications on AWS Lambda, Azure Functions, Google CloudFunctions & more!",
|
||||
"docLink": "https://serverless.com/framework/docs/",
|
||||
"fullName": "Serverless Framework",
|
||||
"language": "serverless",
|
||||
"location": "remote",
|
||||
"name": "serverless framework",
|
||||
"version": "3.27.0"
|
||||
},
|
||||
{
|
||||
"date": "15/02/2023",
|
||||
"description": "Machine Learning in Python",
|
||||
"docLink": "https://scikit-learn.org/stable/",
|
||||
"fullName": "scikit-learn",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "scikit-learn",
|
||||
"version": "1.2.1"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Machine Learning in Python",
|
||||
"docLink": "https://scikit-learn.org/stable/",
|
||||
"fullName": "scikit-learn",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"name": "scikit-learn",
|
||||
"version": "1.2.1"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Pandas is alibrary providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.",
|
||||
"docLink": "https://pandas.pydata.org/docs/",
|
||||
"fullName": "Pandas",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "pandas",
|
||||
"version": "1.5.3"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Pandas is alibrary providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.",
|
||||
"docLink": "https://pandas.pydata.org/docs/",
|
||||
"fullName": "Pandas",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"name": "pandas",
|
||||
"version": "1.5.3"
|
||||
},
|
||||
{
|
||||
"date": "29/02/2023",
|
||||
"description": "Python is a programming language that lets you work quickly and integrate systems more effectively.",
|
||||
"docLink": "https://docs.python.org/3/",
|
||||
"fullName": "Python",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "huggingface_sentence-transformers-all-mpnet-base-v2",
|
||||
"name": "python",
|
||||
"version": "3.11.1"
|
||||
},
|
||||
{
|
||||
"date": "15/02/2023",
|
||||
"description": "Python is a programming language that lets you work quickly and integrate systems more effectively.",
|
||||
"docLink": "https://docs.python.org/3/",
|
||||
"fullName": "Python",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "python",
|
||||
"version": "3.11.1"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Python is a programming language that lets you work quickly and integrate systems more effectively.",
|
||||
"docLink": "https://docs.python.org/3/",
|
||||
"fullName": "Python",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"name": "python",
|
||||
"version": "3.11.1"
|
||||
},
|
||||
{
|
||||
"date": "08/02/2023",
|
||||
"description": "GPT Index is a project consisting of a set of data structures designed to make it easier to use large external knowledge bases with LLMs.",
|
||||
"docLink": "https://gpt-index.readthedocs.io/en/latest/index.html",
|
||||
"fullName": "LangChain",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"name": "gpt-index",
|
||||
"version": "0.4.0"
|
||||
},
|
||||
{
|
||||
"date": "15/02/2023",
|
||||
"description": "Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not.",
|
||||
"docLink": "https://langchain.readthedocs.io/en/latest/index.html",
|
||||
"fullName": "LangChain",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "langchain",
|
||||
"version": "0.0.87"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not.",
|
||||
"docLink": "https://langchain.readthedocs.io/en/latest/index.html",
|
||||
"fullName": "LangChain",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"name": "langchain",
|
||||
"version": "0.0.79"
|
||||
},
|
||||
{
|
||||
"date": "13/03/2023",
|
||||
"description": "Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not.",
|
||||
"docLink": "https://langchain.readthedocs.io/en/latest/index.html",
|
||||
"fullName": "LangChain",
|
||||
"language": "python",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "langchain",
|
||||
"version": "0.0.109"
|
||||
},
|
||||
{
|
||||
"date": "16/03/2023",
|
||||
"description": "A JavaScript library for building user interfaces\nGet Started\n",
|
||||
"docLink": "https://reactjs.org/",
|
||||
"fullName": "React",
|
||||
"language": "javascript",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "react",
|
||||
"version": "v18.2.0"
|
||||
},
|
||||
{
|
||||
"date": "15/02/2023",
|
||||
"description": "is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions.",
|
||||
"docLink": "https://developer.mozilla.org/en-US/docs/Web/JavaScript",
|
||||
"fullName": "JavaScript",
|
||||
"language": "javascript",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "javascript",
|
||||
"version": "ES2015"
|
||||
},
|
||||
{
|
||||
"date": "16/03/2023",
|
||||
"description": "An approachable, performant and versatile framework for building web user interfaces. ",
|
||||
"docLink": "https://vuejs.org/",
|
||||
"fullName": "Vue.js",
|
||||
"language": "javascript",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "vuejs",
|
||||
"version": "v3.3.0"
|
||||
},
|
||||
{
|
||||
"date": "16/03/2023",
|
||||
"description": "Get ready for a development environment that can finally catch up with you.",
|
||||
"docLink": "https://vitejs.dev/",
|
||||
"fullName": "Vite",
|
||||
"language": "javascript",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "vitejs",
|
||||
"version": "v4.2.0"
|
||||
},
|
||||
{
|
||||
"date": "15/02/2023",
|
||||
"description": "Solidity is an object-oriented, high-level language for implementing smart contracts.",
|
||||
"docLink": "https://docs.soliditylang.org/en/v0.8.18/",
|
||||
"fullName": "Solidity",
|
||||
"language": "ethereum",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "solidity",
|
||||
"version": "0.8.18"
|
||||
},
|
||||
{
|
||||
"date": "07/02/2023",
|
||||
"description": "Solidity is an object-oriented, high-level language for implementing smart contracts.",
|
||||
"docLink": "https://docs.soliditylang.org/en/v0.8.18/",
|
||||
"fullName": "Solidity",
|
||||
"language": "ethereum",
|
||||
"location": "remote",
|
||||
"name": "solidity",
|
||||
"version": "0.8.18"
|
||||
},
|
||||
{
|
||||
"date": "28/02/2023",
|
||||
"description": "GPT-powered chat for documentation search & assistance. ",
|
||||
"docLink": "https://github.com/arc53/DocsGPT/wiki",
|
||||
"fullName": "DocsGPT",
|
||||
"language": "docsgpt",
|
||||
"location": "remote",
|
||||
"model": "huggingface_sentence-transformers-all-mpnet-base-v2",
|
||||
"name": "docsgpt",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
{
|
||||
"date": "28/02/2023",
|
||||
"description": "GPT-powered chat for documentation search & assistance. ",
|
||||
"docLink": "https://github.com/arc53/DocsGPT/wiki",
|
||||
"fullName": "DocsGPT",
|
||||
"language": "docsgpt",
|
||||
"location": "remote",
|
||||
"model": "openai_text-embedding-ada-002",
|
||||
"name": "docsgpt",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
],
|
||||
"conversations": [],
|
||||
"docs_check": {
|
||||
"status": "loaded"
|
||||
}
|
||||
}
|
||||
7
mock-backend/src/mocks/routes.json
Normal file
7
mock-backend/src/mocks/routes.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"/api/*": "/$1",
|
||||
"/get_conversations": "/conversations",
|
||||
"/get_single_conversation?id=:id": "/conversations/:id",
|
||||
"/delete_conversation?id=:id": "/conversations/:id",
|
||||
"/conversations?id=:id": "/conversations/:id"
|
||||
}
|
||||
70
mock-backend/src/server.js
Normal file
70
mock-backend/src/server.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import jsonServer from "json-server";
|
||||
import routes from "./mocks/routes.json" assert { type: "json" };
|
||||
import { v4 as uuid } from "uuid";
|
||||
|
||||
const server = jsonServer.create();
|
||||
const router = jsonServer.router("./src/mocks/db.json");
|
||||
const middlewares = jsonServer.defaults();
|
||||
|
||||
const localStorage = [];
|
||||
|
||||
server.use(middlewares);
|
||||
|
||||
server.use(jsonServer.rewriter(routes));
|
||||
|
||||
server.use((req, res, next) => {
|
||||
if (req.method === "POST") {
|
||||
if (req.url.includes("/delete_conversation")) {
|
||||
req.method = "DELETE";
|
||||
} else if (req.url === "/upload") {
|
||||
const taskId = uuid();
|
||||
localStorage.push(taskId);
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
router.render = (req, res) => {
|
||||
if (req.url === "/feedback") {
|
||||
res.status(200).jsonp({ status: "ok" });
|
||||
} else if (req.url === "/upload") {
|
||||
res.status(200).jsonp({
|
||||
status: "ok",
|
||||
task_id: localStorage[localStorage.length - 1],
|
||||
});
|
||||
} else if (req.url.includes("/task_status")) {
|
||||
const taskId = req.query["task_id"];
|
||||
const taskIdExists = localStorage.includes(taskId);
|
||||
if (taskIdExists) {
|
||||
res.status(200).jsonp({
|
||||
result: {
|
||||
directory: "temp",
|
||||
filename: "install.rst",
|
||||
formats: [".rst", ".md", ".pdf"],
|
||||
name_job: "somename",
|
||||
user: "local",
|
||||
},
|
||||
status: "SUCCESS",
|
||||
});
|
||||
} else {
|
||||
res.status(404).jsonp({});
|
||||
}
|
||||
} else if (req.url === "/stream") {
|
||||
res.status(200).jsonp({
|
||||
data: "The answer is 42",
|
||||
sources: [
|
||||
"https://en.wikipedia.org/wiki/42_(number)",
|
||||
"https://en.wikipedia.org/wiki/42_(number)",
|
||||
],
|
||||
conversation_id: "1234",
|
||||
});
|
||||
} else {
|
||||
res.status(res.statusCode).jsonp(res.locals.data);
|
||||
}
|
||||
};
|
||||
|
||||
server.use(router);
|
||||
|
||||
server.listen(7091, () => {
|
||||
console.log("JSON Server is running");
|
||||
});
|
||||
Reference in New Issue
Block a user