diff --git a/datacenter/next.config.js b/datacenter/next.config.js index a07800a23..3a5f3a0d8 100644 --- a/datacenter/next.config.js +++ b/datacenter/next.config.js @@ -8,7 +8,7 @@ const nextConfig = { ignoreBuildErrors: true }, env: { - API_BASE_URL: process.env.API_BASE_URL || 'https://u158074-879a-d00019a9.westa.seetacloud.com:8443' + API_BASE_URL: process.env.API_BASE_URL || 'http://127.0.0.1:5000' } } diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index 0d82c0e46..02f71d1e8 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -96,9 +96,9 @@ def knowledge_list(): return params -# @router.get("/") -# async def read_main(): -# return FileResponse(f"{static_file_path}/index.html") +@router.get("/chat") +async def read_main(): + return FileResponse(f"{static_file_path}/chat.html") @router.get("/v1/chat/dialogue/list", response_model=Result[ConversationVo]) diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 208bb148f..22be7ca26 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -95,19 +95,18 @@ class BaseOutputParser(ABC): yield output def parse_model_nostream_resp(self, response, sep: str): - text = response.strip() - text = text.rstrip() - text = text.strip(b"\x00".decode()) - respObj_ex = json.loads(text) - if respObj_ex["error_code"] == 0: - all_text = respObj_ex["text"] + resp_obj_ex = json.loads(response) + if isinstance(resp_obj_ex, str): + resp_obj_ex = json.loads(resp_obj_ex) + if resp_obj_ex["error_code"] == 0: + all_text = resp_obj_ex["text"] ### 解析返回文本,获取AI回复部分 - tmpResp = all_text.split(sep) + tmp_resp = all_text.split(sep) last_index = -1 - for i in range(len(tmpResp)): - if tmpResp[i].find("assistant:") != -1: + for i in range(len(tmp_resp)): + if tmp_resp[i].find("assistant:") != -1: last_index = i - ai_response = tmpResp[last_index] + ai_response = tmp_resp[last_index] ai_response = ai_response.replace("assistant:", "") ai_response = ai_response.replace("Assistant:", "") ai_response = ai_response.replace("ASSISTANT:", "") @@ -117,7 +116,7 @@ class BaseOutputParser(ABC): print("un_stream ai response:", ai_response) return ai_response else: - raise ValueError("Model server error!code=" + respObj_ex["error_code"]) + raise ValueError("Model server error!code=" + resp_obj_ex["error_code"]) def __extract_json(self, s): i = s.index("{") diff --git a/pilot/scene/base_chat.py b/pilot/scene/base_chat.py index f502c78b9..ef7dd4b02 100644 --- a/pilot/scene/base_chat.py +++ b/pilot/scene/base_chat.py @@ -160,12 +160,13 @@ class BaseChat(ABC): try: rsp_str = "" if not CFG.NEW_SERVER_MODE: - rsp_str = requests.post( + rsp_obj = requests.post( urljoin(CFG.MODEL_SERVER, "generate"), headers=headers, json=payload, timeout=120, ) + rsp_str = rsp_obj.text else: ###TODO no stream mode need independent from pilot.server.llmserver import worker diff --git a/pilot/server/dbgpt_server.py b/pilot/server/dbgpt_server.py index f72f04dd7..84b667876 100644 --- a/pilot/server/dbgpt_server.py +++ b/pilot/server/dbgpt_server.py @@ -72,9 +72,9 @@ app.include_router(knowledge_router, prefix="/api") app.include_router(api_v1) app.include_router(knowledge_router) -app.mount("/static", StaticFiles(directory=static_file_path), name="static") app.mount("/_next/static", StaticFiles(directory=static_file_path + "/_next/static")) app.mount("/", StaticFiles(directory=static_file_path, html=True), name="static") +# app.mount("/chat", StaticFiles(directory=static_file_path + "/chat.html", html=True), name="chat") diff --git a/pilot/server/llmserver.py b/pilot/server/llmserver.py index d87540a8e..4d3e838ce 100644 --- a/pilot/server/llmserver.py +++ b/pilot/server/llmserver.py @@ -176,13 +176,13 @@ def generate(prompt_request: PromptRequest): "stop": prompt_request.stop, } - response = [] + rsp_str = "" output = worker.generate_stream_gate(params) for rsp in output: # rsp = rsp.decode("utf-8") - rsp_str = str(rsp, "utf-8") - response.append(rsp_str) + rsp = rsp.replace(b"\0", b"") + rsp_str = rsp.decode() return rsp_str diff --git a/pilot/server/static/404.html b/pilot/server/static/404.html new file mode 100644 index 000000000..92536cb28 --- /dev/null +++ b/pilot/server/static/404.html @@ -0,0 +1 @@ +