From 865822d1de821e2a64fdbacb76609ccf219fefd5 Mon Sep 17 00:00:00 2001 From: "tuyang.yhj" Date: Thu, 29 Jun 2023 20:41:05 +0800 Subject: [PATCH] WEB API independent --- datacenter/next.config.js | 5 ++++- datacenter/package.json | 4 +++- datacenter/utils/request.ts | 2 +- pilot/mock_datas/chat_history.db | Bin 12288 -> 0 bytes pilot/mock_datas/chat_history.db.wal | 0 pilot/openapi/api_v1/api_v1.py | 11 +++++++---- pilot/server/dbgpt_server.py | 1 - pilot/server/static/test.html | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 pilot/mock_datas/chat_history.db delete mode 100644 pilot/mock_datas/chat_history.db.wal diff --git a/datacenter/next.config.js b/datacenter/next.config.js index ca4a6f7d0..8376cdd5b 100644 --- a/datacenter/next.config.js +++ b/datacenter/next.config.js @@ -2,7 +2,10 @@ const nextConfig = { experimental: { esmExternals: 'loose' - } + }, + images: { + unoptimized: true + }, } module.exports = nextConfig diff --git a/datacenter/package.json b/datacenter/package.json index c17a0586b..038b415ab 100644 --- a/datacenter/package.json +++ b/datacenter/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "export": "next export", + "compile": "next build && next export" }, "dependencies": { "@ant-design/pro-components": "^2.6.2", diff --git a/datacenter/utils/request.ts b/datacenter/utils/request.ts index 65022c9bd..448d3454b 100644 --- a/datacenter/utils/request.ts +++ b/datacenter/utils/request.ts @@ -2,7 +2,7 @@ import { message } from 'antd'; import axios from 'axios'; import { isPlainObject } from 'lodash'; -axios.defaults.baseURL = 'http://30.183.154.8:5000'; +axios.defaults.baseURL = 'http://localhost:5000'; axios.defaults.timeout = 10000; diff --git a/pilot/mock_datas/chat_history.db b/pilot/mock_datas/chat_history.db deleted file mode 100644 index 929805035e1c69ca980b5e0750d0d4b7cc3c7f3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI#p$&jA5Cu?3V1#;hU<7bD5+-0_W+1i903=|FLtgUE{JYfjURCRDU-L1iaT%t* zdaAjjdwW5E009C72oNAZfB*pk1PH_zXj8ev`Kj{MM1TMR0t5&UAV7cs0RjXFL=^D< ZkN9ftOn?9Z0t5&UAV7cs0Rja630#2eCE)-7 diff --git a/pilot/mock_datas/chat_history.db.wal b/pilot/mock_datas/chat_history.db.wal deleted file mode 100644 index e69de29bb..000000000 diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index 17d9b88fe..267deda52 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -2,13 +2,13 @@ import uuid import json import asyncio import time +import os from fastapi import APIRouter, Request, Body, status, HTTPException, Response, BackgroundTasks -from fastapi.responses import JSONResponse -from fastapi.responses import StreamingResponse +from fastapi.responses import JSONResponse, HTMLResponse +from fastapi.responses import StreamingResponse, FileResponse from fastapi.encoders import jsonable_encoder from fastapi.exceptions import RequestValidationError -from fastapi.responses import JSONResponse from sse_starlette.sse import EventSourceResponse from typing import List @@ -34,7 +34,7 @@ knowledge_service = KnowledgeService() model_semaphore = None global_counter = 0 - +static_file_path = os.path.join(os.getcwd(), "server/static") async def validation_exception_handler(request: Request, exc: RequestValidationError): message = "" @@ -82,6 +82,9 @@ def knowledge_list(): params.update({space.name: space.name}) return params +@router.get("/") +async def read_main(): + return FileResponse(f"{static_file_path}/test.html") @router.get("/v1/chat/dialogue/list", response_model=Result[ConversationVo]) diff --git a/pilot/server/dbgpt_server.py b/pilot/server/dbgpt_server.py index 6c22105cd..b69ca3ab3 100644 --- a/pilot/server/dbgpt_server.py +++ b/pilot/server/dbgpt_server.py @@ -55,7 +55,6 @@ app.add_middleware( ) app.mount("/static", StaticFiles(directory=static_file_path), name="static") -app.add_route("/test", "static/test.html") app.include_router(api_v1) app.add_exception_handler(RequestValidationError, validation_exception_handler) diff --git a/pilot/server/static/test.html b/pilot/server/static/test.html index 709180f11..456fb14c5 100644 --- a/pilot/server/static/test.html +++ b/pilot/server/static/test.html @@ -6,7 +6,7 @@ -
+
Hello World! I'm DB-GPT!