diff --git a/.dockerignore b/.dockerignore index 2bcdfd92b..e5b067a78 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ models/ +plugins/ diff --git a/.gitignore b/.gitignore index d040022b1..2b16ce8b9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,9 @@ sdist/ var/ wheels/ -models/* +models/ +plugins/ + pip-wheel-metadata/ share/python-wheels/ *.egg-info/ diff --git a/Dockerfile-webserver b/Dockerfile similarity index 83% rename from Dockerfile-webserver rename to Dockerfile index bd6aa73dd..3b6d7ef92 100644 --- a/Dockerfile-webserver +++ b/Dockerfile @@ -1,23 +1,23 @@ FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 +WORKDIR /app + RUN apt-get update && apt-get install -y \ git \ python3 \ pip - -WORKDIR /app - -COPY . /app - - # upgrade pip RUN pip3 install --upgrade pip +COPY ./requirements.txt /app/requirements.txt + RUN pip install --no-cache-dir -r requirements.txt RUN python3 -m spacy download zh_core_web_sm -EXPOSE 7860 -CMD ["python3", "pilot/server/webserver.py"] +COPY . /app + +EXPOSE 7860 +EXPOSE 8000 \ No newline at end of file diff --git a/Dockerfile-llmserver b/Dockerfile-llmserver deleted file mode 100644 index c36567381..000000000 --- a/Dockerfile-llmserver +++ /dev/null @@ -1,21 +0,0 @@ -FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 - -RUN apt-get update && apt-get install -y \ - git \ - python3 \ - pip - - -WORKDIR /app - -COPY . /app - - -# upgrade pip -RUN pip3 install --upgrade pip - -RUN pip install --no-cache-dir -r requirements.txt - -EXPOSE 8000 - -CMD ["python3", "pilot/server/llmserver.py"] diff --git a/README.md b/README.md index 41084d2c9..ef6d98e54 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-[**简体中文**](README.zh.md) |[**Discord**](https://discord.gg/hmGPnMSb) |[**Documents**](https://db-gpt.readthedocs.io/en/latest/)|[**Wechat**](https://github.com/csunny/DB-GPT/blob/main/README.zh.md#%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC) +[**简体中文**](README.zh.md) |[**Discord**](https://discord.gg/4BNdxm5d) |[**Documents**](https://db-gpt.readthedocs.io/en/latest/)|[**Wechat**](https://github.com/csunny/DB-GPT/blob/main/README.zh.md#%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC) @@ -21,10 +21,11 @@ As large models are released and iterated upon, they are becoming increasingly i DB-GPT is an experimental open-source project that uses localized GPT large models to interact with your data and environment. With this solution, you can be assured that there is no risk of data leakage, and your data is 100% private and secure. ## News +- [2023/06/25]🔥support chatglm2-6b model. [documents](https://db-gpt.readthedocs.io/en/latest/modules/llms.html) - [2023/06/14] support gpt4all model, which can run at M1/M2, or cpu machine. [documents](https://db-gpt.readthedocs.io/en/latest/modules/llms.html) - [2023/06/01]🔥 On the basis of the Vicuna-13B basic model, task chain calls are implemented through plugins. For example, the implementation of creating a database with a single sentence.[demo](./assets/auto_plugin.gif) - [2023/06/01]🔥 QLoRA guanaco(7b, 13b, 33b) support. -- [2023/05/28]🔥 Learning from crawling data from the Internet [demo](./assets/chaturl_en.gif) +- [2023/05/28] Learning from crawling data from the Internet [demo](./assets/chaturl_en.gif) - [2023/05/21] Generate SQL and execute it automatically. [demo](./assets/auto_sql_en.gif) - [2023/05/15] Chat with documents. [demo](./assets/new_knownledge_en.gif) - [2023/05/06] SQL generation and diagnosis. [demo](./assets/demo_en.gif) @@ -149,7 +150,7 @@ This project is standing on the shoulders of giants and is not going to work wit The MIT License (MIT) ## Contact Information -We are working on building a community, if you have any ideas about building the community, feel free to contact us. [Discord](https://discord.gg/hmGPnMSb) +We are working on building a community, if you have any ideas about building the community, feel free to contact us. [Discord](https://discord.gg/4BNdxm5d) [![Star History Chart](https://api.star-history.com/svg?repos=csunny/DB-GPT)](https://star-history.com/#csunny/DB-GPT) diff --git a/README.zh.md b/README.zh.md index 544fca460..612011db2 100644 --- a/README.zh.md +++ b/README.zh.md @@ -23,6 +23,7 @@ DB-GPT 是一个开源的以数据库为基础的GPT实验项目,使用本地 ## 最新发布 +- [2023/06/25]🔥 支持ChatGLM2-6B模型。 [使用文档](https://db-gpt.readthedocs.io/projects/db-gpt-docs-zh-cn/zh_CN/latest/modules/llms.html) - [2023/06/14]🔥 支持gpt4all模型,可以在M1/M2 或者CPU机器上运行。 [使用文档](https://db-gpt.readthedocs.io/projects/db-gpt-docs-zh-cn/zh_CN/latest/modules/llms.html) - [2023/06/01]🔥 在Vicuna-13B基础模型的基础上,通过插件实现任务链调用。例如单句创建数据库的实现. - [2023/06/01]🔥 QLoRA guanaco(原驼)支持, 支持4090运行33B diff --git a/docker-compose.yml b/docker-compose.yml index b224e1ac3..9f17e160f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,11 +16,16 @@ services: webserver: build: context: . - dockerfile: Dockerfile-webserver + dockerfile: Dockerfile + command: python3 pilot/server/webserver.py environment: - MODEL_SERVER=http://llmserver:8000 - LOCAL_DB_HOST=db - WEB_SERVER_PORT=7860 + - ALLOWLISTED_PLUGINS=db_dashboard + depends_on: + - db + - llmserver volumes: - ./models:/app/models - ./plugins:/app/plugins @@ -28,16 +33,19 @@ services: env_file: - .env.template ports: - - 7860:7860 + - 7860:7860/tcp expose: - - 7860 + - 7860/tcp restart: unless-stopped llmserver: build: context: . - dockerfile: Dockerfile-llmserver + dockerfile: Dockerfile + command: python3 pilot/server/llmserver.py environment: - LOCAL_DB_HOST=db + depends_on: + - db volumes: - ./models:/app/models env_file: @@ -50,9 +58,17 @@ services: reservations: devices: - driver: nvidia - device_ids: ['1'] + device_ids: ['0'] capabilities: [gpu] - + tunnel: + image: cloudflare/cloudflared:latest + container_name: cloudflared-tunnel + restart: unless-stopped + environment: + - TUNNEL_URL=http://webserver:7860 + command: tunnel --no-autoupdate + depends_on: + - webserver volumes: diff --git a/pilot/configs/model_config.py b/pilot/configs/model_config.py index 0dc78af06..22354b4bf 100644 --- a/pilot/configs/model_config.py +++ b/pilot/configs/model_config.py @@ -39,6 +39,8 @@ LLM_MODEL_CONFIG = { "codet5p-2b": os.path.join(MODEL_PATH, "codet5p-2b"), "chatglm-6b-int4": os.path.join(MODEL_PATH, "chatglm-6b-int4"), "chatglm-6b": os.path.join(MODEL_PATH, "chatglm-6b"), + "chatglm2-6b": os.path.join(MODEL_PATH, "chatglm2-6b"), + "chatglm2-6b-int4": os.path.join(MODEL_PATH, "chatglm2-6b-int4"), "text2vec-base": os.path.join(MODEL_PATH, "text2vec-base-chinese"), "guanaco-33b-merged": os.path.join(MODEL_PATH, "guanaco-33b-merged"), "falcon-40b": os.path.join(MODEL_PATH, "falcon-40b"), diff --git a/pilot/model/llm_out/chatglm_llm.py b/pilot/model/llm_out/chatglm_llm.py index dc8522fcc..1c341e08f 100644 --- a/pilot/model/llm_out/chatglm_llm.py +++ b/pilot/model/llm_out/chatglm_llm.py @@ -54,7 +54,12 @@ def chatglm_generate_stream( try: query = messages[-2].split("human:")[1] except IndexError: - query = messages[-3].split("human:")[1] + # fix doc qa: https://github.com/csunny/DB-GPT/issues/274 + doc_qa_message = messages[-2] + if "system:" in doc_qa_message: + query = doc_qa_message.split("system:")[1] + else: + query = messages[-3].split("human:")[1] print("Query Message: ", query) # output = "" # i = 0 diff --git a/pilot/openapi/api_v1/api_v1.py b/pilot/openapi/api_v1/api_v1.py index c6bd08ad0..38bcfcf22 100644 --- a/pilot/openapi/api_v1/api_v1.py +++ b/pilot/openapi/api_v1/api_v1.py @@ -17,7 +17,6 @@ from fastapi.responses import JSONResponse, HTMLResponse from fastapi.responses import StreamingResponse, FileResponse from fastapi.encoders import jsonable_encoder from fastapi.exceptions import RequestValidationError -from sse_starlette.sse import EventSourceResponse from typing import List from pilot.openapi.api_v1.api_view_model import ( diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 7202d3019..208bb148f 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -119,7 +119,7 @@ class BaseOutputParser(ABC): else: raise ValueError("Model server error!code=" + respObj_ex["error_code"]) - def __extract_json(slef, s): + def __extract_json(self, s): i = s.index("{") count = 1 # 当前所在嵌套深度,即还没闭合的'{'个数 for j, c in enumerate(s[i + 1 :], start=i + 1): diff --git a/pilot/server/static/_next/static/chunks/702.d4f5815f0f061322.js b/pilot/server/static/_next/static/chunks/702.d4f5815f0f061322.js index 57d0d13c9..a9a9a390c 100644 --- a/pilot/server/static/_next/static/chunks/702.d4f5815f0f061322.js +++ b/pilot/server/static/_next/static/chunks/702.d4f5815f0f061322.js @@ -1 +1 @@ -"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[702],{57931:function(e,t,a){a.d(t,{ZP:function(){return c},Cg:function(){return l}});var n=a(9268),r=a(89081),o=a(89749),i=a(86006);let[l,s]=function(){let e=i.createContext(void 0);return[function(){let t=i.useContext(e);if(void 0===t)throw Error("useCtx must be inside a Provider with a value");return t},e.Provider]}();var c=e=>{let{children:t}=e,{run:a,data:i,refresh:l}=(0,r.Z)(async()=>await (0,o.T)("/v1/chat/dialogue/list"),{manual:!0});return(0,n.jsx)(s,{value:{dialogueList:i,queryDialogueList:a,refreshDialogList:l},children:t})}},49702:function(e,t,a){a.r(t);var n=a(9268),r=a(89081),o=a(89749),i=a(66487),l=a(34605),s=a(57931);t.default=e=>{var t,a,c,u,d,h;let{refreshDialogList:m}=(0,s.Cg)(),{data:v}=(0,r.Z)(async()=>{var t;return await (0,o.T)("/v1/chat/dialogue/messages/history",{con_uid:null===(t=e.params)||void 0===t?void 0:t.agentId})},{ready:!!(null===(t=e.params)||void 0===t?void 0:t.agentId)}),{data:x}=(0,r.Z)(async()=>{var t;return await (0,o.K)("/v1/chat/mode/params/list?chat_mode=".concat(null===(t=e.searchParams)||void 0===t?void 0:t.scene))},{ready:!!(null===(a=e.searchParams)||void 0===a?void 0:a.scene)}),{history:g,handleChatSubmit:p}=(0,i.Z)({queryAgentURL:"http://30.183.153.109:5000/v1/chat/completions",queryBody:{conv_uid:null===(c=e.params)||void 0===c?void 0:c.agentId,chat_mode:(null===(u=e.searchParams)||void 0===u?void 0:u.scene)||"chat_normal"},initHistory:null==v?void 0:v.data});return(0,n.jsx)("div",{className:"mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 py-6 sm:gap-8 xl:max-w-5xl ",children:(0,n.jsx)(l.Z,{initialMessage:(null==v?void 0:v.data)&&(null==v?void 0:null===(d=v.data)||void 0===d?void 0:d.length)<=0?null===(h=e.searchParams)||void 0===h?void 0:h.initMessage:void 0,clearIntialMessage:async()=>{await m()},messages:g||[],onSubmit:p,paramsList:null==x?void 0:x.data})})}},34605:function(e,t,a){var n=a(9268),r=a(67830),o=a(54842),i=a(70900),l=a(62414),s=a(94244),c=a(33155),u=a(7354),d=a(35891),h=a(35086),m=a(53047),v=a(86006),x=a(19700),g=a(92391),p=a(70321),y=a(75403),f=a(99398),w=a(49064);let j=g.z.object({query:g.z.string().min(1)});t.Z=e=>{let{messages:t,onSubmit:a,initialMessage:g,readOnly:Z,paramsList:b,clearIntialMessage:S}=e,P=v.useRef(null),[C,O]=(0,v.useState)(!1),[R,N]=(0,v.useState)(),[k,E]=(0,v.useState)(),_=(0,x.cI)({resolver:(0,r.F)(j),defaultValues:{}}),L=async e=>{let{query:t}=e;try{O(!0),_.reset(),await a(t,{select_param:null==b?void 0:b[k]})}catch(e){}finally{O(!1)}},T=async()=>{try{let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString())),await L({query:g})}catch(e){console.log(e)}finally{null==S||S()}},z={overrides:{code:e=>{let{children:t}=e;return(0,n.jsx)(f.Z,{language:"javascript",style:w.Z,children:t})}}};return v.useEffect(()=>{P.current&&P.current.scrollTo(0,P.current.scrollHeight)},[null==t?void 0:t.length]),v.useEffect(()=>{g&&t.length<=0&&T()},[g]),v.useEffect(()=>{var e,t;b&&(null===(e=Object.keys(b||{}))||void 0===e?void 0:e.length)>0&&E(null===(t=Object.keys(b||{}))||void 0===t?void 0:t[0])},[b]),(0,n.jsxs)(i.Z,{direction:"column",gap:2,sx:{display:"flex",flex:1,flexBasis:"100%",width:"100%",height:"100%",maxHeight:"100%",minHeight:"100%",mx:"auto"},children:[(0,n.jsxs)(i.Z,{ref:P,direction:"column",gap:2,sx:{boxSizing:"border-box",maxWidth:"100%",width:"100%",mx:"auto",flex:1,maxHeight:"100%",overflowY:"auto",p:2,border:"1px solid",borderColor:"var(--joy-palette-divider)"},children:[R&&(0,n.jsx)(l.Z,{size:"sm",variant:"outlined",color:"primary",className:"message-agent",sx:{mr:"auto",ml:"none",whiteSpace:"pre-wrap"},children:null==R?void 0:R.context}),t.filter(e=>["view","human"].includes(e.role)).map((e,t)=>{var a;return(0,n.jsx)(i.Z,{sx:{mr:"view"===e.role?"auto":"none",ml:"human"===e.role?"auto":"none"},children:(0,n.jsx)(l.Z,{size:"sm",variant:"outlined",className:"view"===e.role?"message-agent":"message-human",color:"view"===e.role?"primary":"neutral",sx:e=>({px:2,"ol, ul":{my:0,pl:2},ol:{listStyle:"numeric"},ul:{listStyle:"disc",mb:2},li:{my:1},a:{textDecoration:"underline"}}),children:(0,n.jsx)(y.Z,{options:z,children:null===(a=e.context)||void 0===a?void 0:a.replaceAll("\\n","\n")})})},t)}),C&&(0,n.jsx)(s.Z,{variant:"soft",color:"neutral",size:"sm",sx:{mx:"auto",my:2}})]}),!Z&&(0,n.jsxs)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",flexDirection:"column",gap:"12px"},onSubmit:e=>{e.stopPropagation(),_.handleSubmit(L)(e)},children:[Object.keys(b||{}).length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(c.Z,{value:k,onChange:(e,t)=>{E(t)},className:"max-w-xs",children:Object.keys(b||{}).map(e=>(0,n.jsx)(u.Z,{value:e,children:null==b?void 0:b[e]},e))}),(0,n.jsx)(d.Z,{className:"cursor-pointer",title:k,placement:"top",variant:"outlined",children:(0,n.jsx)(p.Z,{})})]}),(0,n.jsx)(h.ZP,{sx:{width:"100%"},variant:"outlined",endDecorator:(0,n.jsx)(m.ZP,{type:"submit",disabled:C,children:(0,n.jsx)(o.Z,{})}),..._.register("query")})]})]})}},66487:function(e,t,a){a.d(t,{Z:function(){return l}});var n=a(71990),r=a(86006),o=e=>{let t=(0,r.useReducer)((e,t)=>({...e,...t}),{...e});return t},i=a(57931),l=e=>{let{queryAgentURL:t,channel:a,queryBody:l,initHistory:s}=e,[c,u]=o({history:s||[]}),{refreshDialogList:d}=(0,i.Cg)();(0,r.useEffect)(()=>{s&&u({history:s})},[s]);let h=async(e,r)=>{if(!e)return;let o=[...c.history,{role:"human",context:e}],i=o.length;u({history:o});try{let s=new AbortController;await (0,n.L)(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,...l,user_input:e,channel:a}),signal:s.signal,async onopen(e){if(o.length<=1){d();let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString()))}(!e.ok||e.headers.get("content-type")!==n.a)&&e.status>=400&&e.status<500&&429!==e.status&&e.status},onclose(){console.log("onclose")},onerror(e){throw Error(e)},onmessage:e=>{var t;if(console.log(e,"e"),e.data=e.data.replaceAll("\\n","\n"),"[DONE]"===e.data)s.abort();else if(null===(t=e.data)||void 0===t?void 0:t.startsWith("[ERROR]"))s.abort(),u({history:[...o,{role:"view",context:e.data.replace("[ERROR]","")}]});else{let t=[...o];e.data&&((null==t?void 0:t[i])?t[i].context="".concat(e.data):t.push({role:"view",context:e.data}),u({history:t}))}}})}catch(e){console.log("---e",e),u({history:[...o,{role:"view",context:"请求出错"}]})}};return{handleChatSubmit:h,history:c.history}}},89749:function(e,t,a){a.d(t,{K:function(){return c},T:function(){return s}});var n=a(3748),r=a(24214),o=a(84835);r.Z.defaults.baseURL="http://127.0.0.1:5000",r.Z.defaults.timeout=1e4,r.Z.interceptors.response.use(e=>e.data,e=>Promise.reject(e));let i={"content-type":"application/json"},l=e=>{if(!(0,o.isPlainObject)(e))return JSON.stringify(e);let t={...e};for(let e in t){let a=t[e];"string"==typeof a&&(t[e]=a.trim())}return JSON.stringify(t)},s=(e,t)=>{if(t){let a=Object.keys(t).filter(e=>void 0!==t[e]&&""!==t[e]).map(e=>"".concat(e,"=").concat(t[e])).join("&");a&&(e+="?".concat(a))}return r.Z.get(e,{headers:i}).then(e=>e).catch(e=>{n.ZP.error(e),Promise.reject(e)})},c=(e,t)=>{let a=l(t);return r.Z.post(e,{body:a,headers:i}).then(e=>e).catch(e=>{n.ZP.error(e),Promise.reject(e)})}}}]); \ No newline at end of file +"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[702],{57931:function(e,t,a){a.d(t,{ZP:function(){return c},Cg:function(){return l}});var n=a(9268),r=a(89081),o=a(89749),i=a(86006);let[l,s]=function(){let e=i.createContext(void 0);return[function(){let t=i.useContext(e);if(void 0===t)throw Error("useCtx must be inside a Provider with a value");return t},e.Provider]}();var c=e=>{let{children:t}=e,{run:a,data:i,refresh:l}=(0,r.Z)(async()=>await (0,o.T)("/v1/chat/dialogue/list"),{manual:!0});return(0,n.jsx)(s,{value:{dialogueList:i,queryDialogueList:a,refreshDialogList:l},children:t})}},49702:function(e,t,a){a.r(t);var n=a(9268),r=a(89081),o=a(89749),i=a(66487),l=a(34605),s=a(57931);t.default=e=>{var t,a,c,u,d,h;let{refreshDialogList:m}=(0,s.Cg)(),{data:v}=(0,r.Z)(async()=>{var t;return await (0,o.T)("/v1/chat/dialogue/messages/history",{con_uid:null===(t=e.params)||void 0===t?void 0:t.agentId})},{ready:!!(null===(t=e.params)||void 0===t?void 0:t.agentId)}),{data:x}=(0,r.Z)(async()=>{var t;return await (0,o.K)("/v1/chat/mode/params/list?chat_mode=".concat(null===(t=e.searchParams)||void 0===t?void 0:t.scene))},{ready:!!(null===(a=e.searchParams)||void 0===a?void 0:a.scene)}),{history:g,handleChatSubmit:p}=(0,i.Z)({queryAgentURL:"http://localhost:5000/v1/chat/completions",queryBody:{conv_uid:null===(c=e.params)||void 0===c?void 0:c.agentId,chat_mode:(null===(u=e.searchParams)||void 0===u?void 0:u.scene)||"chat_normal"},initHistory:null==v?void 0:v.data});return(0,n.jsx)("div",{className:"mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 py-6 sm:gap-8 xl:max-w-5xl ",children:(0,n.jsx)(l.Z,{initialMessage:(null==v?void 0:v.data)&&(null==v?void 0:null===(d=v.data)||void 0===d?void 0:d.length)<=0?null===(h=e.searchParams)||void 0===h?void 0:h.initMessage:void 0,clearIntialMessage:async()=>{await m()},messages:g||[],onSubmit:p,paramsList:null==x?void 0:x.data})})}},34605:function(e,t,a){var n=a(9268),r=a(67830),o=a(54842),i=a(70900),l=a(62414),s=a(94244),c=a(33155),u=a(7354),d=a(35891),h=a(35086),m=a(53047),v=a(86006),x=a(19700),g=a(92391),p=a(70321),y=a(75403),f=a(99398),w=a(49064);let j=g.z.object({query:g.z.string().min(1)});t.Z=e=>{let{messages:t,onSubmit:a,initialMessage:g,readOnly:Z,paramsList:b,clearIntialMessage:S}=e,P=v.useRef(null),[C,O]=(0,v.useState)(!1),[R,N]=(0,v.useState)(),[k,E]=(0,v.useState)(),_=(0,x.cI)({resolver:(0,r.F)(j),defaultValues:{}}),L=async e=>{let{query:t}=e;try{O(!0),_.reset(),await a(t,{select_param:null==b?void 0:b[k]})}catch(e){}finally{O(!1)}},T=async()=>{try{let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString())),await L({query:g})}catch(e){console.log(e)}finally{null==S||S()}},z={overrides:{code:e=>{let{children:t}=e;return(0,n.jsx)(f.Z,{language:"javascript",style:w.Z,children:t})}}};return v.useEffect(()=>{P.current&&P.current.scrollTo(0,P.current.scrollHeight)},[null==t?void 0:t.length]),v.useEffect(()=>{g&&t.length<=0&&T()},[g]),v.useEffect(()=>{var e,t;b&&(null===(e=Object.keys(b||{}))||void 0===e?void 0:e.length)>0&&E(null===(t=Object.keys(b||{}))||void 0===t?void 0:t[0])},[b]),(0,n.jsxs)(i.Z,{direction:"column",gap:2,sx:{display:"flex",flex:1,flexBasis:"100%",width:"100%",height:"100%",maxHeight:"100%",minHeight:"100%",mx:"auto"},children:[(0,n.jsxs)(i.Z,{ref:P,direction:"column",gap:2,sx:{boxSizing:"border-box",maxWidth:"100%",width:"100%",mx:"auto",flex:1,maxHeight:"100%",overflowY:"auto",p:2,border:"1px solid",borderColor:"var(--joy-palette-divider)"},children:[R&&(0,n.jsx)(l.Z,{size:"sm",variant:"outlined",color:"primary",className:"message-agent",sx:{mr:"auto",ml:"none",whiteSpace:"pre-wrap"},children:null==R?void 0:R.context}),t.filter(e=>["view","human"].includes(e.role)).map((e,t)=>{var a;return(0,n.jsx)(i.Z,{sx:{mr:"view"===e.role?"auto":"none",ml:"human"===e.role?"auto":"none"},children:(0,n.jsx)(l.Z,{size:"sm",variant:"outlined",className:"view"===e.role?"message-agent":"message-human",color:"view"===e.role?"primary":"neutral",sx:e=>({px:2,"ol, ul":{my:0,pl:2},ol:{listStyle:"numeric"},ul:{listStyle:"disc",mb:2},li:{my:1},a:{textDecoration:"underline"}}),children:(0,n.jsx)(y.Z,{options:z,children:null===(a=e.context)||void 0===a?void 0:a.replaceAll("\\n","\n")})})},t)}),C&&(0,n.jsx)(s.Z,{variant:"soft",color:"neutral",size:"sm",sx:{mx:"auto",my:2}})]}),!Z&&(0,n.jsxs)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",flexDirection:"column",gap:"12px"},onSubmit:e=>{e.stopPropagation(),_.handleSubmit(L)(e)},children:[Object.keys(b||{}).length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(c.Z,{value:k,onChange:(e,t)=>{E(t)},className:"max-w-xs",children:Object.keys(b||{}).map(e=>(0,n.jsx)(u.Z,{value:e,children:null==b?void 0:b[e]},e))}),(0,n.jsx)(d.Z,{className:"cursor-pointer",title:k,placement:"top",variant:"outlined",children:(0,n.jsx)(p.Z,{})})]}),(0,n.jsx)(h.ZP,{sx:{width:"100%"},variant:"outlined",endDecorator:(0,n.jsx)(m.ZP,{type:"submit",disabled:C,children:(0,n.jsx)(o.Z,{})}),..._.register("query")})]})]})}},66487:function(e,t,a){a.d(t,{Z:function(){return l}});var n=a(71990),r=a(86006),o=e=>{let t=(0,r.useReducer)((e,t)=>({...e,...t}),{...e});return t},i=a(57931),l=e=>{let{queryAgentURL:t,channel:a,queryBody:l,initHistory:s}=e,[c,u]=o({history:s||[]}),{refreshDialogList:d}=(0,i.Cg)();(0,r.useEffect)(()=>{s&&u({history:s})},[s]);let h=async(e,r)=>{if(!e)return;let o=[...c.history,{role:"human",context:e}],i=o.length;u({history:o});try{let s=new AbortController;await (0,n.L)(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,...l,user_input:e,channel:a}),signal:s.signal,async onopen(e){if(o.length<=1){d();let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString()))}(!e.ok||e.headers.get("content-type")!==n.a)&&e.status>=400&&e.status<500&&429!==e.status&&e.status},onclose(){console.log("onclose")},onerror(e){throw Error(e)},onmessage:e=>{var t;if(console.log(e,"e"),e.data=e.data.replaceAll("\\n","\n"),"[DONE]"===e.data)s.abort();else if(null===(t=e.data)||void 0===t?void 0:t.startsWith("[ERROR]"))s.abort(),u({history:[...o,{role:"view",context:e.data.replace("[ERROR]","")}]});else{let t=[...o];e.data&&((null==t?void 0:t[i])?t[i].context="".concat(e.data):t.push({role:"view",context:e.data}),u({history:t}))}}})}catch(e){console.log("---e",e),u({history:[...o,{role:"view",context:"请求出错"}]})}};return{handleChatSubmit:h,history:c.history}}},89749:function(e,t,a){a.d(t,{K:function(){return c},T:function(){return s}});var n=a(3748),r=a(24214),o=a(84835);r.Z.defaults.baseURL="http://127.0.0.1:5000",r.Z.defaults.timeout=1e4,r.Z.interceptors.response.use(e=>e.data,e=>Promise.reject(e));let i={"content-type":"application/json"},l=e=>{if(!(0,o.isPlainObject)(e))return JSON.stringify(e);let t={...e};for(let e in t){let a=t[e];"string"==typeof a&&(t[e]=a.trim())}return JSON.stringify(t)},s=(e,t)=>{if(t){let a=Object.keys(t).filter(e=>void 0!==t[e]&&""!==t[e]).map(e=>"".concat(e,"=").concat(t[e])).join("&");a&&(e+="?".concat(a))}return r.Z.get(e,{headers:i}).then(e=>e).catch(e=>{n.ZP.error(e),Promise.reject(e)})},c=(e,t)=>{let a=l(t);return r.Z.post(e,{body:a,headers:i}).then(e=>e).catch(e=>{n.ZP.error(e),Promise.reject(e)})}}}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/app/agents/page-4286c92088ccc4e9.js b/pilot/server/static/_next/static/chunks/app/agents/page-4286c92088ccc4e9.js index 74e9a6159..548b38c30 100644 --- a/pilot/server/static/_next/static/chunks/app/agents/page-4286c92088ccc4e9.js +++ b/pilot/server/static/_next/static/chunks/app/agents/page-4286c92088ccc4e9.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[718],{82738:function(e,t,l){Promise.resolve().then(l.bind(l,68947))},68947:function(e,t,l){"use strict";l.r(t);var s=l(9268),r=l(34605),a=l(91440),n=l(50645),o=l(5737),i=l(45642),c=l(62414),u=l(26974),h=l(22046),d=l(78417),m=l(66487);let x=(0,n.Z)(o.Z)(e=>{let{theme:t}=e;return{...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}});t.default=()=>{let{handleChatSubmit:e,history:t}=(0,m.Z)({queryAgentURL:"http://30.183.153.109:5000/v1/chat/completions"}),l=[{year:"1951 年",sales:0},{year:"1952 年",sales:52},{year:"1956 年",sales:61},{year:"1957 年",sales:45},{year:"1958 年",sales:48},{year:"1959 年",sales:38},{year:"1960 年",sales:38},{year:"1962 年",sales:38}];return(0,s.jsx)("div",{className:"p-4 flex flex-row gap-6 min-h-full w-full",children:(0,s.jsx)("div",{className:"flex w-full",children:(0,s.jsxs)(i.Z,{container:!0,spacing:2,sx:{flexGrow:1},children:[(0,s.jsx)(i.Z,{xs:8,children:(0,s.jsxs)(d.Z,{spacing:2,className:"h-full",children:[(0,s.jsx)(x,{children:(0,s.jsx)(i.Z,{container:!0,spacing:2,children:[{label:"Revenue Won",value:"$7,811,851"},{label:"Close %",value:"37.7%"},{label:"AVG Days to Close",value:"121"},{label:"Opportunities Won",value:"526"}].map(e=>(0,s.jsx)(i.Z,{xs:3,children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"justify-around",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:e.label}),(0,s.jsx)(h.ZP,{children:e.value})]})})},e.label))})}),(0,s.jsx)(x,{className:"flex-1",children:(0,s.jsx)(c.Z,{className:"h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Revenue Won by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)(a.Chart,{padding:[10,20,50,40],autoFit:!0,data:[{month:"Jan",city:"Tokyo",temperature:7},{month:"Feb",city:"Tokyo",temperature:13},{month:"Mar",city:"Tokyo",temperature:16.5},{month:"Apr",city:"Tokyo",temperature:14.5},{month:"May",city:"Tokyo",temperature:10},{month:"Jun",city:"Tokyo",temperature:7.5},{month:"Jul",city:"Tokyo",temperature:9.2},{month:"Aug",city:"Tokyo",temperature:14.5},{month:"Sep",city:"Tokyo",temperature:9.3},{month:"Oct",city:"Tokyo",temperature:8.3},{month:"Nov",city:"Tokyo",temperature:8.9},{month:"Dec",city:"Tokyo",temperature:5.6}],children:(0,s.jsx)(a.LineAdvance,{shape:"smooth",point:!0,area:!0,position:"month*temperature",color:"city"})})})]})})}),(0,s.jsx)(x,{className:"flex-1",children:(0,s.jsxs)(i.Z,{container:!0,spacing:2,className:"h-full",children:[(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})}),(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})}),(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})})]})})]})}),(0,s.jsx)(i.Z,{xs:4,children:(0,s.jsx)(r.Z,{messages:t,onSubmit:e})})]})})})}},57931:function(e,t,l){"use strict";l.d(t,{ZP:function(){return c},Cg:function(){return o}});var s=l(9268),r=l(89081),a=l(89749),n=l(86006);let[o,i]=function(){let e=n.createContext(void 0);return[function(){let t=n.useContext(e);if(void 0===t)throw Error("useCtx must be inside a Provider with a value");return t},e.Provider]}();var c=e=>{let{children:t}=e,{run:l,data:n,refresh:o}=(0,r.Z)(async()=>await (0,a.T)("/v1/chat/dialogue/list"),{manual:!0});return(0,s.jsx)(i,{value:{dialogueList:n,queryDialogueList:l,refreshDialogList:o},children:t})}},34605:function(e,t,l){"use strict";var s=l(9268),r=l(67830),a=l(54842),n=l(70900),o=l(62414),i=l(94244),c=l(33155),u=l(7354),h=l(35891),d=l(35086),m=l(53047),x=l(86006),y=l(19700),p=l(92391),f=l(70321),j=l(75403),v=l(99398),g=l(49064);let Z=p.z.object({query:p.z.string().min(1)});t.Z=e=>{let{messages:t,onSubmit:l,initialMessage:p,readOnly:b,paramsList:w,clearIntialMessage:N}=e,k=x.useRef(null),[T,P]=(0,x.useState)(!1),[C,S]=(0,x.useState)(),[O,R]=(0,x.useState)(),E=(0,y.cI)({resolver:(0,r.F)(Z),defaultValues:{}}),A=async e=>{let{query:t}=e;try{P(!0),E.reset(),await l(t,{select_param:null==w?void 0:w[O]})}catch(e){}finally{P(!1)}},W=async()=>{try{let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString())),await A({query:p})}catch(e){console.log(e)}finally{null==N||N()}},M={overrides:{code:e=>{let{children:t}=e;return(0,s.jsx)(v.Z,{language:"javascript",style:g.Z,children:t})}}};return x.useEffect(()=>{k.current&&k.current.scrollTo(0,k.current.scrollHeight)},[null==t?void 0:t.length]),x.useEffect(()=>{p&&t.length<=0&&W()},[p]),x.useEffect(()=>{var e,t;w&&(null===(e=Object.keys(w||{}))||void 0===e?void 0:e.length)>0&&R(null===(t=Object.keys(w||{}))||void 0===t?void 0:t[0])},[w]),(0,s.jsxs)(n.Z,{direction:"column",gap:2,sx:{display:"flex",flex:1,flexBasis:"100%",width:"100%",height:"100%",maxHeight:"100%",minHeight:"100%",mx:"auto"},children:[(0,s.jsxs)(n.Z,{ref:k,direction:"column",gap:2,sx:{boxSizing:"border-box",maxWidth:"100%",width:"100%",mx:"auto",flex:1,maxHeight:"100%",overflowY:"auto",p:2,border:"1px solid",borderColor:"var(--joy-palette-divider)"},children:[C&&(0,s.jsx)(o.Z,{size:"sm",variant:"outlined",color:"primary",className:"message-agent",sx:{mr:"auto",ml:"none",whiteSpace:"pre-wrap"},children:null==C?void 0:C.context}),t.filter(e=>["view","human"].includes(e.role)).map((e,t)=>{var l;return(0,s.jsx)(n.Z,{sx:{mr:"view"===e.role?"auto":"none",ml:"human"===e.role?"auto":"none"},children:(0,s.jsx)(o.Z,{size:"sm",variant:"outlined",className:"view"===e.role?"message-agent":"message-human",color:"view"===e.role?"primary":"neutral",sx:e=>({px:2,"ol, ul":{my:0,pl:2},ol:{listStyle:"numeric"},ul:{listStyle:"disc",mb:2},li:{my:1},a:{textDecoration:"underline"}}),children:(0,s.jsx)(j.Z,{options:M,children:null===(l=e.context)||void 0===l?void 0:l.replaceAll("\\n","\n")})})},t)}),T&&(0,s.jsx)(i.Z,{variant:"soft",color:"neutral",size:"sm",sx:{mx:"auto",my:2}})]}),!b&&(0,s.jsxs)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",flexDirection:"column",gap:"12px"},onSubmit:e=>{e.stopPropagation(),E.handleSubmit(A)(e)},children:[Object.keys(w||{}).length>0&&(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(c.Z,{value:O,onChange:(e,t)=>{R(t)},className:"max-w-xs",children:Object.keys(w||{}).map(e=>(0,s.jsx)(u.Z,{value:e,children:null==w?void 0:w[e]},e))}),(0,s.jsx)(h.Z,{className:"cursor-pointer",title:O,placement:"top",variant:"outlined",children:(0,s.jsx)(f.Z,{})})]}),(0,s.jsx)(d.ZP,{sx:{width:"100%"},variant:"outlined",endDecorator:(0,s.jsx)(m.ZP,{type:"submit",disabled:T,children:(0,s.jsx)(a.Z,{})}),...E.register("query")})]})]})}},66487:function(e,t,l){"use strict";l.d(t,{Z:function(){return o}});var s=l(71990),r=l(86006),a=e=>{let t=(0,r.useReducer)((e,t)=>({...e,...t}),{...e});return t},n=l(57931),o=e=>{let{queryAgentURL:t,channel:l,queryBody:o,initHistory:i}=e,[c,u]=a({history:i||[]}),{refreshDialogList:h}=(0,n.Cg)();(0,r.useEffect)(()=>{i&&u({history:i})},[i]);let d=async(e,r)=>{if(!e)return;let a=[...c.history,{role:"human",context:e}],n=a.length;u({history:a});try{let i=new AbortController;await (0,s.L)(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,...o,user_input:e,channel:l}),signal:i.signal,async onopen(e){if(a.length<=1){h();let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString()))}(!e.ok||e.headers.get("content-type")!==s.a)&&e.status>=400&&e.status<500&&429!==e.status&&e.status},onclose(){console.log("onclose")},onerror(e){throw Error(e)},onmessage:e=>{var t;if(console.log(e,"e"),e.data=e.data.replaceAll("\\n","\n"),"[DONE]"===e.data)i.abort();else if(null===(t=e.data)||void 0===t?void 0:t.startsWith("[ERROR]"))i.abort(),u({history:[...a,{role:"view",context:e.data.replace("[ERROR]","")}]});else{let t=[...a];e.data&&((null==t?void 0:t[n])?t[n].context="".concat(e.data):t.push({role:"view",context:e.data}),u({history:t}))}}})}catch(e){console.log("---e",e),u({history:[...a,{role:"view",context:"请求出错"}]})}};return{handleChatSubmit:d,history:c.history}}},89749:function(e,t,l){"use strict";l.d(t,{K:function(){return c},T:function(){return i}});var s=l(3748),r=l(24214),a=l(84835);r.Z.defaults.baseURL="http://127.0.0.1:5000",r.Z.defaults.timeout=1e4,r.Z.interceptors.response.use(e=>e.data,e=>Promise.reject(e));let n={"content-type":"application/json"},o=e=>{if(!(0,a.isPlainObject)(e))return JSON.stringify(e);let t={...e};for(let e in t){let l=t[e];"string"==typeof l&&(t[e]=l.trim())}return JSON.stringify(t)},i=(e,t)=>{if(t){let l=Object.keys(t).filter(e=>void 0!==t[e]&&""!==t[e]).map(e=>"".concat(e,"=").concat(t[e])).join("&");l&&(e+="?".concat(l))}return r.Z.get(e,{headers:n}).then(e=>e).catch(e=>{s.ZP.error(e),Promise.reject(e)})},c=(e,t)=>{let l=o(t);return r.Z.post(e,{body:l,headers:n}).then(e=>e).catch(e=>{s.ZP.error(e),Promise.reject(e)})}}},function(e){e.O(0,[180,757,448,22,86,93,259,751,234,947,253,769,744],function(){return e(e.s=82738)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[718],{82738:function(e,t,l){Promise.resolve().then(l.bind(l,68947))},68947:function(e,t,l){"use strict";l.r(t);var s=l(9268),r=l(34605),a=l(91440),n=l(50645),o=l(5737),i=l(45642),c=l(62414),u=l(26974),h=l(22046),d=l(78417),m=l(66487);let x=(0,n.Z)(o.Z)(e=>{let{theme:t}=e;return{...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}});t.default=()=>{let{handleChatSubmit:e,history:t}=(0,m.Z)({queryAgentURL:"http://localhost:5000/v1/chat/completions"}),l=[{year:"1951 年",sales:0},{year:"1952 年",sales:52},{year:"1956 年",sales:61},{year:"1957 年",sales:45},{year:"1958 年",sales:48},{year:"1959 年",sales:38},{year:"1960 年",sales:38},{year:"1962 年",sales:38}];return(0,s.jsx)("div",{className:"p-4 flex flex-row gap-6 min-h-full w-full",children:(0,s.jsx)("div",{className:"flex w-full",children:(0,s.jsxs)(i.Z,{container:!0,spacing:2,sx:{flexGrow:1},children:[(0,s.jsx)(i.Z,{xs:8,children:(0,s.jsxs)(d.Z,{spacing:2,className:"h-full",children:[(0,s.jsx)(x,{children:(0,s.jsx)(i.Z,{container:!0,spacing:2,children:[{label:"Revenue Won",value:"$7,811,851"},{label:"Close %",value:"37.7%"},{label:"AVG Days to Close",value:"121"},{label:"Opportunities Won",value:"526"}].map(e=>(0,s.jsx)(i.Z,{xs:3,children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"justify-around",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:e.label}),(0,s.jsx)(h.ZP,{children:e.value})]})})},e.label))})}),(0,s.jsx)(x,{className:"flex-1",children:(0,s.jsx)(c.Z,{className:"h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Revenue Won by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)(a.Chart,{padding:[10,20,50,40],autoFit:!0,data:[{month:"Jan",city:"Tokyo",temperature:7},{month:"Feb",city:"Tokyo",temperature:13},{month:"Mar",city:"Tokyo",temperature:16.5},{month:"Apr",city:"Tokyo",temperature:14.5},{month:"May",city:"Tokyo",temperature:10},{month:"Jun",city:"Tokyo",temperature:7.5},{month:"Jul",city:"Tokyo",temperature:9.2},{month:"Aug",city:"Tokyo",temperature:14.5},{month:"Sep",city:"Tokyo",temperature:9.3},{month:"Oct",city:"Tokyo",temperature:8.3},{month:"Nov",city:"Tokyo",temperature:8.9},{month:"Dec",city:"Tokyo",temperature:5.6}],children:(0,s.jsx)(a.LineAdvance,{shape:"smooth",point:!0,area:!0,position:"month*temperature",color:"city"})})})]})})}),(0,s.jsx)(x,{className:"flex-1",children:(0,s.jsxs)(i.Z,{container:!0,spacing:2,className:"h-full",children:[(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})}),(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})}),(0,s.jsx)(i.Z,{xs:4,className:"h-full",children:(0,s.jsx)(c.Z,{className:"flex-1 h-full",children:(0,s.jsxs)(u.Z,{className:"h-full",children:[(0,s.jsx)(h.ZP,{gutterBottom:!0,component:"div",children:"Close % by Month"}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsxs)(a.Chart,{autoFit:!0,data:l,children:[(0,s.jsx)(a.Interval,{position:"year*sales",style:{lineWidth:3,stroke:(0,a.getTheme)().colors10[0]}}),(0,s.jsx)(a.Tooltip,{shared:!0})]})})]})})})]})})]})}),(0,s.jsx)(i.Z,{xs:4,children:(0,s.jsx)(r.Z,{messages:t,onSubmit:e})})]})})})}},57931:function(e,t,l){"use strict";l.d(t,{ZP:function(){return c},Cg:function(){return o}});var s=l(9268),r=l(89081),a=l(89749),n=l(86006);let[o,i]=function(){let e=n.createContext(void 0);return[function(){let t=n.useContext(e);if(void 0===t)throw Error("useCtx must be inside a Provider with a value");return t},e.Provider]}();var c=e=>{let{children:t}=e,{run:l,data:n,refresh:o}=(0,r.Z)(async()=>await (0,a.T)("/v1/chat/dialogue/list"),{manual:!0});return(0,s.jsx)(i,{value:{dialogueList:n,queryDialogueList:l,refreshDialogList:o},children:t})}},34605:function(e,t,l){"use strict";var s=l(9268),r=l(67830),a=l(54842),n=l(70900),o=l(62414),i=l(94244),c=l(33155),u=l(7354),h=l(35891),d=l(35086),m=l(53047),x=l(86006),y=l(19700),p=l(92391),f=l(70321),j=l(75403),v=l(99398),g=l(49064);let Z=p.z.object({query:p.z.string().min(1)});t.Z=e=>{let{messages:t,onSubmit:l,initialMessage:p,readOnly:b,paramsList:w,clearIntialMessage:N}=e,k=x.useRef(null),[T,P]=(0,x.useState)(!1),[C,S]=(0,x.useState)(),[O,R]=(0,x.useState)(),E=(0,y.cI)({resolver:(0,r.F)(Z),defaultValues:{}}),A=async e=>{let{query:t}=e;try{P(!0),E.reset(),await l(t,{select_param:null==w?void 0:w[O]})}catch(e){}finally{P(!1)}},W=async()=>{try{let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString())),await A({query:p})}catch(e){console.log(e)}finally{null==N||N()}},M={overrides:{code:e=>{let{children:t}=e;return(0,s.jsx)(v.Z,{language:"javascript",style:g.Z,children:t})}}};return x.useEffect(()=>{k.current&&k.current.scrollTo(0,k.current.scrollHeight)},[null==t?void 0:t.length]),x.useEffect(()=>{p&&t.length<=0&&W()},[p]),x.useEffect(()=>{var e,t;w&&(null===(e=Object.keys(w||{}))||void 0===e?void 0:e.length)>0&&R(null===(t=Object.keys(w||{}))||void 0===t?void 0:t[0])},[w]),(0,s.jsxs)(n.Z,{direction:"column",gap:2,sx:{display:"flex",flex:1,flexBasis:"100%",width:"100%",height:"100%",maxHeight:"100%",minHeight:"100%",mx:"auto"},children:[(0,s.jsxs)(n.Z,{ref:k,direction:"column",gap:2,sx:{boxSizing:"border-box",maxWidth:"100%",width:"100%",mx:"auto",flex:1,maxHeight:"100%",overflowY:"auto",p:2,border:"1px solid",borderColor:"var(--joy-palette-divider)"},children:[C&&(0,s.jsx)(o.Z,{size:"sm",variant:"outlined",color:"primary",className:"message-agent",sx:{mr:"auto",ml:"none",whiteSpace:"pre-wrap"},children:null==C?void 0:C.context}),t.filter(e=>["view","human"].includes(e.role)).map((e,t)=>{var l;return(0,s.jsx)(n.Z,{sx:{mr:"view"===e.role?"auto":"none",ml:"human"===e.role?"auto":"none"},children:(0,s.jsx)(o.Z,{size:"sm",variant:"outlined",className:"view"===e.role?"message-agent":"message-human",color:"view"===e.role?"primary":"neutral",sx:e=>({px:2,"ol, ul":{my:0,pl:2},ol:{listStyle:"numeric"},ul:{listStyle:"disc",mb:2},li:{my:1},a:{textDecoration:"underline"}}),children:(0,s.jsx)(j.Z,{options:M,children:null===(l=e.context)||void 0===l?void 0:l.replaceAll("\\n","\n")})})},t)}),T&&(0,s.jsx)(i.Z,{variant:"soft",color:"neutral",size:"sm",sx:{mx:"auto",my:2}})]}),!b&&(0,s.jsxs)("form",{style:{maxWidth:"100%",width:"100%",position:"relative",display:"flex",marginTop:"auto",overflow:"visible",background:"none",justifyContent:"center",marginLeft:"auto",marginRight:"auto",flexDirection:"column",gap:"12px"},onSubmit:e=>{e.stopPropagation(),E.handleSubmit(A)(e)},children:[Object.keys(w||{}).length>0&&(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(c.Z,{value:O,onChange:(e,t)=>{R(t)},className:"max-w-xs",children:Object.keys(w||{}).map(e=>(0,s.jsx)(u.Z,{value:e,children:null==w?void 0:w[e]},e))}),(0,s.jsx)(h.Z,{className:"cursor-pointer",title:O,placement:"top",variant:"outlined",children:(0,s.jsx)(f.Z,{})})]}),(0,s.jsx)(d.ZP,{sx:{width:"100%"},variant:"outlined",endDecorator:(0,s.jsx)(m.ZP,{type:"submit",disabled:T,children:(0,s.jsx)(a.Z,{})}),...E.register("query")})]})]})}},66487:function(e,t,l){"use strict";l.d(t,{Z:function(){return o}});var s=l(71990),r=l(86006),a=e=>{let t=(0,r.useReducer)((e,t)=>({...e,...t}),{...e});return t},n=l(57931),o=e=>{let{queryAgentURL:t,channel:l,queryBody:o,initHistory:i}=e,[c,u]=a({history:i||[]}),{refreshDialogList:h}=(0,n.Cg)();(0,r.useEffect)(()=>{i&&u({history:i})},[i]);let d=async(e,r)=>{if(!e)return;let a=[...c.history,{role:"human",context:e}],n=a.length;u({history:a});try{let i=new AbortController;await (0,s.L)(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...r,...o,user_input:e,channel:l}),signal:i.signal,async onopen(e){if(a.length<=1){h();let e=new URLSearchParams(window.location.search);e.delete("initMessage"),window.history.replaceState(null,null,"?".concat(e.toString()))}(!e.ok||e.headers.get("content-type")!==s.a)&&e.status>=400&&e.status<500&&429!==e.status&&e.status},onclose(){console.log("onclose")},onerror(e){throw Error(e)},onmessage:e=>{var t;if(console.log(e,"e"),e.data=e.data.replaceAll("\\n","\n"),"[DONE]"===e.data)i.abort();else if(null===(t=e.data)||void 0===t?void 0:t.startsWith("[ERROR]"))i.abort(),u({history:[...a,{role:"view",context:e.data.replace("[ERROR]","")}]});else{let t=[...a];e.data&&((null==t?void 0:t[n])?t[n].context="".concat(e.data):t.push({role:"view",context:e.data}),u({history:t}))}}})}catch(e){console.log("---e",e),u({history:[...a,{role:"view",context:"请求出错"}]})}};return{handleChatSubmit:d,history:c.history}}},89749:function(e,t,l){"use strict";l.d(t,{K:function(){return c},T:function(){return i}});var s=l(3748),r=l(24214),a=l(84835);r.Z.defaults.baseURL="http://127.0.0.1:5000",r.Z.defaults.timeout=1e4,r.Z.interceptors.response.use(e=>e.data,e=>Promise.reject(e));let n={"content-type":"application/json"},o=e=>{if(!(0,a.isPlainObject)(e))return JSON.stringify(e);let t={...e};for(let e in t){let l=t[e];"string"==typeof l&&(t[e]=l.trim())}return JSON.stringify(t)},i=(e,t)=>{if(t){let l=Object.keys(t).filter(e=>void 0!==t[e]&&""!==t[e]).map(e=>"".concat(e,"=").concat(t[e])).join("&");l&&(e+="?".concat(l))}return r.Z.get(e,{headers:n}).then(e=>e).catch(e=>{s.ZP.error(e),Promise.reject(e)})},c=(e,t)=>{let l=o(t);return r.Z.post(e,{body:l,headers:n}).then(e=>e).catch(e=>{s.ZP.error(e),Promise.reject(e)})}}},function(e){e.O(0,[180,757,448,22,86,93,259,751,234,947,253,769,744],function(){return e(e.s=82738)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/app/datastores/documents/chunklist/page-65ded782e5468079.js b/pilot/server/static/_next/static/chunks/app/datastores/documents/chunklist/page-65ded782e5468079.js index f0dabeff6..f599b4d09 100644 --- a/pilot/server/static/_next/static/chunks/app/datastores/documents/chunklist/page-65ded782e5468079.js +++ b/pilot/server/static/_next/static/chunks/app/datastores/documents/chunklist/page-65ded782e5468079.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[538],{4596:function(e,t,n){"use strict";n.d(t,{Z:function(){return r}});let r=e=>e?"function"==typeof e?e():e:null},61714:function(e,t,n){"use strict";n.d(t,{ZP:function(){return g}});var r=n(8683),o=n.n(r),a=n(99753),i=n(86006),l=n(79746),c=n(4596),s=n(92886),d=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(e);ot.indexOf(r[o])&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n};let u=(e,t,n)=>{if(t||n)return i.createElement(i.Fragment,null,t&&i.createElement("div",{className:`${e}-title`},(0,c.Z)(t)),i.createElement("div",{className:`${e}-inner-content`},(0,c.Z)(n)))};function p(e){let{hashId:t,prefixCls:n,className:r,style:l,placement:c="top",title:s,content:d,children:p}=e;return i.createElement("div",{className:o()(t,n,`${n}-pure`,`${n}-placement-${c}`,r),style:l},i.createElement("div",{className:`${n}-arrow`}),i.createElement(a.G,Object.assign({},e,{className:t,prefixCls:n}),p||u(n,s,d)))}function g(e){let{prefixCls:t}=e,n=d(e,["prefixCls"]),{getPrefixCls:r}=i.useContext(l.E_),o=r("popover",t),[a,c]=(0,s.Z)(o);return a(i.createElement(p,Object.assign({},n,{prefixCls:o,hashId:c})))}},24746:function(e,t,n){"use strict";var r=n(8683),o=n.n(r),a=n(86006),i=n(4596),l=n(80716),c=n(79746),s=n(15241),d=n(61714),u=n(92886),p=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(e);ot.indexOf(r[o])&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n};let g=e=>{let{title:t,content:n,prefixCls:r}=e;return a.createElement(a.Fragment,null,t&&a.createElement("div",{className:`${r}-title`},(0,i.Z)(t)),a.createElement("div",{className:`${r}-inner-content`},(0,i.Z)(n)))},m=a.forwardRef((e,t)=>{let{prefixCls:n,title:r,content:i,overlayClassName:d,placement:m="top",trigger:f="hover",mouseEnterDelay:h=.1,mouseLeaveDelay:x=.1,overlayStyle:y={}}=e,b=p(e,["prefixCls","title","content","overlayClassName","placement","trigger","mouseEnterDelay","mouseLeaveDelay","overlayStyle"]),{getPrefixCls:v}=a.useContext(c.E_),j=v("popover",n),[O,$]=(0,u.Z)(j),w=v(),S=o()(d,$);return O(a.createElement(s.Z,Object.assign({placement:m,trigger:f,mouseEnterDelay:h,mouseLeaveDelay:x,overlayStyle:y},b,{prefixCls:j,overlayClassName:S,ref:t,overlay:r||i?a.createElement(g,{prefixCls:j,title:r,content:i}):null,transitionName:(0,l.mL)(w,"zoom-big",b.transitionName),"data-popover-inject":!0})))});m._InternalPanelDoNotUseOrYouWillBeFired=d.ZP,t.Z=m},92886:function(e,t,n){"use strict";var r=n(98663),o=n(87270),a=n(20798),i=n(83688),l=n(40650),c=n(70721);let s=e=>{let{componentCls:t,popoverColor:n,minWidth:o,fontWeightStrong:i,popoverPadding:l,boxShadowSecondary:c,colorTextHeading:s,borderRadiusLG:d,zIndexPopup:u,marginXS:p,colorBgElevated:g,popoverBg:m}=e;return[{[t]:Object.assign(Object.assign({},(0,r.Wf)(e)),{position:"absolute",top:0,left:{_skip_check_:!0,value:0},zIndex:u,fontWeight:"normal",whiteSpace:"normal",textAlign:"start",cursor:"auto",userSelect:"text",transformOrigin:"var(--arrow-x, 50%) var(--arrow-y, 50%)","--antd-arrow-background-color":g,"&-rtl":{direction:"rtl"},"&-hidden":{display:"none"},[`${t}-content`]:{position:"relative"},[`${t}-inner`]:{backgroundColor:m,backgroundClip:"padding-box",borderRadius:d,boxShadow:c,padding:l},[`${t}-title`]:{minWidth:o,marginBottom:p,color:s,fontWeight:i},[`${t}-inner-content`]:{color:n}})},(0,a.ZP)(e,{colorBg:"var(--antd-arrow-background-color)"}),{[`${t}-pure`]:{position:"relative",maxWidth:"none",margin:e.sizePopupArrow,display:"inline-block",[`${t}-content`]:{display:"inline-block"}}}]},d=e=>{let{componentCls:t}=e;return{[t]:i.i.map(n=>{let r=e[`${n}6`];return{[`&${t}-${n}`]:{"--antd-arrow-background-color":r,[`${t}-inner`]:{backgroundColor:r},[`${t}-arrow`]:{background:"transparent"}}}})}},u=e=>{let{componentCls:t,lineWidth:n,lineType:r,colorSplit:o,paddingSM:a,controlHeight:i,fontSize:l,lineHeight:c,padding:s}=e,d=i-Math.round(l*c);return{[t]:{[`${t}-inner`]:{padding:0},[`${t}-title`]:{margin:0,padding:`${d/2}px ${s}px ${d/2-n}px`,borderBottom:`${n}px ${r} ${o}`},[`${t}-inner-content`]:{padding:`${a}px ${s}px`}}}};t.Z=(0,l.Z)("Popover",e=>{let{colorBgElevated:t,colorText:n,wireframe:r}=e,a=(0,c.TS)(e,{popoverPadding:12,popoverBg:t,popoverColor:n});return[s(a),d(a),r&&u(a),(0,o._y)(a,"zoom-big")]},e=>({width:177,minWidth:177,zIndexPopup:e.zIndexPopupBase+30}),{deprecatedTokens:[["width","minWidth"]]})},55254:function(e,t,n){Promise.resolve().then(n.bind(n,26257))},74724:function(e,t,n){"use strict";n.d(t,{S:function(){return r}});let r="http://30.183.153.109:5000"},26257:function(e,t,n){"use strict";n.r(t);var r=n(9268),o=n(56008),a=n(86006),i=n(78635),l=n(83192),c=n(70900),s=n(24746),d=n(18434),u=n(74724);t.default=()=>{let{mode:e}=(0,i.tv)(),t=(0,o.useSearchParams)().get("spacename"),n=(0,o.useSearchParams)().get("documentid"),[p,g]=(0,a.useState)(0),[m,f]=(0,a.useState)(0),[h,x]=(0,a.useState)([]);return(0,a.useEffect)(()=>{(async function(){let e=await fetch("".concat(u.S,"/knowledge/").concat(t,"/chunk/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document_id:n,page:1,page_size:20})}),r=await e.json();r.success&&(x(r.data.data),g(r.data.total),f(r.data.page))})()},[]),(0,r.jsx)("div",{className:"p-4",children:h.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(l.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===e?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{children:"Name"}),(0,r.jsx)("th",{children:"Content"}),(0,r.jsx)("th",{children:"Meta Data"})]})}),(0,r.jsx)("tbody",{children:h.map(e=>(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:e.doc_name}),(0,r.jsx)("td",{children:(0,r.jsx)(s.Z,{content:e.content,trigger:"hover",children:e.content.length>10?"".concat(e.content.slice(0,10),"..."):e.content})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.Z,{content:JSON.stringify(e.meta_info||"{}",null,2),trigger:"hover",children:e.meta_info.length>10?"".concat(e.meta_info.slice(0,10),"..."):e.meta_info})})]},e.id))})]}),(0,r.jsx)(c.Z,{direction:"row",justifyContent:"flex-end",sx:{marginTop:"20px"},children:(0,r.jsx)(d.Z,{defaultPageSize:20,showSizeChanger:!1,current:m,total:p,onChange:async e=>{let r=await fetch("".concat(u.S,"/knowledge/").concat(t,"/chunk/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document_id:n,page:e,page_size:20})}),o=await r.json();o.success&&(x(o.data.data),g(o.data.total),f(o.data.page))},hideOnSinglePage:!0})})]}):(0,r.jsx)(r.Fragment,{})})}}},function(e){e.O(0,[448,599,952,777,434,253,769,744],function(){return e(e.s=55254)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[538],{4596:function(e,t,n){"use strict";n.d(t,{Z:function(){return r}});let r=e=>e?"function"==typeof e?e():e:null},61714:function(e,t,n){"use strict";n.d(t,{ZP:function(){return g}});var r=n(8683),o=n.n(r),a=n(99753),i=n(86006),l=n(79746),c=n(4596),s=n(92886),d=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(e);ot.indexOf(r[o])&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n};let u=(e,t,n)=>{if(t||n)return i.createElement(i.Fragment,null,t&&i.createElement("div",{className:`${e}-title`},(0,c.Z)(t)),i.createElement("div",{className:`${e}-inner-content`},(0,c.Z)(n)))};function p(e){let{hashId:t,prefixCls:n,className:r,style:l,placement:c="top",title:s,content:d,children:p}=e;return i.createElement("div",{className:o()(t,n,`${n}-pure`,`${n}-placement-${c}`,r),style:l},i.createElement("div",{className:`${n}-arrow`}),i.createElement(a.G,Object.assign({},e,{className:t,prefixCls:n}),p||u(n,s,d)))}function g(e){let{prefixCls:t}=e,n=d(e,["prefixCls"]),{getPrefixCls:r}=i.useContext(l.E_),o=r("popover",t),[a,c]=(0,s.Z)(o);return a(i.createElement(p,Object.assign({},n,{prefixCls:o,hashId:c})))}},24746:function(e,t,n){"use strict";var r=n(8683),o=n.n(r),a=n(86006),i=n(4596),l=n(80716),c=n(79746),s=n(15241),d=n(61714),u=n(92886),p=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(e);ot.indexOf(r[o])&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n};let g=e=>{let{title:t,content:n,prefixCls:r}=e;return a.createElement(a.Fragment,null,t&&a.createElement("div",{className:`${r}-title`},(0,i.Z)(t)),a.createElement("div",{className:`${r}-inner-content`},(0,i.Z)(n)))},m=a.forwardRef((e,t)=>{let{prefixCls:n,title:r,content:i,overlayClassName:d,placement:m="top",trigger:f="hover",mouseEnterDelay:h=.1,mouseLeaveDelay:x=.1,overlayStyle:y={}}=e,b=p(e,["prefixCls","title","content","overlayClassName","placement","trigger","mouseEnterDelay","mouseLeaveDelay","overlayStyle"]),{getPrefixCls:v}=a.useContext(c.E_),j=v("popover",n),[O,$]=(0,u.Z)(j),w=v(),S=o()(d,$);return O(a.createElement(s.Z,Object.assign({placement:m,trigger:f,mouseEnterDelay:h,mouseLeaveDelay:x,overlayStyle:y},b,{prefixCls:j,overlayClassName:S,ref:t,overlay:r||i?a.createElement(g,{prefixCls:j,title:r,content:i}):null,transitionName:(0,l.mL)(w,"zoom-big",b.transitionName),"data-popover-inject":!0})))});m._InternalPanelDoNotUseOrYouWillBeFired=d.ZP,t.Z=m},92886:function(e,t,n){"use strict";var r=n(98663),o=n(87270),a=n(20798),i=n(83688),l=n(40650),c=n(70721);let s=e=>{let{componentCls:t,popoverColor:n,minWidth:o,fontWeightStrong:i,popoverPadding:l,boxShadowSecondary:c,colorTextHeading:s,borderRadiusLG:d,zIndexPopup:u,marginXS:p,colorBgElevated:g,popoverBg:m}=e;return[{[t]:Object.assign(Object.assign({},(0,r.Wf)(e)),{position:"absolute",top:0,left:{_skip_check_:!0,value:0},zIndex:u,fontWeight:"normal",whiteSpace:"normal",textAlign:"start",cursor:"auto",userSelect:"text",transformOrigin:"var(--arrow-x, 50%) var(--arrow-y, 50%)","--antd-arrow-background-color":g,"&-rtl":{direction:"rtl"},"&-hidden":{display:"none"},[`${t}-content`]:{position:"relative"},[`${t}-inner`]:{backgroundColor:m,backgroundClip:"padding-box",borderRadius:d,boxShadow:c,padding:l},[`${t}-title`]:{minWidth:o,marginBottom:p,color:s,fontWeight:i},[`${t}-inner-content`]:{color:n}})},(0,a.ZP)(e,{colorBg:"var(--antd-arrow-background-color)"}),{[`${t}-pure`]:{position:"relative",maxWidth:"none",margin:e.sizePopupArrow,display:"inline-block",[`${t}-content`]:{display:"inline-block"}}}]},d=e=>{let{componentCls:t}=e;return{[t]:i.i.map(n=>{let r=e[`${n}6`];return{[`&${t}-${n}`]:{"--antd-arrow-background-color":r,[`${t}-inner`]:{backgroundColor:r},[`${t}-arrow`]:{background:"transparent"}}}})}},u=e=>{let{componentCls:t,lineWidth:n,lineType:r,colorSplit:o,paddingSM:a,controlHeight:i,fontSize:l,lineHeight:c,padding:s}=e,d=i-Math.round(l*c);return{[t]:{[`${t}-inner`]:{padding:0},[`${t}-title`]:{margin:0,padding:`${d/2}px ${s}px ${d/2-n}px`,borderBottom:`${n}px ${r} ${o}`},[`${t}-inner-content`]:{padding:`${a}px ${s}px`}}}};t.Z=(0,l.Z)("Popover",e=>{let{colorBgElevated:t,colorText:n,wireframe:r}=e,a=(0,c.TS)(e,{popoverPadding:12,popoverBg:t,popoverColor:n});return[s(a),d(a),r&&u(a),(0,o._y)(a,"zoom-big")]},e=>({width:177,minWidth:177,zIndexPopup:e.zIndexPopupBase+30}),{deprecatedTokens:[["width","minWidth"]]})},55254:function(e,t,n){Promise.resolve().then(n.bind(n,26257))},74724:function(e,t,n){"use strict";n.d(t,{S:function(){return r}});let r="http://localhost:5000"},26257:function(e,t,n){"use strict";n.r(t);var r=n(9268),o=n(56008),a=n(86006),i=n(78635),l=n(83192),c=n(70900),s=n(24746),d=n(18434),u=n(74724);t.default=()=>{let{mode:e}=(0,i.tv)(),t=(0,o.useSearchParams)().get("spacename"),n=(0,o.useSearchParams)().get("documentid"),[p,g]=(0,a.useState)(0),[m,f]=(0,a.useState)(0),[h,x]=(0,a.useState)([]);return(0,a.useEffect)(()=>{(async function(){let e=await fetch("".concat(u.S,"/knowledge/").concat(t,"/chunk/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document_id:n,page:1,page_size:20})}),r=await e.json();r.success&&(x(r.data.data),g(r.data.total),f(r.data.page))})()},[]),(0,r.jsx)("div",{className:"p-4",children:h.length?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(l.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===e?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{children:"Name"}),(0,r.jsx)("th",{children:"Content"}),(0,r.jsx)("th",{children:"Meta Data"})]})}),(0,r.jsx)("tbody",{children:h.map(e=>(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:e.doc_name}),(0,r.jsx)("td",{children:(0,r.jsx)(s.Z,{content:e.content,trigger:"hover",children:e.content.length>10?"".concat(e.content.slice(0,10),"..."):e.content})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.Z,{content:JSON.stringify(e.meta_info||"{}",null,2),trigger:"hover",children:e.meta_info.length>10?"".concat(e.meta_info.slice(0,10),"..."):e.meta_info})})]},e.id))})]}),(0,r.jsx)(c.Z,{direction:"row",justifyContent:"flex-end",sx:{marginTop:"20px"},children:(0,r.jsx)(d.Z,{defaultPageSize:20,showSizeChanger:!1,current:m,total:p,onChange:async e=>{let r=await fetch("".concat(u.S,"/knowledge/").concat(t,"/chunk/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document_id:n,page:e,page_size:20})}),o=await r.json();o.success&&(x(o.data.data),g(o.data.total),f(o.data.page))},hideOnSinglePage:!0})})]}):(0,r.jsx)(r.Fragment,{})})}}},function(e){e.O(0,[448,599,952,777,434,253,769,744],function(){return e(e.s=55254)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/app/datastores/documents/page-0b797043cfee212f.js b/pilot/server/static/_next/static/chunks/app/datastores/documents/page-0b797043cfee212f.js index 28e11dd5d..1b9332911 100644 --- a/pilot/server/static/_next/static/chunks/app/datastores/documents/page-0b797043cfee212f.js +++ b/pilot/server/static/_next/static/chunks/app/datastores/documents/page-0b797043cfee212f.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[470],{22199:function(e,t,a){Promise.resolve().then(a.bind(a,42069))},74724:function(e,t,a){"use strict";a.d(t,{S:function(){return n}});let n="http://30.183.153.109:5000"},42069:function(e,t,a){"use strict";a.r(t);var n=a(9268),s=a(56008),o=a(86006),i=a(50645),c=a(5737),r=a(78635),l=a(99987),d=a(83192),h=a(58927),u=a(70900),p=a(11437),x=a(90545),g=a(35086),f=a(866),m=a(65326),j=a.n(m),y=a(72474),S=a(50157),w=a(3748),b=a(18434),P=a(74724);let{Dragger:Z}=S.default,C=(0,i.Z)(c.Z)(e=>{let{theme:t}=e;return{width:"50%",backgroundColor:"dark"===t.palette.mode?t.palette.background.level1:"#fff",...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}}),T=["Choose a Datasource type","Setup the Datasource"],k=[{type:"text",title:"Text",subTitle:"Fill your raw text"},{type:"webPage",title:"URL",subTitle:"Fetch the content of a URL"},{type:"file",title:"Document",subTitle:"Upload a document, document type can be PDF, CSV, Text, PowerPoint, Word, Markdown"}];t.default=()=>{let e=(0,s.useRouter)(),t=(0,s.useSearchParams)().get("name"),{mode:a}=(0,r.tv)(),[i,m]=(0,o.useState)(!1),[S,O]=(0,o.useState)(0),[_,v]=(0,o.useState)(""),[N,D]=(0,o.useState)([]),[F,z]=(0,o.useState)(""),[R,E]=(0,o.useState)(""),[L,U]=(0,o.useState)(""),[W,J]=(0,o.useState)(""),[M,I]=(0,o.useState)(null),[B,Y]=(0,o.useState)(0),[A,H]=(0,o.useState)(0);return(0,o.useEffect)(()=>{(async function(){let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:1,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))})()},[]),(0,n.jsxs)("div",{className:"p-4",children:[(0,n.jsx)(c.Z,{sx:{display:"flex",flexDirection:"row-reverse"},children:(0,n.jsx)(l.Z,{variant:"outlined",onClick:()=>m(!0),children:"+ Add Datasource"})}),N.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(d.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===a?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:"Name"}),(0,n.jsx)("th",{children:"Type"}),(0,n.jsx)("th",{children:"Size"}),(0,n.jsx)("th",{children:"Last Synch"}),(0,n.jsx)("th",{children:"Status"}),(0,n.jsx)("th",{children:"Operation"})]})}),(0,n.jsx)("tbody",{children:N.map(a=>(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:a.doc_name}),(0,n.jsx)("td",{children:(0,n.jsx)(h.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:a.doc_type})}),(0,n.jsxs)("td",{children:[a.chunk_size," chunks"]}),(0,n.jsx)("td",{children:j()(a.last_sync).format("YYYY-MM-DD HH:MM:SS")}),(0,n.jsx)("td",{children:(0,n.jsx)(h.Z,{sx:{fontWeight:300},variant:"soft",color:function(){switch(a.status){case"TODO":return"neutral";case"RUNNING":return"primary";case"FINISHED":return"success";case"FAILED":return"danger"}}(),children:a.status})}),(0,n.jsx)("td",{children:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l.Z,{variant:"outlined",size:"sm",onClick:async()=>{let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/sync"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_ids:[a.id]})}),n=await e.json();n.success?w.ZP.success("success"):w.ZP.error(n.err_msg||"failed")},children:"Synch"}),(0,n.jsx)(l.Z,{variant:"outlined",size:"sm",onClick:()=>{e.push("/datastores/documents/chunklist?spacename=".concat(t,"&documentid=").concat(a.id))},children:"Detail of Chunks"})]})})]},a.id))})]}),(0,n.jsx)(u.Z,{direction:"row",justifyContent:"flex-end",sx:{marginTop:"20px"},children:(0,n.jsx)(b.Z,{defaultPageSize:20,showSizeChanger:!1,current:A,total:B,onChange:async e=>{let a=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:e,page_size:20})}),n=await a.json();n.success&&(D(n.data.data),Y(n.data.total),H(n.data.page))},hideOnSinglePage:!0})})]}):(0,n.jsx)(n.Fragment,{}),(0,n.jsx)(p.Z,{sx:{display:"flex",justifyContent:"center",alignItems:"center","z-index":1e3},open:i,onClose:()=>m(!1),children:(0,n.jsxs)(c.Z,{variant:"outlined",sx:{width:800,borderRadius:"md",p:3,boxShadow:"lg"},children:[(0,n.jsx)(x.Z,{sx:{width:"100%"},children:(0,n.jsx)(u.Z,{spacing:2,direction:"row",children:T.map((e,t)=>(0,n.jsx)(C,{sx:{fontWeight:S===t?"bold":""},children:e},e))})}),0===S?(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{sx:{margin:"30px auto"},children:k.map(e=>(0,n.jsxs)(c.Z,{sx:{boxSizing:"border-box",height:"80px",padding:"12px",display:"flex",flexDirection:"column",justifyContent:"space-between",border:"1px solid gray",borderRadius:"6px",marginBottom:"20px",cursor:"pointer"},onClick:()=>{v(e.type),O(1)},children:[(0,n.jsx)(c.Z,{sx:{fontSize:"20px",fontWeight:"bold"},children:e.title}),(0,n.jsx)(c.Z,{children:e.subTitle})]},e.type))})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(x.Z,{sx:{margin:"30px auto"},children:["Name:",(0,n.jsx)(g.ZP,{placeholder:"Please input the name",onChange:e=>E(e.target.value),sx:{marginBottom:"20px"}}),"webPage"===_?(0,n.jsxs)(n.Fragment,{children:["Web Page URL:",(0,n.jsx)(g.ZP,{placeholder:"Please input the Web Page URL",onChange:e=>z(e.target.value)})]}):"file"===_?(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(Z,{name:"file",multiple:!1,onChange(e){var t;if(console.log(e),0===e.fileList.length){I(null),E("");return}I(e.file.originFileObj),E(null===(t=e.file.originFileObj)||void 0===t?void 0:t.name)},children:[(0,n.jsx)("p",{className:"ant-upload-drag-icon",children:(0,n.jsx)(y.Z,{})}),(0,n.jsx)("p",{style:{color:"rgb(22, 108, 255)",fontSize:"20px"},children:"Select or Drop file"}),(0,n.jsx)("p",{className:"ant-upload-hint",style:{color:"rgb(22, 108, 255)"},children:"PDF, PowerPoint, Excel, Word, Text, Markdown,"})]})}):(0,n.jsxs)(n.Fragment,{children:["Text Source(Optional):",(0,n.jsx)(g.ZP,{placeholder:"Please input the text source",onChange:e=>U(e.target.value),sx:{marginBottom:"20px"}}),"Text:",(0,n.jsx)(f.Z,{onChange:e=>J(e.target.value),minRows:4,sx:{marginBottom:"20px"}})]})]}),(0,n.jsx)(l.Z,{onClick:async()=>{if(""===R){w.ZP.error("Please input the name");return}if("webPage"===_){if(""===F){w.ZP.error("Please input the Web Page URL");return}let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:R,content:F,doc_type:"URL"})}),a=await e.json();if(a.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(a.err_msg||"failed")}else if("file"===_){if(!M){w.ZP.error("Please select a file");return}let e=new FormData;e.append("doc_name",R),e.append("doc_file",M),e.append("doc_type","DOCUMENT");let a=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/upload"),{method:"POST",body:e}),n=await a.json();if(n.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(n.err_msg||"failed")}else{if(""===W){w.ZP.error("Please input the text");return}let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:R,source:L,content:W,doc_type:"TEXT"})}),a=await e.json();if(a.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(a.err_msg||"failed")}},children:"Finish"})]})]})})]})}}},function(e){e.O(0,[550,448,22,599,86,952,261,777,434,611,253,769,744],function(){return e(e.s=22199)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[470],{22199:function(e,t,a){Promise.resolve().then(a.bind(a,42069))},74724:function(e,t,a){"use strict";a.d(t,{S:function(){return n}});let n="http://localhost:5000"},42069:function(e,t,a){"use strict";a.r(t);var n=a(9268),s=a(56008),o=a(86006),i=a(50645),c=a(5737),r=a(78635),l=a(99987),d=a(83192),h=a(58927),u=a(70900),p=a(11437),x=a(90545),g=a(35086),f=a(866),m=a(65326),j=a.n(m),y=a(72474),S=a(50157),w=a(3748),b=a(18434),P=a(74724);let{Dragger:Z}=S.default,C=(0,i.Z)(c.Z)(e=>{let{theme:t}=e;return{width:"50%",backgroundColor:"dark"===t.palette.mode?t.palette.background.level1:"#fff",...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}}),T=["Choose a Datasource type","Setup the Datasource"],k=[{type:"text",title:"Text",subTitle:"Fill your raw text"},{type:"webPage",title:"URL",subTitle:"Fetch the content of a URL"},{type:"file",title:"Document",subTitle:"Upload a document, document type can be PDF, CSV, Text, PowerPoint, Word, Markdown"}];t.default=()=>{let e=(0,s.useRouter)(),t=(0,s.useSearchParams)().get("name"),{mode:a}=(0,r.tv)(),[i,m]=(0,o.useState)(!1),[S,O]=(0,o.useState)(0),[_,v]=(0,o.useState)(""),[N,D]=(0,o.useState)([]),[F,z]=(0,o.useState)(""),[R,E]=(0,o.useState)(""),[L,U]=(0,o.useState)(""),[W,J]=(0,o.useState)(""),[M,I]=(0,o.useState)(null),[B,Y]=(0,o.useState)(0),[A,H]=(0,o.useState)(0);return(0,o.useEffect)(()=>{(async function(){let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:1,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))})()},[]),(0,n.jsxs)("div",{className:"p-4",children:[(0,n.jsx)(c.Z,{sx:{display:"flex",flexDirection:"row-reverse"},children:(0,n.jsx)(l.Z,{variant:"outlined",onClick:()=>m(!0),children:"+ Add Datasource"})}),N.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(d.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===a?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:"Name"}),(0,n.jsx)("th",{children:"Type"}),(0,n.jsx)("th",{children:"Size"}),(0,n.jsx)("th",{children:"Last Synch"}),(0,n.jsx)("th",{children:"Status"}),(0,n.jsx)("th",{children:"Operation"})]})}),(0,n.jsx)("tbody",{children:N.map(a=>(0,n.jsxs)("tr",{children:[(0,n.jsx)("td",{children:a.doc_name}),(0,n.jsx)("td",{children:(0,n.jsx)(h.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:a.doc_type})}),(0,n.jsxs)("td",{children:[a.chunk_size," chunks"]}),(0,n.jsx)("td",{children:j()(a.last_sync).format("YYYY-MM-DD HH:MM:SS")}),(0,n.jsx)("td",{children:(0,n.jsx)(h.Z,{sx:{fontWeight:300},variant:"soft",color:function(){switch(a.status){case"TODO":return"neutral";case"RUNNING":return"primary";case"FINISHED":return"success";case"FAILED":return"danger"}}(),children:a.status})}),(0,n.jsx)("td",{children:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l.Z,{variant:"outlined",size:"sm",onClick:async()=>{let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/sync"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_ids:[a.id]})}),n=await e.json();n.success?w.ZP.success("success"):w.ZP.error(n.err_msg||"failed")},children:"Synch"}),(0,n.jsx)(l.Z,{variant:"outlined",size:"sm",onClick:()=>{e.push("/datastores/documents/chunklist?spacename=".concat(t,"&documentid=").concat(a.id))},children:"Detail of Chunks"})]})})]},a.id))})]}),(0,n.jsx)(u.Z,{direction:"row",justifyContent:"flex-end",sx:{marginTop:"20px"},children:(0,n.jsx)(b.Z,{defaultPageSize:20,showSizeChanger:!1,current:A,total:B,onChange:async e=>{let a=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:e,page_size:20})}),n=await a.json();n.success&&(D(n.data.data),Y(n.data.total),H(n.data.page))},hideOnSinglePage:!0})})]}):(0,n.jsx)(n.Fragment,{}),(0,n.jsx)(p.Z,{sx:{display:"flex",justifyContent:"center",alignItems:"center","z-index":1e3},open:i,onClose:()=>m(!1),children:(0,n.jsxs)(c.Z,{variant:"outlined",sx:{width:800,borderRadius:"md",p:3,boxShadow:"lg"},children:[(0,n.jsx)(x.Z,{sx:{width:"100%"},children:(0,n.jsx)(u.Z,{spacing:2,direction:"row",children:T.map((e,t)=>(0,n.jsx)(C,{sx:{fontWeight:S===t?"bold":""},children:e},e))})}),0===S?(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{sx:{margin:"30px auto"},children:k.map(e=>(0,n.jsxs)(c.Z,{sx:{boxSizing:"border-box",height:"80px",padding:"12px",display:"flex",flexDirection:"column",justifyContent:"space-between",border:"1px solid gray",borderRadius:"6px",marginBottom:"20px",cursor:"pointer"},onClick:()=>{v(e.type),O(1)},children:[(0,n.jsx)(c.Z,{sx:{fontSize:"20px",fontWeight:"bold"},children:e.title}),(0,n.jsx)(c.Z,{children:e.subTitle})]},e.type))})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(x.Z,{sx:{margin:"30px auto"},children:["Name:",(0,n.jsx)(g.ZP,{placeholder:"Please input the name",onChange:e=>E(e.target.value),sx:{marginBottom:"20px"}}),"webPage"===_?(0,n.jsxs)(n.Fragment,{children:["Web Page URL:",(0,n.jsx)(g.ZP,{placeholder:"Please input the Web Page URL",onChange:e=>z(e.target.value)})]}):"file"===_?(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(Z,{name:"file",multiple:!1,onChange(e){var t;if(console.log(e),0===e.fileList.length){I(null),E("");return}I(e.file.originFileObj),E(null===(t=e.file.originFileObj)||void 0===t?void 0:t.name)},children:[(0,n.jsx)("p",{className:"ant-upload-drag-icon",children:(0,n.jsx)(y.Z,{})}),(0,n.jsx)("p",{style:{color:"rgb(22, 108, 255)",fontSize:"20px"},children:"Select or Drop file"}),(0,n.jsx)("p",{className:"ant-upload-hint",style:{color:"rgb(22, 108, 255)"},children:"PDF, PowerPoint, Excel, Word, Text, Markdown,"})]})}):(0,n.jsxs)(n.Fragment,{children:["Text Source(Optional):",(0,n.jsx)(g.ZP,{placeholder:"Please input the text source",onChange:e=>U(e.target.value),sx:{marginBottom:"20px"}}),"Text:",(0,n.jsx)(f.Z,{onChange:e=>J(e.target.value),minRows:4,sx:{marginBottom:"20px"}})]})]}),(0,n.jsx)(l.Z,{onClick:async()=>{if(""===R){w.ZP.error("Please input the name");return}if("webPage"===_){if(""===F){w.ZP.error("Please input the Web Page URL");return}let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:R,content:F,doc_type:"URL"})}),a=await e.json();if(a.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(a.err_msg||"failed")}else if("file"===_){if(!M){w.ZP.error("Please select a file");return}let e=new FormData;e.append("doc_name",R),e.append("doc_file",M),e.append("doc_type","DOCUMENT");let a=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/upload"),{method:"POST",body:e}),n=await a.json();if(n.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(n.err_msg||"failed")}else{if(""===W){w.ZP.error("Please input the text");return}let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:R,source:L,content:W,doc_type:"TEXT"})}),a=await e.json();if(a.success){w.ZP.success("success"),m(!1);let e=await fetch("".concat(P.S,"/knowledge/").concat(t,"/document/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({page:A,page_size:20})}),a=await e.json();a.success&&(D(a.data.data),Y(a.data.total),H(a.data.page))}else w.ZP.error(a.err_msg||"failed")}},children:"Finish"})]})]})})]})}}},function(e){e.O(0,[550,448,22,599,86,952,261,777,434,611,253,769,744],function(){return e(e.s=22199)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/app/datastores/page-171d660b8104db30.js b/pilot/server/static/_next/static/chunks/app/datastores/page-171d660b8104db30.js index 08147a5ff..d9a8d94b8 100644 --- a/pilot/server/static/_next/static/chunks/app/datastores/page-171d660b8104db30.js +++ b/pilot/server/static/_next/static/chunks/app/datastores/page-171d660b8104db30.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[43],{31982:function(e,t,n){Promise.resolve().then(n.bind(n,44323))},74724:function(e,t,n){"use strict";n.d(t,{S:function(){return s}});let s="http://30.183.153.109:5000"},44323:function(e,t,n){"use strict";n.r(t);var s=n(9268),a=n(56008),o=n(86006),r=n(72474),i=n(50157),l=n(3748),c=n(50645),d=n(5737),h=n(78635),u=n(99987),p=n(83192),x=n(58927),g=n(11437),f=n(90545),m=n(70900),j=n(35086),y=n(866),b=n(74724);let{Dragger:w}=i.default,P=(0,c.Z)(d.Z)(e=>{let{theme:t}=e;return{width:"33%",backgroundColor:"dark"===t.palette.mode?t.palette.background.level1:"#fff",...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}}),S=["Knowledge Space Configuration","Choose a Datasource type","Setup the Datasource"],Z=[{type:"text",title:"Text",subTitle:"Fill your raw text"},{type:"webPage",title:"URL",subTitle:"Fetch the content of a URL"},{type:"file",title:"Document",subTitle:"Upload a document, document type can be PDF, CSV, Text, PowerPoint, Word, Markdown"}];t.default=()=>{let e=(0,a.useRouter)(),{mode:t}=(0,h.tv)(),[n,i]=(0,o.useState)(0),[c,C]=(0,o.useState)(""),[v,T]=(0,o.useState)([]),[k,_]=(0,o.useState)(!1),[N,O]=(0,o.useState)(""),[F,R]=(0,o.useState)(""),[W,D]=(0,o.useState)(""),[U,E]=(0,o.useState)(""),[L,z]=(0,o.useState)(""),[J,B]=(0,o.useState)(null);return(0,o.useEffect)(()=>{(async function(){let e=await fetch("".concat(b.S,"/knowledge/space/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();t.success&&T(t.data)})()},[]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(d.Z,{sx:{display:"flex",justifyContent:"space-between"},className:"p-4",children:[(0,s.jsx)(d.Z,{sx:{fontSize:"30px",fontWeight:"bold"},children:"Knowledge Spaces"}),(0,s.jsx)(u.Z,{onClick:()=>_(!0),variant:"outlined",children:"+ New Knowledge Space"})]}),(0,s.jsx)("div",{className:"page-body p-4",children:v.length?(0,s.jsxs)(p.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===t?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Name"}),(0,s.jsx)("th",{children:"Vector"}),(0,s.jsx)("th",{children:"Owner"})]})}),(0,s.jsx)("tbody",{children:v.map(t=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:(0,s.jsx)("a",{style:{fontWeight:"bold"},href:"javascript:;",onClick:()=>e.push("/datastores/documents?name=".concat(t.name)),children:t.name})}),(0,s.jsx)("td",{children:(0,s.jsx)(x.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:t.vector_type})}),(0,s.jsx)("td",{children:(0,s.jsx)(x.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:t.owner})})]},t.id))})]}):(0,s.jsx)(s.Fragment,{})}),(0,s.jsx)(g.Z,{sx:{display:"flex",justifyContent:"center",alignItems:"center","z-index":1e3},open:k,onClose:()=>_(!1),children:(0,s.jsxs)(d.Z,{variant:"outlined",sx:{width:800,borderRadius:"md",p:3,boxShadow:"lg"},children:[(0,s.jsx)(f.Z,{sx:{width:"100%"},children:(0,s.jsx)(m.Z,{spacing:2,direction:"row",children:S.map((e,t)=>(0,s.jsx)(P,{sx:{fontWeight:n===t?"bold":""},children:e},e))})}),0===n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(f.Z,{sx:{margin:"30px auto"},children:["Knowledge Space Name:",(0,s.jsx)(j.ZP,{placeholder:"Please input the name",onChange:e=>O(e.target.value)})]}),(0,s.jsx)(u.Z,{variant:"outlined",onClick:async()=>{if(""===N){l.ZP.error("please input the name");return}let e=await fetch("".concat(b.S,"/knowledge/space/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,vector_type:"Chroma",owner:"keting",desc:"test1"})}),t=await e.json();if(t.success){l.ZP.success("success"),i(1);let e=await fetch("".concat(b.S,"/knowledge/space/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();t.success&&T(t.data)}else l.ZP.error(t.err_msg||"failed")},children:"Next"})]}):1===n?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(f.Z,{sx:{margin:"30px auto"},children:Z.map(e=>(0,s.jsxs)(d.Z,{sx:{boxSizing:"border-box",height:"80px",padding:"12px",display:"flex",flexDirection:"column",justifyContent:"space-between",border:"1px solid gray",borderRadius:"6px",marginBottom:"20px",cursor:"pointer"},onClick:()=>{C(e.type),i(2)},children:[(0,s.jsx)(d.Z,{sx:{fontSize:"20px",fontWeight:"bold"},children:e.title}),(0,s.jsx)(d.Z,{children:e.subTitle})]},e.type))})}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(f.Z,{sx:{margin:"30px auto"},children:["Name:",(0,s.jsx)(j.ZP,{placeholder:"Please input the name",onChange:e=>D(e.target.value),sx:{marginBottom:"20px"}}),"webPage"===c?(0,s.jsxs)(s.Fragment,{children:["Web Page URL:",(0,s.jsx)(j.ZP,{placeholder:"Please input the Web Page URL",onChange:e=>R(e.target.value)})]}):"file"===c?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)(w,{name:"file",multiple:!1,onChange(e){var t;if(console.log(e),0===e.fileList.length){B(null),D("");return}B(e.file.originFileObj),D(null===(t=e.file.originFileObj)||void 0===t?void 0:t.name)},children:[(0,s.jsx)("p",{className:"ant-upload-drag-icon",children:(0,s.jsx)(r.Z,{})}),(0,s.jsx)("p",{style:{color:"rgb(22, 108, 255)",fontSize:"20px"},children:"Select or Drop file"}),(0,s.jsx)("p",{className:"ant-upload-hint",style:{color:"rgb(22, 108, 255)"},children:"PDF, PowerPoint, Excel, Word, Text, Markdown,"})]})}):(0,s.jsxs)(s.Fragment,{children:["Text Source(Optional):",(0,s.jsx)(j.ZP,{placeholder:"Please input the text source",onChange:e=>E(e.target.value),sx:{marginBottom:"20px"}}),"Text:",(0,s.jsx)(y.Z,{onChange:e=>z(e.target.value),minRows:4,sx:{marginBottom:"20px"}})]})]}),(0,s.jsx)(u.Z,{onClick:async()=>{if(""===W){l.ZP.error("Please input the name");return}if("webPage"===c){if(""===F){l.ZP.error("Please input the Web Page URL");return}let e=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:W,content:F,doc_type:"URL"})}),t=await e.json();t.success?(l.ZP.success("success"),_(!1)):l.ZP.error(t.err_msg||"failed")}else if("file"===c){if(!J){l.ZP.error("Please select a file");return}let e=new FormData;e.append("doc_name",W),e.append("doc_file",J),e.append("doc_type","DOCUMENT");let t=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/upload"),{method:"POST",body:e}),n=await t.json();n.success?(l.ZP.success("success"),_(!1)):l.ZP.error(n.err_msg||"failed")}else{if(""===L){l.ZP.error("Please input the text");return}let e=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:W,source:U,content:L,doc_type:"TEXT"})}),t=await e.json();t.success?(l.ZP.success("success"),_(!1)):l.ZP.error(t.err_msg||"failed")}},children:"Finish"})]})]})})]})}}},function(e){e.O(0,[448,22,599,86,952,261,777,611,253,769,744],function(){return e(e.s=31982)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[43],{31982:function(e,t,n){Promise.resolve().then(n.bind(n,44323))},74724:function(e,t,n){"use strict";n.d(t,{S:function(){return s}});let s="http://localhost:5000"},44323:function(e,t,n){"use strict";n.r(t);var s=n(9268),a=n(56008),o=n(86006),r=n(72474),i=n(50157),l=n(3748),c=n(50645),d=n(5737),h=n(78635),u=n(99987),p=n(83192),x=n(58927),g=n(11437),f=n(90545),m=n(70900),j=n(35086),y=n(866),b=n(74724);let{Dragger:w}=i.default,P=(0,c.Z)(d.Z)(e=>{let{theme:t}=e;return{width:"33%",backgroundColor:"dark"===t.palette.mode?t.palette.background.level1:"#fff",...t.typography.body2,padding:t.spacing(1),textAlign:"center",borderRadius:4,color:t.vars.palette.text.secondary}}),S=["Knowledge Space Configuration","Choose a Datasource type","Setup the Datasource"],Z=[{type:"text",title:"Text",subTitle:"Fill your raw text"},{type:"webPage",title:"URL",subTitle:"Fetch the content of a URL"},{type:"file",title:"Document",subTitle:"Upload a document, document type can be PDF, CSV, Text, PowerPoint, Word, Markdown"}];t.default=()=>{let e=(0,a.useRouter)(),{mode:t}=(0,h.tv)(),[n,i]=(0,o.useState)(0),[c,C]=(0,o.useState)(""),[v,T]=(0,o.useState)([]),[k,_]=(0,o.useState)(!1),[N,O]=(0,o.useState)(""),[F,R]=(0,o.useState)(""),[W,D]=(0,o.useState)(""),[U,E]=(0,o.useState)(""),[L,z]=(0,o.useState)(""),[J,B]=(0,o.useState)(null);return(0,o.useEffect)(()=>{(async function(){let e=await fetch("".concat(b.S,"/knowledge/space/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();t.success&&T(t.data)})()},[]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(d.Z,{sx:{display:"flex",justifyContent:"space-between"},className:"p-4",children:[(0,s.jsx)(d.Z,{sx:{fontSize:"30px",fontWeight:"bold"},children:"Knowledge Spaces"}),(0,s.jsx)(u.Z,{onClick:()=>_(!0),variant:"outlined",children:"+ New Knowledge Space"})]}),(0,s.jsx)("div",{className:"page-body p-4",children:v.length?(0,s.jsxs)(p.Z,{color:"info",variant:"soft",size:"lg",sx:{"& tbody tr: hover":{backgroundColor:"light"===t?"rgb(246, 246, 246)":"rgb(33, 33, 40)"},"& tbody tr: hover a":{textDecoration:"underline"}},children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Name"}),(0,s.jsx)("th",{children:"Vector"}),(0,s.jsx)("th",{children:"Owner"})]})}),(0,s.jsx)("tbody",{children:v.map(t=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:(0,s.jsx)("a",{style:{fontWeight:"bold"},href:"javascript:;",onClick:()=>e.push("/datastores/documents?name=".concat(t.name)),children:t.name})}),(0,s.jsx)("td",{children:(0,s.jsx)(x.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:t.vector_type})}),(0,s.jsx)("td",{children:(0,s.jsx)(x.Z,{variant:"soft",color:"neutral",sx:{fontWeight:300},children:t.owner})})]},t.id))})]}):(0,s.jsx)(s.Fragment,{})}),(0,s.jsx)(g.Z,{sx:{display:"flex",justifyContent:"center",alignItems:"center","z-index":1e3},open:k,onClose:()=>_(!1),children:(0,s.jsxs)(d.Z,{variant:"outlined",sx:{width:800,borderRadius:"md",p:3,boxShadow:"lg"},children:[(0,s.jsx)(f.Z,{sx:{width:"100%"},children:(0,s.jsx)(m.Z,{spacing:2,direction:"row",children:S.map((e,t)=>(0,s.jsx)(P,{sx:{fontWeight:n===t?"bold":""},children:e},e))})}),0===n?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(f.Z,{sx:{margin:"30px auto"},children:["Knowledge Space Name:",(0,s.jsx)(j.ZP,{placeholder:"Please input the name",onChange:e=>O(e.target.value)})]}),(0,s.jsx)(u.Z,{variant:"outlined",onClick:async()=>{if(""===N){l.ZP.error("please input the name");return}let e=await fetch("".concat(b.S,"/knowledge/space/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,vector_type:"Chroma",owner:"keting",desc:"test1"})}),t=await e.json();if(t.success){l.ZP.success("success"),i(1);let e=await fetch("".concat(b.S,"/knowledge/space/list"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),t=await e.json();t.success&&T(t.data)}else l.ZP.error(t.err_msg||"failed")},children:"Next"})]}):1===n?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(f.Z,{sx:{margin:"30px auto"},children:Z.map(e=>(0,s.jsxs)(d.Z,{sx:{boxSizing:"border-box",height:"80px",padding:"12px",display:"flex",flexDirection:"column",justifyContent:"space-between",border:"1px solid gray",borderRadius:"6px",marginBottom:"20px",cursor:"pointer"},onClick:()=>{C(e.type),i(2)},children:[(0,s.jsx)(d.Z,{sx:{fontSize:"20px",fontWeight:"bold"},children:e.title}),(0,s.jsx)(d.Z,{children:e.subTitle})]},e.type))})}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(f.Z,{sx:{margin:"30px auto"},children:["Name:",(0,s.jsx)(j.ZP,{placeholder:"Please input the name",onChange:e=>D(e.target.value),sx:{marginBottom:"20px"}}),"webPage"===c?(0,s.jsxs)(s.Fragment,{children:["Web Page URL:",(0,s.jsx)(j.ZP,{placeholder:"Please input the Web Page URL",onChange:e=>R(e.target.value)})]}):"file"===c?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)(w,{name:"file",multiple:!1,onChange(e){var t;if(console.log(e),0===e.fileList.length){B(null),D("");return}B(e.file.originFileObj),D(null===(t=e.file.originFileObj)||void 0===t?void 0:t.name)},children:[(0,s.jsx)("p",{className:"ant-upload-drag-icon",children:(0,s.jsx)(r.Z,{})}),(0,s.jsx)("p",{style:{color:"rgb(22, 108, 255)",fontSize:"20px"},children:"Select or Drop file"}),(0,s.jsx)("p",{className:"ant-upload-hint",style:{color:"rgb(22, 108, 255)"},children:"PDF, PowerPoint, Excel, Word, Text, Markdown,"})]})}):(0,s.jsxs)(s.Fragment,{children:["Text Source(Optional):",(0,s.jsx)(j.ZP,{placeholder:"Please input the text source",onChange:e=>E(e.target.value),sx:{marginBottom:"20px"}}),"Text:",(0,s.jsx)(y.Z,{onChange:e=>z(e.target.value),minRows:4,sx:{marginBottom:"20px"}})]})]}),(0,s.jsx)(u.Z,{onClick:async()=>{if(""===W){l.ZP.error("Please input the name");return}if("webPage"===c){if(""===F){l.ZP.error("Please input the Web Page URL");return}let e=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:W,content:F,doc_type:"URL"})}),t=await e.json();t.success?(l.ZP.success("success"),_(!1)):l.ZP.error(t.err_msg||"failed")}else if("file"===c){if(!J){l.ZP.error("Please select a file");return}let e=new FormData;e.append("doc_name",W),e.append("doc_file",J),e.append("doc_type","DOCUMENT");let t=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/upload"),{method:"POST",body:e}),n=await t.json();n.success?(l.ZP.success("success"),_(!1)):l.ZP.error(n.err_msg||"failed")}else{if(""===L){l.ZP.error("Please input the text");return}let e=await fetch("".concat(b.S,"/knowledge/").concat(N,"/document/add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({doc_name:W,source:U,content:L,doc_type:"TEXT"})}),t=await e.json();t.success?(l.ZP.success("success"),_(!1)):l.ZP.error(t.err_msg||"failed")}},children:"Finish"})]})]})})]})}}},function(e){e.O(0,[448,22,599,86,952,261,777,611,253,769,744],function(){return e(e.s=31982)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/pilot/source_embedding/knowledge_embedding.py b/pilot/source_embedding/knowledge_embedding.py index cf13b3017..b36880067 100644 --- a/pilot/source_embedding/knowledge_embedding.py +++ b/pilot/source_embedding/knowledge_embedding.py @@ -35,6 +35,7 @@ class KnowledgeEmbedding: self.knowledge_embedding_client.index_to_store(docs) def read(self): + self.knowledge_embedding_client = self.init_knowledge_embedding() return self.knowledge_embedding_client.read_batch() def init_knowledge_embedding(self): diff --git a/pilot/source_embedding/source_embedding.py b/pilot/source_embedding/source_embedding.py index 3d881fcdf..372e35c22 100644 --- a/pilot/source_embedding/source_embedding.py +++ b/pilot/source_embedding/source_embedding.py @@ -33,9 +33,6 @@ class SourceEmbedding(ABC): self.vector_store_config = vector_store_config self.embedding_args = embedding_args self.embeddings = vector_store_config["embeddings"] - self.vector_client = VectorStoreConnector( - CFG.VECTOR_STORE_TYPE, vector_store_config - ) @abstractmethod @register @@ -59,11 +56,17 @@ class SourceEmbedding(ABC): @register def index_to_store(self, docs): """index to vector store""" + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) self.vector_client.load_document(docs) @register def similar_search(self, doc, topk): """vector store similarity_search""" + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) try: ans = self.vector_client.similar_search(doc, topk) except NotEnoughElementsException: @@ -71,6 +74,9 @@ class SourceEmbedding(ABC): return ans def vector_name_exist(self): + self.vector_client = VectorStoreConnector( + CFG.VECTOR_STORE_TYPE, self.vector_store_config + ) return self.vector_client.vector_name_exists() def source_embedding(self): diff --git a/setup.py b/setup.py index b0732aeda..46dea861b 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ def parse_requirements(file_name: str) -> List[str]: setuptools.setup( name="DB-GPT", packages=find_packages(), - version="0.2.2", + version="0.2.3", author="csunny", author_email="cfqcsunny@gmail.com", description="DB-GPT is an experimental open-source project that uses localized GPT large models to interact with your data and environment." diff --git a/tools/knowlege_init.py b/tools/knowledge_init.py similarity index 87% rename from tools/knowlege_init.py rename to tools/knowledge_init.py index bf1cb1b68..752cf18d0 100644 --- a/tools/knowlege_init.py +++ b/tools/knowledge_init.py @@ -30,23 +30,26 @@ class LocalKnowledgeInit: def knowledge_persist(self, file_path): """knowledge persist""" + docs = [] + embedding_engine = None for root, _, files in os.walk(file_path, topdown=False): for file in files: filename = os.path.join(root, file) - # docs = self._load_file(filename) ke = KnowledgeEmbedding( knowledge_source=filename, knowledge_type=KnowledgeType.DOCUMENT.value, model_name=self.model_name, vector_store_config=self.vector_store_config, ) - client = ke.init_knowledge_embedding() - client.source_embedding() + embedding_engine = ke.init_knowledge_embedding() + doc = ke.read() + docs.extend(doc) + embedding_engine.index_to_store(docs) print(f"""begin create {self.vector_store_config["vector_store_name"]} space""") space = KnowledgeSpaceRequest space.name = self.vector_store_config["vector_store_name"] - space.desc = "" - space.owner = "knowledge_init.py" + space.desc = "knowledge_init.py" + space.owner = "DB-GPT" knowledge_space_service.create_knowledge_space(space)