diff --git a/pilot/base_modules/agent/commands/command_mange.py b/pilot/base_modules/agent/commands/command_mange.py index 7e1f48194..dd95ee2db 100644 --- a/pilot/base_modules/agent/commands/command_mange.py +++ b/pilot/base_modules/agent/commands/command_mange.py @@ -370,7 +370,8 @@ class ApiCall: return html else: api_call_element = ET.Element("chart-view") - api_call_element.set("content", self.__to_antv_vis_param(api_status)) + api_call_element.attrib["content"] = self.__to_antv_vis_param(api_status) + # api_call_element.set("content", self.__to_antv_vis_param(api_status)) # api_call_element.text = self.__to_antv_vis_param(api_status) result = ET.tostring(api_call_element, encoding="utf-8") return result.decode("utf-8") diff --git a/pilot/model/model_adapter.py b/pilot/model/model_adapter.py index 8c4eac537..bed62a34d 100644 --- a/pilot/model/model_adapter.py +++ b/pilot/model/model_adapter.py @@ -158,8 +158,15 @@ class LLMModelAdaper: else: raise ValueError(f"Unknown role: {role}") - can_use_system = "" + can_use_systems:[] = [] if system_messages: + if len(system_messages) > 1: + ## Compatible with dbgpt complex scenarios, the last system will protect more complete information entered by the current user + user_messages[-1] = system_messages[-1] + can_use_systems = system_messages[:-1] + else: + can_use_systems = system_messages + for i in range(len(user_messages)): # TODO vicuna 兼容 测试完放弃 user_messages[-1] = system_messages[-1] if len(system_messages) > 1: @@ -171,8 +178,10 @@ class LLMModelAdaper: conv.append_message(conv.roles[1], ai_messages[i]) if isinstance(conv, Conversation): - conv.set_system_message(can_use_system) + conv.set_system_message("".join(can_use_systems)) else: + conv.update_system_message("".join(can_use_systems)) + conv.update_system_message(can_use_system) # Add a blank message for the assistant. diff --git a/pilot/model/proxy/llms/chatgpt.py b/pilot/model/proxy/llms/chatgpt.py index 9e6d1a20a..97699897c 100644 --- a/pilot/model/proxy/llms/chatgpt.py +++ b/pilot/model/proxy/llms/chatgpt.py @@ -58,6 +58,42 @@ def _initialize_openai(params: ProxyModelParameters): return openai_params +def __convert_2_gpt_messages(messages: List[ModelMessage]): + + chat_round = 0 + gpt_messages = [] + + last_usr_message = "" + system_messages = [] + + for message in messages: + if message.role == ModelMessageRoleType.HUMAN: + last_usr_message = message.content + elif message.role == ModelMessageRoleType.SYSTEM: + system_messages.append(message.content) + elif message.role == ModelMessageRoleType.AI: + last_ai_message = message.content + gpt_messages.append({"role": "user", "content": last_usr_message}) + gpt_messages.append({"role": "assistant", "content": last_ai_message}) + + # build last user messge + + if len(system_messages) >0: + if len(system_messages) > 1: + end_message = system_messages[-1] + else: + last_message = messages[-1] + if last_message.role == ModelMessageRoleType.HUMAN: + end_message = system_messages[-1] + "\n" + last_message.content + else: + end_message = system_messages[-1] + else: + last_message = messages[-1] + end_message = last_message.content + gpt_messages.append({"role": "user", "content": end_message}) + return gpt_messages, system_messages + + def _initialize_openai_v1(params: ProxyModelParameters): try: from openai import OpenAI diff --git a/pilot/scene/chat_agent/auto_gen.py b/pilot/scene/chat_agent/auto_gen.py deleted file mode 100644 index 9f5bda05c..000000000 --- a/pilot/scene/chat_agent/auto_gen.py +++ /dev/null @@ -1,64 +0,0 @@ -import autogen -from autogen import oai, AssistantAgent, UserProxyAgent, config_list_from_json -from openai.openai_object import OpenAIObject - -config_list = [ - { - "model": "gpt-3.5-turbo", - "api_base": "http://43.156.9.162:3001/api/openai/v1", - "api_type": "open_ai", - "api_key": "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", - } -] -llm_config = { - "request_timeout": 600, - "seed": 45, # change the seed for different trials - "config_list": config_list, - "temperature": 0, - "max_tokens": 3000, -} - -# assistant = AssistantAgent("assistant", llm_config=llm_config) -# user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding"}) -# - -assistant = autogen.AssistantAgent( - name="assistant", - llm_config=llm_config, - is_termination_msg=lambda x: True if "TERMINATE" in x.get("content") else False, -) - -# 创建名为 user_proxy 的用户代理实例,这里定义为进行干预 -user_proxy = autogen.UserProxyAgent( - name="user_proxy", - human_input_mode="TERMINATE", - max_consecutive_auto_reply=1, - is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), - code_execution_config={"work_dir": "web"}, - llm_config=llm_config, - system_message="""Reply TERMINATE if the task has been solved at full satisfaction. -Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""", -) - -task1 = """今天是星期几?,还有几天周末?请告诉我答案。""" - -if __name__ == "__main__": - user_proxy.initiate_chat(assistant, message=task1) - # user_proxy.initiate_chat(assistant, message="Plot a chart of NVDA and TESLA stock price change YTD.") - - # response: OpenAIObject = oai.Completion.create( - # config_list=[ - # { - # "model": "gpt-3.5-turbo", - # "api_base": "http://43.156.9.162:3001/api/openai/v1", - # "api_type": "open_ai", - # "api_key": "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", - # } - # ], - # prompt="你好呀!", - # ) - # - # print(response) - # - # text = response.get("choices")[0].get("text") - # print(text) diff --git a/pilot/scene/chat_agent/auto_gen2.py b/pilot/scene/chat_agent/auto_gen2.py deleted file mode 100644 index 0ff65f939..000000000 --- a/pilot/scene/chat_agent/auto_gen2.py +++ /dev/null @@ -1,94 +0,0 @@ -import autogen - -config_list = [ - { - "model": "gpt-3.5-turbo", - "api_base": "http://43.156.9.162:3001/api/openai/v1", - "api_type": "open_ai", - "api_key": "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", - } -] -llm_config = { - "functions": [ - { - "name": "python", - "description": "run cell in ipython and return the execution result.", - "parameters": { - "type": "object", - "properties": { - "cell": { - "type": "string", - "description": "Valid Python cell to execute.", - } - }, - "required": ["cell"], - }, - }, - { - "name": "sh", - "description": "run a shell script and return the execution result.", - "parameters": { - "type": "object", - "properties": { - "script": { - "type": "string", - "description": "Valid shell script to execute.", - } - }, - "required": ["script"], - }, - }, - ], - "config_list": config_list, - "request_timeout": 120, - "max_tokens": 3000, -} -chatbot = autogen.AssistantAgent( - name="chatbot", - system_message="For coding tasks, only use the functions you have been provided with. Reply TERMINATE when the task is done.", - llm_config=llm_config, -) - -# create a UserProxyAgent instance named "user_proxy" -user_proxy = autogen.UserProxyAgent( - name="user_proxy", - is_termination_msg=lambda x: x.get("content", "") - and x.get("content", "").rstrip().endswith("TERMINATE"), - human_input_mode="NEVER", - max_consecutive_auto_reply=10, - code_execution_config={"work_dir": "coding"}, -) - -# define functions according to the function description -from IPython import get_ipython - - -def exec_python(cell): - ipython = get_ipython() - result = ipython.run_cell(cell) - log = str(result.result) - if result.error_before_exec is not None: - log += f"\n{result.error_before_exec}" - if result.error_in_exec is not None: - log += f"\n{result.error_in_exec}" - return log - - -def exec_sh(script): - return user_proxy.execute_code_blocks([("sh", script)]) - - -# register the functions -user_proxy.register_function( - function_map={ - "python": exec_python, - "sh": exec_sh, - } -) - -if __name__ == "__main__": - # start the conversation - user_proxy.initiate_chat( - chatbot, - message="Draw two agents chatting with each other with an example dialog. Don't add plt.show().", - ) diff --git a/pilot/scene/chat_data/chat_excel/excel_analyze/prompt.py b/pilot/scene/chat_data/chat_excel/excel_analyze/prompt.py index 0af8b3c3a..14c743ef5 100644 --- a/pilot/scene/chat_data/chat_excel/excel_analyze/prompt.py +++ b/pilot/scene/chat_data/chat_excel/excel_analyze/prompt.py @@ -19,7 +19,7 @@ Constraint: 2.Please choose the best one from the display methods given below for data rendering, and put the type name into the name parameter value that returns the required format. If you cannot find the most suitable one, use 'Table' as the display method. , the available data display methods are as follows: {disply_type} 3.The table name that needs to be used in SQL is: {table_name}. Please check the sql you generated and do not use column names that are not in the data structure. 4.Give priority to answering using data analysis. If the user's question does not involve data analysis, you can answer according to your understanding. - 5.The part of the required output format needs to be parsed by the code. Please ensure that this part of the content is output as required. + 5.All analysis sql content is converted to: [data display method][correct duckdb data analysis sql] content like this, and answer in the following format. Please respond in the following format: thoughts summary to say to user.[Data display method][Correct duckdb data analysis sql] @@ -36,7 +36,8 @@ _DEFAULT_TEMPLATE_ZH = """ 2.请从如下给出的展示方式种选择最优的一种用以进行数据渲染,将类型名称放入返回要求格式的name参数值种,如果找不到最合适的则使用'Table'作为展示方式,可用数据展示方式如下: {disply_type} 3.SQL中需要使用的表名是: {table_name},请检查你生成的sql,不要使用没在数据结构中的列名,。 4.优先使用数据分析的方式回答,如果用户问题不涉及数据分析内容,你可以按你的理解进行回答 - 5.要求的输出格式中部分需要被代码解析执行,请确保这部分内容按要求输出,不要参考历史信息的返回格式,请按下面要求返回 + 5.所有分析sql内容,都转换为:[数据展示方式][正确的duckdb数据分析sql]这样的内容, 并按下面要求格式回答 + 请确保你的输出内容格式如下: 对用户说的想法摘要.[数据展示方式][正确的duckdb数据分析sql] diff --git a/pilot/server/static/_next/static/chunks/807.23d6fbbcbcee8863.js b/pilot/server/static/_next/static/chunks/807.23d6fbbcbcee8863.js new file mode 100644 index 000000000..2fb4e5f43 --- /dev/null +++ b/pilot/server/static/_next/static/chunks/807.23d6fbbcbcee8863.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[807],{85958:function(e,l,t){t.r(l),t.d(l,{default:function(){return ew}});var a=t(85893),r=t(67294),n=t(2093),s=t(1375),o=t(2453),i=t(58989),c=t(83454),d=e=>{let{queryAgentURL:l="/api/v1/chat/completions"}=e,t=(0,r.useMemo)(()=>new AbortController,[]),a=(0,r.useCallback)(async e=>{let{context:a,data:r,chatId:n,onMessage:d,onClose:u,onDone:x,onError:m}=e;if(!a){o.ZP.warning(i.Z.t("NoContextTip"));return}let h={...r,conv_uid:n,user_input:a};if(!h.conv_uid){o.ZP.error("conv_uid 不存在,请刷新后重试");return}try{var p;await (0,s.L)("".concat(null!==(p=c.env.API_BASE_URL)&&void 0!==p?p:"").concat(l),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h),signal:t.signal,openWhenHidden:!0,async onopen(e){if(e.ok&&e.headers.get("content-type")===s.a)return},onclose(){t.abort(),null==u||u()},onerror(e){throw Error(e)},onmessage:e=>{var l;let t=null===(l=e.data)||void 0===l?void 0:l.replaceAll("\\n","\n");"[DONE]"===t?null==x||x():(null==t?void 0:t.startsWith("[ERROR]"))?null==m||m(null==t?void 0:t.replace("[ERROR]","")):null==d||d(t)}})}catch(e){t.abort(),null==m||m("Sorry, We meet some error, please try agin later.",e)}},[l]);return(0,r.useEffect)(()=>()=>{t.abort()},[]),a},u=t(39332),x=t(99513),m=t(24019),h=t(50888),p=t(97937),g=t(63606),v=t(50228),f=t(87547),j=t(89035),b=t(33035),y=t(12767),w=t(94184),Z=t.n(w),_=t(66309),N=t(81799),k=t(41468),C=t(44442),S=t(29158),P=t(98165),R=t(38426),E=t(61607),O=t(36782),D=t(13135),A=t(71577),M=t(57132),I=t(79166),L=t(93179),q=t(20640),F=t.n(q);function T(e){let{code:l,language:t}=e;return(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(A.ZP,{className:"absolute right-3 top-2 text-gray-300 hover:!text-gray-200 bg-gray-700",type:"text",icon:(0,a.jsx)(M.Z,{}),onClick:()=>{let e=F()(l);o.ZP[e?"success":"error"](e?"Copy success":"Copy failed")}}),(0,a.jsx)(L.Z,{language:t,style:I.Z,children:l})]})}let z=["custom-view","chart-view","references"],J={code(e){var l;let{inline:t,node:r,className:n,children:s,style:o,...i}=e,{context:c,matchValues:d}=function(e){let l=z.reduce((l,t)=>{let a=RegExp("<".concat(t,"[^>]*/?>"),"gi");return e=e.replace(a,e=>(l.push(e),"")),l},[]);return{context:e,matchValues:l}}(Array.isArray(s)?s.join("\n"):s),u=/language-(\w+)/.exec(n||"");return(0,a.jsxs)(a.Fragment,{children:[!t&&u?(0,a.jsx)(T,{code:c,language:null!==(l=null==u?void 0:u[1])&&void 0!==l?l:"javascript"}):(0,a.jsx)("code",{...i,style:o,className:"px-[6px] py-[2px] rounded bg-gray-700 text-gray-100 dark:bg-gray-100 dark:text-gray-800 text-sm",children:s}),(0,a.jsx)(b.D,{components:J,rehypePlugins:[y.Z],children:d.join("\n")})]})},ul(e){let{children:l}=e;return(0,a.jsx)("ul",{className:"py-1",children:l})},ol(e){let{children:l}=e;return(0,a.jsx)("ol",{className:"py-1",children:l})},li(e){let{children:l,ordered:t}=e;return(0,a.jsx)("li",{className:"text-sm leading-7 ml-5 pl-2 text-gray-600 dark:text-gray-300 ".concat(t?"list-decimal":"list-disc"),children:l})},table(e){let{children:l}=e;return(0,a.jsx)("table",{className:"my-2 rounded-tl-md rounded-tr-md max-w-full bg-white dark:bg-gray-900 text-sm rounded-lg overflow-hidden",children:l})},thead(e){let{children:l}=e;return(0,a.jsx)("thead",{className:"bg-[#fafafa] dark:bg-black font-semibold",children:l})},th(e){let{children:l}=e;return(0,a.jsx)("th",{className:"!text-left p-4",children:l})},td(e){let{children:l}=e;return(0,a.jsx)("td",{className:"p-4 border-t border-[#f0f0f0] dark:border-gray-700",children:l})},h1(e){let{children:l}=e;return(0,a.jsx)("h3",{className:"text-2xl font-bold my-4 border-b border-slate-300 pb-4",children:l})},h2(e){let{children:l}=e;return(0,a.jsx)("h3",{className:"text-xl font-bold my-3",children:l})},h3(e){let{children:l}=e;return(0,a.jsx)("h3",{className:"text-lg font-semibold my-2",children:l})},h4(e){let{children:l}=e;return(0,a.jsx)("h3",{className:"text-base font-semibold my-1",children:l})},a(e){let{children:l,href:t}=e;return(0,a.jsxs)("div",{className:"inline-block text-blue-600 dark:text-blue-400",children:[(0,a.jsx)(S.Z,{className:"mr-1"}),(0,a.jsx)("a",{href:t,target:"_blank",children:l})]})},img(e){let{src:l,alt:t}=e;return(0,a.jsx)("div",{children:(0,a.jsx)(R.Z,{className:"min-h-[1rem] max-w-full max-h-full border rounded",src:l,alt:t,placeholder:(0,a.jsx)(_.Z,{icon:(0,a.jsx)(P.Z,{spin:!0}),color:"processing",children:"Image Loading..."}),fallback:"/images/fallback.png"})})},blockquote(e){let{children:l}=e;return(0,a.jsx)("blockquote",{className:"py-4 px-6 border-l-4 border-blue-600 rounded bg-white my-2 text-gray-500 dark:bg-slate-800 dark:text-gray-200 dark:border-white shadow-sm",children:l})},references(e){let l,{children:t}=e;try{l=JSON.parse(t)}catch(e){return console.log(e),(0,a.jsx)("p",{className:"text-sm",children:"Render Reference Error!"})}let r=null==l?void 0:l.references;return!r||(null==r?void 0:r.length)<1?null:(0,a.jsxs)("div",{className:"border-t-[1px] border-gray-300 mt-3 py-2",children:[(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-2",children:[(0,a.jsx)(S.Z,{className:"mr-2"}),(0,a.jsx)("span",{className:"font-semibold",children:l.title})]}),r.map((e,l)=>{var t;return(0,a.jsxs)("p",{className:"text-sm font-normal block ml-2 h-6 leading-6 overflow-hidden",children:[(0,a.jsxs)("span",{className:"inline-block w-6",children:["[",l+1,"]"]}),(0,a.jsx)("span",{className:"mr-4 text-blue-400",children:e.name}),null==e?void 0:null===(t=e.pages)||void 0===t?void 0:t.map((l,t)=>(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{children:l},"file_page_".concat(t)),t<(null==e?void 0:e.pages.length)-1&&(0,a.jsx)("span",{children:","},"file_page__".concat(t))]}))]},"file_".concat(l))})]})},"chart-view":function(e){var l,t,r;let n,{content:s}=e;try{n=JSON.parse(s)}catch(e){console.log(e,s),n={type:"response_table",sql:"",data:[]}}let o=(null==n?void 0:null===(l=n.data)||void 0===l?void 0:l[0])?null===(t=Object.keys(null==n?void 0:null===(r=n.data)||void 0===r?void 0:r[0]))||void 0===t?void 0:t.map(e=>({title:e,dataIndex:e,key:e})):[],i={key:"chart",label:"Chart",children:(0,a.jsx)(D._z,{data:null==n?void 0:n.data,chartType:(0,D.aG)(null==n?void 0:n.type)})},c={key:"sql",label:"SQL",children:(0,a.jsx)(T,{code:(0,O.WU)(null==n?void 0:n.sql,{language:"mysql"}),language:"sql"})},d={key:"data",label:"Data",children:(0,a.jsx)(E.Z,{dataSource:null==n?void 0:n.data,columns:o})},u=(null==n?void 0:n.type)==="response_table"?[d,c]:[i,c,d];return(0,a.jsx)("div",{children:(0,a.jsx)(C.Z,{defaultActiveKey:(null==n?void 0:n.type)==="response_table"?"data":"chart",items:u,size:"small"})},null==n?void 0:n.type)}},W={todo:{bgClass:"bg-gray-500",icon:(0,a.jsx)(m.Z,{className:"ml-2"})},runing:{bgClass:"bg-blue-500",icon:(0,a.jsx)(h.Z,{className:"ml-2"})},failed:{bgClass:"bg-red-500",icon:(0,a.jsx)(p.Z,{className:"ml-2"})},completed:{bgClass:"bg-green-500",icon:(0,a.jsx)(g.Z,{className:"ml-2"})}};function H(e){return e.replaceAll("\\n","\n").replace(/]+)>/gi,"").replace(/]+)>/gi,"")}var V=(0,r.memo)(function(e){let{children:l,content:t,isChartChat:n,onLinkClick:s}=e,{scene:o}=(0,r.useContext)(k.p),{context:i,model_name:c,role:d}=t,u="view"===d,{relations:x,value:m,cachePlguinContext:h}=(0,r.useMemo)(()=>{if("string"!=typeof i)return{relations:[],value:"",cachePlguinContext:[]};let[e,l]=i.split(" relations:"),t=l?l.split(","):[],a=[],r=0,n=e.replace(/]*>[^<]*<\/dbgpt-view>/gi,e=>{try{var l;let t=e.replaceAll("\n","\\n").replace(/<[^>]*>|<\/[^>]*>/gm,""),n=JSON.parse(t),s="".concat(r,"");return a.push({...n,result:H(null!==(l=n.result)&&void 0!==l?l:"")}),r++,s}catch(l){return console.log(l.message,l),e}});return{relations:t,cachePlguinContext:a,value:n}},[i]),p=(0,r.useMemo)(()=>({"custom-view"(e){var l;let{children:t}=e,r=+t.toString();if(!h[r])return t;let{name:n,status:s,err_msg:o,result:i}=h[r],{bgClass:c,icon:d}=null!==(l=W[s])&&void 0!==l?l:{};return(0,a.jsxs)("div",{className:"bg-white dark:bg-[#212121] rounded-lg overflow-hidden my-2 flex flex-col lg:max-w-[80%]",children:[(0,a.jsxs)("div",{className:Z()("flex px-4 md:px-6 py-2 items-center text-white text-sm",c),children:[n,d]}),i?(0,a.jsx)("div",{className:"px-4 md:px-6 py-4 text-sm",children:(0,a.jsx)(b.D,{components:J,rehypePlugins:[y.Z],children:null!=i?i:""})}):(0,a.jsx)("div",{className:"px-4 md:px-6 py-4 text-sm",children:o})]})}}),[i,h]);return(0,a.jsxs)("div",{className:Z()("relative flex flex-wrap w-full px-2 sm:px-4 py-2 sm:py-4 rounded-xl break-words",{"bg-slate-100 dark:bg-[#353539]":u,"lg:w-full xl:w-full pl-0":["chat_with_db_execute","chat_dashboard"].includes(o)}),children:[(0,a.jsx)("div",{className:"mr-2 flex flex-shrink-0 items-center justify-center h-7 w-7 rounded-full text-lg sm:mr-4",children:u?(0,N.A)(c)||(0,a.jsx)(v.Z,{}):(0,a.jsx)(f.Z,{})}),(0,a.jsxs)("div",{className:"flex-1 overflow-hidden items-center text-md leading-8",children:[!u&&"string"==typeof i&&i,u&&n&&"object"==typeof i&&(0,a.jsxs)("div",{children:["[".concat(i.template_name,"]: "),(0,a.jsxs)("span",{className:"text-[#1677ff] cursor-pointer",onClick:s,children:[(0,a.jsx)(j.Z,{className:"mr-1"}),i.template_introduce||"More Details"]})]}),u&&"string"==typeof i&&(0,a.jsx)(b.D,{components:{...J,...p},rehypePlugins:[y.Z],children:H(m)}),!!(null==x?void 0:x.length)&&(0,a.jsx)("div",{className:"flex flex-wrap mt-2",children:null==x?void 0:x.map((e,l)=>(0,a.jsx)(_.Z,{color:"#108ee9",children:e},e+l))})]}),l]})}),$=t(59301),G=t(41132),B=t(74312),K=t(3414),Q=t(72868),U=t(59562),X=t(14553),Y=t(25359),ee=t(7203),el=t(48665),et=t(26047),ea=t(99056),er=t(57814),en=t(63955),es=t(33028),eo=t(40911),ei=t(66478),ec=t(83062),ed=t(50489),eu=t(67421),ex=e=>{var l;let{conv_index:t,question:n,knowledge_space:s}=e,{t:i}=(0,eu.$G)(),{chatId:c}=(0,r.useContext)(k.p),[d,u]=(0,r.useState)(""),[x,m]=(0,r.useState)(4),[h,p]=(0,r.useState)(""),g=(0,r.useRef)(null),[v,f]=o.ZP.useMessage(),[j,b]=(0,r.useState)({});(0,r.useEffect)(()=>{(0,ed.Vx)((0,ed.Lu)()).then(e=>{var l;console.log(e),b(null!==(l=e[1])&&void 0!==l?l:{})}).catch(e=>{console.log(e)})},[]);let y=(0,r.useCallback)((e,l)=>{l?(0,ed.Vx)((0,ed.Eb)(c,t)).then(e=>{var l,t,a,r;let n=null!==(l=e[1])&&void 0!==l?l:{};u(null!==(t=n.ques_type)&&void 0!==t?t:""),m(parseInt(null!==(a=n.score)&&void 0!==a?a:"4")),p(null!==(r=n.messages)&&void 0!==r?r:"")}).catch(e=>{console.log(e)}):(u(""),m(4),p(""))},[c,t]),w=(0,B.Z)(K.Z)(e=>{let{theme:l}=e;return{backgroundColor:"dark"===l.palette.mode?"#FBFCFD":"#0E0E10",...l.typography["body-sm"],padding:l.spacing(1),display:"flex",alignItems:"center",justifyContent:"center",borderRadius:4,width:"100%",height:"100%"}});return(0,a.jsxs)(Q.L,{onOpenChange:y,children:[f,(0,a.jsx)(ec.Z,{title:i("Rating"),children:(0,a.jsx)(U.Z,{slots:{root:X.ZP},slotProps:{root:{variant:"plain",color:"primary"}},sx:{borderRadius:40},children:(0,a.jsx)($.Z,{})})}),(0,a.jsxs)(Y.Z,{children:[(0,a.jsx)(ee.Z,{disabled:!0,sx:{minHeight:0}}),(0,a.jsx)(el.Z,{sx:{width:"100%",maxWidth:350,display:"grid",gap:3,padding:1},children:(0,a.jsx)("form",{onSubmit:e=>{e.preventDefault();let l={conv_uid:c,conv_index:t,question:n,knowledge_space:s,score:x,ques_type:d,messages:h};console.log(l),(0,ed.Vx)((0,ed.VC)({data:l})).then(e=>{v.open({type:"success",content:"save success"})}).catch(e=>{v.open({type:"error",content:"save error"})})},children:(0,a.jsxs)(et.Z,{container:!0,spacing:.5,columns:13,sx:{flexGrow:1},children:[(0,a.jsx)(et.Z,{xs:3,children:(0,a.jsx)(w,{children:i("Q_A_Category")})}),(0,a.jsx)(et.Z,{xs:10,children:(0,a.jsx)(ea.Z,{action:g,value:d,placeholder:"Choose one…",onChange:(e,l)=>u(null!=l?l:""),...d&&{endDecorator:(0,a.jsx)(X.ZP,{size:"sm",variant:"plain",color:"neutral",onMouseDown:e=>{e.stopPropagation()},onClick:()=>{var e;u(""),null===(e=g.current)||void 0===e||e.focusVisible()},children:(0,a.jsx)(G.Z,{})}),indicator:null},sx:{width:"100%"},children:null===(l=Object.keys(j))||void 0===l?void 0:l.map(e=>(0,a.jsx)(er.Z,{value:e,children:j[e]},e))})}),(0,a.jsx)(et.Z,{xs:3,children:(0,a.jsx)(w,{children:(0,a.jsx)(ec.Z,{title:(0,a.jsx)(el.Z,{children:(0,a.jsx)("div",{children:i("feed_back_desc")})}),variant:"solid",placement:"left",children:i("Q_A_Rating")})})}),(0,a.jsx)(et.Z,{xs:10,sx:{pl:0,ml:0},children:(0,a.jsx)(en.Z,{"aria-label":"Custom",step:1,min:0,max:5,valueLabelFormat:function(e){return({0:i("Lowest"),1:i("Missed"),2:i("Lost"),3:i("Incorrect"),4:i("Verbose"),5:i("Best")})[e]},valueLabelDisplay:"on",marks:[{value:0,label:"0"},{value:1,label:"1"},{value:2,label:"2"},{value:3,label:"3"},{value:4,label:"4"},{value:5,label:"5"}],sx:{width:"90%",pt:3,m:2,ml:1},onChange:e=>{var l;return m(null===(l=e.target)||void 0===l?void 0:l.value)},value:x})}),(0,a.jsx)(et.Z,{xs:13,children:(0,a.jsx)(es.Z,{placeholder:i("Please_input_the_text"),value:h,onChange:e=>p(e.target.value),minRows:2,maxRows:4,endDecorator:(0,a.jsx)(eo.ZP,{level:"body-xs",sx:{ml:"auto"},children:i("input_count")+h.length+i("input_unit")}),sx:{width:"100%",fontSize:14}})}),(0,a.jsx)(et.Z,{xs:13,children:(0,a.jsx)(ei.Z,{type:"submit",variant:"outlined",sx:{width:"100%",height:"100%"},children:i("submit")})})]})})})]})]})},em=t(32983),eh=t(12069),ep=t(96486),eg=t.n(ep),ev=t(38954),ef=t(98399),ej=e=>{var l;let{messages:t,onSubmit:s}=e,{dbParam:i,currentDialogue:c,scene:d,model:m,refreshDialogList:h,chatId:p,agentList:g}=(0,r.useContext)(k.p),{t:v}=(0,eu.$G)(),f=(0,u.useSearchParams)(),j=null!==(l=f&&f.get("spaceNameOriginal"))&&void 0!==l?l:"",[b,y]=(0,r.useState)(!1),[w,_]=(0,r.useState)(!1),[C,S]=(0,r.useState)(t),[P,R]=(0,r.useState)(""),E=(0,r.useRef)(null),O=(0,r.useMemo)(()=>"chat_dashboard"===d,[d]),D=(0,r.useMemo)(()=>{switch(d){case"chat_agent":return g.join(",");case"chat_excel":return null==c?void 0:c.select_param;default:return j||i}},[d,g,c,i,j]),A=async e=>{if(!b&&e.trim())try{y(!0),await s(e,{select_param:null!=D?D:""})}finally{y(!1)}},I=e=>{try{return JSON.parse(e)}catch(l){return e}},[L,q]=o.ZP.useMessage(),T=async e=>{let l=null==e?void 0:e.replace(/\trelations:.*/g,""),t=F()(l);t?l?L.open({type:"success",content:v("Copy_success")}):L.open({type:"warning",content:v("Copy_nothing")}):L.open({type:"error",content:v("Copry_error")})};return(0,n.Z)(async()=>{let e=(0,ef.a_)();e&&e.id===p&&(await A(e.message),h(),localStorage.removeItem(ef.rU))},[p]),(0,r.useEffect)(()=>{let e=t;O&&(e=eg().cloneDeep(t).map(e=>((null==e?void 0:e.role)==="view"&&"string"==typeof(null==e?void 0:e.context)&&(e.context=I(null==e?void 0:e.context)),e))),S(e.filter(e=>["view","human"].includes(e.role)))},[O,t]),(0,r.useEffect)(()=>{setTimeout(()=>{var e;null===(e=E.current)||void 0===e||e.scrollTo(0,E.current.scrollHeight)},50)},[t]),(0,a.jsxs)(a.Fragment,{children:[q,(0,a.jsx)("div",{ref:E,className:"flex flex-1 overflow-y-auto pb-8 w-full flex-col",children:(0,a.jsx)("div",{className:"flex items-center flex-1 flex-col text-sm leading-6 text-slate-900 dark:text-slate-300 sm:text-base sm:leading-7",children:C.length?C.map((e,l)=>{var t;return(0,a.jsx)(V,{content:e,isChartChat:O,onLinkClick:()=>{_(!0),R(JSON.stringify(null==e?void 0:e.context,null,2))},children:"view"===e.role&&(0,a.jsxs)("div",{className:"flex w-full flex-row-reverse pt-2 border-t border-gray-200",children:[(0,a.jsx)(ex,{conv_index:Math.ceil((l+1)/2),question:null===(t=null==C?void 0:C.filter(l=>(null==l?void 0:l.role)==="human"&&(null==l?void 0:l.order)===e.order)[0])||void 0===t?void 0:t.context,knowledge_space:j||i||""}),(0,a.jsx)(ec.Z,{title:v("Copy"),children:(0,a.jsx)(ei.Z,{onClick:()=>T(null==e?void 0:e.context),slots:{root:X.ZP},slotProps:{root:{variant:"plain",color:"primary"}},sx:{borderRadius:40},children:(0,a.jsx)(M.Z,{})})})]})},l)}):(0,a.jsx)(em.Z,{image:"/empty.png",imageStyle:{width:320,height:320,margin:"0 auto",maxWidth:"100%",maxHeight:"100%"},className:"flex items-center justify-center flex-col h-full w-full",description:"Start a conversation"})})}),(0,a.jsx)("div",{className:Z()("relative after:absolute after:-top-8 after:h-8 after:w-full after:bg-gradient-to-t after:from-white after:to-transparent dark:after:from-[#212121]",{"cursor-not-allowed":"chat_excel"===d&&!(null==c?void 0:c.select_param)}),children:(0,a.jsxs)("div",{className:"flex flex-wrap w-full py-2 sm:pt-6 sm:pb-10",children:[m&&(0,a.jsx)("div",{className:"mr-2 flex items-center h-10",children:(0,N.A)(m)}),(0,a.jsx)(ev.Z,{loading:b,onSubmit:A})]})}),(0,a.jsx)(eh.default,{title:"JSON Editor",open:w,width:"60%",cancelButtonProps:{hidden:!0},onOk:()=>{_(!1)},onCancel:()=>{_(!1)},children:(0,a.jsx)(x.Z,{className:"w-full h-[500px]",language:"json",value:P})})]})},eb=t(34625),ey=t(45247),ew=()=>{var e;let l=(0,u.useSearchParams)(),{scene:t,chatId:s,model:o,setModel:i}=(0,r.useContext)(k.p),c=d({}),x=null!==(e=l&&l.get("initMessage"))&&void 0!==e?e:"",[m,h]=(0,r.useState)(!1),[p,g]=(0,r.useState)(),[v,f]=(0,r.useState)([]),j=async()=>{h(!0);let[,e]=await (0,ed.Vx)((0,ed.$i)(s));f(null!=e?e:[]),h(!1)},b=e=>{var l;let t=null===(l=e[e.length-1])||void 0===l?void 0:l.context;if(t)try{let e=JSON.parse(t);g((null==e?void 0:e.template_name)==="report"?null==e?void 0:e.charts:void 0)}catch(e){g(void 0)}};(0,n.Z)(async()=>{let e=(0,ef.a_)();e&&e.id===s||await j()},[x,s]),(0,r.useEffect)(()=>{var e,l;if(!v.length)return;let t=null===(e=null===(l=v.filter(e=>"view"===e.role))||void 0===l?void 0:l.slice(-1))||void 0===e?void 0:e[0];(null==t?void 0:t.model_name)&&i(t.model_name),b(v)},[v.length]);let y=(0,r.useCallback)((e,l)=>new Promise(a=>{let r=[...v,{role:"human",context:e,model_name:o,order:0,time_stamp:0},{role:"view",context:"",model_name:o,order:0,time_stamp:0}],n=r.length-1;f([...r]),c({context:e,data:{...l,chat_mode:t||"chat_normal",model_name:o},chatId:s,onMessage:e=>{r[n].context=e,f([...r])},onDone:()=>{b(r),a()},onClose:()=>{b(r),a()},onError:e=>{r[n].context=e,f([...r]),a()}})}),[v,c,o]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ey.Z,{visible:m}),(0,a.jsx)(eb.Z,{refreshHistory:j,modelChange:e=>{i(e)}}),(0,a.jsxs)("div",{className:"px-4 flex flex-1 flex-wrap overflow-hidden relative",children:[!!(null==p?void 0:p.length)&&(0,a.jsx)("div",{className:"w-full xl:w-3/4 h-3/5 xl:pr-4 xl:h-full overflow-y-auto",children:(0,a.jsx)(D.ZP,{chartsData:p})}),!(null==p?void 0:p.length)&&"chat_dashboard"===t&&(0,a.jsx)(em.Z,{image:"/empty.png",imageStyle:{width:320,height:320,margin:"0 auto",maxWidth:"100%",maxHeight:"100%"},className:"w-full xl:w-3/4 h-3/5 xl:h-full pt-0 md:pt-10"}),(0,a.jsx)("div",{className:Z()("flex flex-1 flex-col overflow-hidden",{"px-0 xl:pl-4 h-2/5 xl:h-full border-t xl:border-t-0 xl:border-l":"chat_dashboard"===t,"h-full lg:px-8":"chat_dashboard"!==t}),children:(0,a.jsx)(ej,{messages:v,onSubmit:y})})]})]})}},38954:function(e,l,t){t.d(l,{Z:function(){return y}});var a=t(85893),r=t(27496),n=t(59566),s=t(71577),o=t(67294),i=t(2487),c=t(83062),d=t(2453),u=t(46735),x=t(74627),m=t(39479),h=t(51009),p=t(58299),g=t(577),v=t(30119),f=t(67421);let j=e=>{let{data:l,loading:t,submit:r,close:n}=e,{t:s}=(0,f.$G)(),o=e=>()=>{r(e),n()};return(0,a.jsx)("div",{style:{maxHeight:400,overflow:"auto"},children:(0,a.jsx)(i.Z,{dataSource:null==l?void 0:l.data,loading:t,rowKey:e=>e.prompt_name,renderItem:e=>(0,a.jsx)(i.Z.Item,{onClick:o(e.content),children:(0,a.jsx)(c.Z,{title:e.content,children:(0,a.jsx)(i.Z.Item.Meta,{style:{cursor:"copy"},title:e.prompt_name,description:s("Prompt_Info_Scene")+":".concat(e.chat_scene,",")+s("Prompt_Info_Sub_Scene")+":".concat(e.sub_chat_scene)})})},e.prompt_name)})})};var b=e=>{let{submit:l}=e,{t}=(0,f.$G)(),[r,n]=(0,o.useState)(!1),[s,i]=(0,o.useState)("common"),{data:b,loading:y}=(0,g.Z)(()=>(0,v.PR)("/prompt/list",{prompt_type:s}),{refreshDeps:[s],onError:e=>{d.ZP.error(null==e?void 0:e.message)}});return(0,a.jsx)(u.ZP,{theme:{components:{Popover:{minWidth:250}}},children:(0,a.jsx)(x.Z,{title:(0,a.jsx)(m.Z.Item,{label:"Prompt "+t("Type"),children:(0,a.jsx)(h.default,{style:{width:150},value:s,onChange:e=>{i(e)},options:[{label:t("Public")+" Prompts",value:"common"},{label:t("Private")+" Prompts",value:"private"}]})}),content:(0,a.jsx)(j,{data:b,loading:y,submit:l,close:()=>{n(!1)}}),placement:"topRight",trigger:"click",open:r,onOpenChange:e=>{n(e)},children:(0,a.jsx)(c.Z,{title:t("Click_Select")+" Prompt",children:(0,a.jsx)(p.Z,{className:"bottom-[30%]"})})})})},y=function(e){let{children:l,loading:t,onSubmit:i,...c}=e,[d,u]=(0,o.useState)("");return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.default.TextArea,{className:"flex-1",size:"large",value:d,autoSize:{minRows:1,maxRows:4},...c,onPressEnter:e=>{if(d.trim()&&13===e.keyCode){if(e.shiftKey){u(e=>e+"\n");return}i(d),setTimeout(()=>{u("")},0)}},onChange:e=>{if("number"==typeof c.maxLength){u(e.target.value.substring(0,c.maxLength));return}u(e.target.value)}}),(0,a.jsx)(s.ZP,{className:"ml-2 flex items-center justify-center",size:"large",type:"text",loading:t,icon:(0,a.jsx)(r.Z,{}),onClick:()=>{i(d)}}),(0,a.jsx)(b,{submit:e=>{u(d+e)}}),l]})}},45247:function(e,l,t){var a=t(85893),r=t(50888);l.Z=function(e){let{visible:l}=e;return l?(0,a.jsx)("div",{className:"absolute w-full h-full top-0 left-0 flex justify-center items-center z-10 bg-white dark:bg-black bg-opacity-50 dark:bg-opacity-50 backdrop-blur-sm text-3xl animate-fade animate-duration-200",children:(0,a.jsx)(r.Z,{})}):null}}}]); \ No newline at end of file diff --git a/pilot/server/static/_next/static/chunks/pages/knowledge-258ebd9530cbbd39.js b/pilot/server/static/_next/static/chunks/pages/knowledge-258ebd9530cbbd39.js new file mode 100644 index 000000000..57ba87631 --- /dev/null +++ b/pilot/server/static/_next/static/chunks/pages/knowledge-258ebd9530cbbd39.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[265],{54681:function(e,t,l){(window.__NEXT_P=window.__NEXT_P||[]).push(["/knowledge",function(){return l(4223)}])},47207:function(e,t,l){"use strict";l.d(t,{Z:function(){return c}});var s=l(85893),a=l(27595),n=l(27329),i=l(68346);function c(e){let{type:t}=e;return"TEXT"===t?(0,s.jsx)(a.Z,{className:"text-[#2AA3FF] mr-2 !text-lg"}):"DOCUMENT"===t?(0,s.jsx)(n.Z,{className:"text-[#2AA3FF] mr-2 !text-lg"}):(0,s.jsx)(i.Z,{className:"text-[#2AA3FF] mr-2 !text-lg"})}},4223:function(e,t,l){"use strict";l.r(t),l.d(t,{default:function(){return es}});var s=l(85893),a=l(67294),n=l(24969),i=l(71577),c=l(12069),r=l(3363),o=l(46735),d=l(74627),m=l(40411),u=l(11163),x=l(25675),h=l.n(x),p=l(28058),_=l(31484),j=l(78346),f=l(83062),b=l(66309),g=l(85813),N=l(96074),Z=l(32983),w=l(42075),y=l(75081),k=l(31326),v=l(88008),P=l(27704),T=l(18754),S=l(50489),C=l(30381),F=l.n(C),D=l(59566),E=l(71230),I=l(15746),A=l(39479),V=l(44442),z=l(67421),O=l(31545),M=l(6321);let{TextArea:q}=D.default;function U(e){let{space:t,argumentsShow:l,setArgumentsShow:n}=e,{t:r}=(0,z.$G)(),[o,d]=(0,a.useState)(),[m,u]=(0,a.useState)(!1),x=async()=>{let[e,l]=await (0,S.Vx)((0,S.Tu)(t.name));d(l)};(0,a.useEffect)(()=>{x()},[t.name]);let h=[{key:"Embedding",label:(0,s.jsxs)("div",{children:[(0,s.jsx)(O.Z,{}),r("Embedding")]}),children:(0,s.jsxs)(E.Z,{gutter:24,children:[(0,s.jsx)(I.Z,{span:12,offset:0,children:(0,s.jsx)(A.Z.Item,{tooltip:r("the_top_k_vectors"),rules:[{required:!0}],label:r("topk"),name:["embedding","topk"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12"})})}),(0,s.jsx)(I.Z,{span:12,children:(0,s.jsx)(A.Z.Item,{tooltip:r("Set_a_threshold_score"),rules:[{required:!0}],label:r("recall_score"),name:["embedding","recall_score"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:r("Please_input_the_owner")})})}),(0,s.jsx)(I.Z,{span:12,children:(0,s.jsx)(A.Z.Item,{tooltip:r("Recall_Type"),rules:[{required:!0}],label:r("recall_type"),name:["embedding","recall_type"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12"})})}),(0,s.jsx)(I.Z,{span:12,children:(0,s.jsx)(A.Z.Item,{tooltip:r("A_model_used"),rules:[{required:!0}],label:r("model"),name:["embedding","model"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12"})})}),(0,s.jsx)(I.Z,{span:12,children:(0,s.jsx)(A.Z.Item,{tooltip:r("The_size_of_the_data_chunks"),rules:[{required:!0}],label:r("chunk_size"),name:["embedding","chunk_size"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12"})})}),(0,s.jsx)(I.Z,{span:12,children:(0,s.jsx)(A.Z.Item,{tooltip:r("The_amount_of_overlap"),rules:[{required:!0}],label:r("chunk_overlap"),name:["embedding","chunk_overlap"],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:r("Please_input_the_description")})})})]})},{key:"Prompt",label:(0,s.jsxs)("div",{children:[(0,s.jsx)(M.Z,{}),r("Prompt")]}),children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(A.Z.Item,{tooltip:r("A_contextual_parameter"),label:r("scene"),name:["prompt","scene"],children:(0,s.jsx)(q,{rows:4,className:"mb-2"})}),(0,s.jsx)(A.Z.Item,{tooltip:r("structure_or_format"),label:r("template"),name:["prompt","template"],children:(0,s.jsx)(q,{rows:7,className:"mb-2"})}),(0,s.jsx)(A.Z.Item,{tooltip:r("The_maximum_number_of_tokens"),label:r("max_token"),name:["prompt","max_token"],children:(0,s.jsx)(D.default,{className:"mb-2"})})]})}],p=async e=>{u(!0);let[l,s,a]=await (0,S.Vx)((0,S.iH)(t.name,{argument:JSON.stringify(e)}));u(!1),(null==a?void 0:a.success)&&n(!1)};return(0,s.jsx)(c.default,{width:850,open:l,onCancel:()=>{n(!1)},footer:null,children:(0,s.jsx)(y.Z,{spinning:m,children:(0,s.jsxs)(A.Z,{size:"large",className:"mt-4",layout:"vertical",name:"basic",initialValues:{...o},autoComplete:"off",onFinish:p,children:[(0,s.jsx)(V.Z,{items:h}),(0,s.jsxs)("div",{className:"mt-3 mb-3",children:[(0,s.jsx)(i.ZP,{htmlType:"submit",type:"primary",className:"mr-6",children:r("Submit")}),(0,s.jsx)(i.ZP,{onClick:()=>{n(!1)},children:r("close")})]})]})})})}var G=l(47207);let{confirm:R}=c.default;function L(e){let{space:t}=e,{t:l}=(0,z.$G)(),c=(0,u.useRouter)(),[r,o]=(0,a.useState)(!1),[d,m]=(0,a.useState)([]),[x,h]=(0,a.useState)(!1),[_,j]=(0,a.useState)(0),C=(0,a.useRef)(1),D=(0,a.useMemo)(()=>d.length<_,[d.length,_]),E=e=>{R({title:l("Tips"),icon:(0,s.jsx)(p.Z,{}),content:"".concat(l("Del_Document_Tips"),"?"),okText:"Yes",okType:"danger",cancelText:"No",async onOk(){await O(e)}})};async function I(){o(!0);let[e,l]=await (0,S.Vx)((0,S._Q)(t.name,{page:C.current,page_size:18}));m(null==l?void 0:l.data),j(null==l?void 0:l.total),o(!1)}let A=async()=>{if(!D)return;o(!0),C.current+=1;let[e,l]=await (0,S.Vx)((0,S._Q)(t.name,{page:C.current,page_size:18}));m([...d,...l.data]),o(!1)},V=async(e,t)=>{await (0,S.Vx)((0,S.Hx)(e,{doc_ids:[t]}))},O=async l=>{await (0,S.Vx)((0,S.n3)(t.name,{doc_name:l.doc_name})),I(),e.onDeleteDoc()},M=()=>{e.onAddDoc(t.name)},q=(e,t)=>{let l;switch(e){case"TODO":l="gold";break;case"RUNNING":l="#2db7f5";break;case"FINISHED":l="#87d068";break;default:l="f50"}return(0,s.jsx)(f.Z,{title:t,children:(0,s.jsx)(b.Z,{color:l,children:e})})};return(0,a.useEffect)(()=>{I()},[t]),(0,s.jsxs)("div",{className:"collapse-container pt-2 px-4",children:[(0,s.jsxs)(w.Z,{children:[(0,s.jsx)(i.ZP,{size:"middle",type:"primary",className:"flex items-center",icon:(0,s.jsx)(n.Z,{}),onClick:M,children:l("Add_Datasource")}),(0,s.jsx)(i.ZP,{size:"middle",className:"flex items-center mx-2",icon:(0,s.jsx)(T.Z,{}),onClick:()=>{h(!0)},children:"Arguments"})]}),(0,s.jsx)(N.Z,{}),(0,s.jsx)(y.Z,{spinning:r,children:(null==d?void 0:d.length)>0?(0,s.jsxs)("div",{className:"max-h-96 overflow-auto max-w-3/4",children:[(0,s.jsx)("div",{className:"mt-3 grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2 lg:grid-cols-3 xl:gap-x-5",children:d.map(e=>(0,s.jsxs)(g.Z,{className:" dark:bg-[#484848] relative shrink-0 grow-0 cursor-pointer rounded-[10px] border border-gray-200 border-solid w-full",title:(0,s.jsx)(f.Z,{title:e.doc_name,children:(0,s.jsxs)("div",{className:"truncate ",children:[(0,s.jsx)(G.Z,{type:e.doc_type}),(0,s.jsx)("span",{children:e.doc_name})]})}),extra:(0,s.jsxs)("div",{className:"mx-3",children:[(0,s.jsx)(f.Z,{title:"detail",children:(0,s.jsx)(k.Z,{className:"mr-2 !text-lg",style:{color:"#1b7eff",fontSize:"20px"},onClick:()=>{c.push("/knowledge/chunk/?spaceName=".concat(t.name,"&id=").concat(e.id))}})}),(0,s.jsx)(f.Z,{title:"Sync",children:(0,s.jsx)(v.Z,{className:"mr-2 !text-lg",style:{color:"#1b7eff",fontSize:"20px"},onClick:()=>{V(t.name,e.id)}})}),(0,s.jsx)(f.Z,{title:"Delete",children:(0,s.jsx)(P.Z,{className:"text-[#ff1b2e] !text-lg",onClick:()=>{E(e)}})})]}),children:[(0,s.jsxs)("p",{className:"mt-2 font-semibold ",children:[l("Size"),":"]}),(0,s.jsxs)("p",{children:[e.chunk_size," chunks"]}),(0,s.jsxs)("p",{className:"mt-2 font-semibold ",children:[l("Last_Synch"),":"]}),(0,s.jsx)("p",{children:F()(e.last_sync).format("YYYY-MM-DD HH:MM:SS")}),(0,s.jsx)("p",{className:"mt-2 mb-2",children:q(e.status,e.result)})]},e.id))}),D&&(0,s.jsx)(N.Z,{children:(0,s.jsx)("span",{className:"cursor-pointer",onClick:A,children:l("Load_More")})})]}):(0,s.jsx)(Z.Z,{image:Z.Z.PRESENTED_IMAGE_DEFAULT,children:(0,s.jsx)(i.ZP,{type:"primary",className:"flex items-center mx-auto",icon:(0,s.jsx)(n.Z,{}),onClick:M,children:"Create Now"})})}),(0,s.jsx)(U,{space:t,argumentsShow:x,setArgumentsShow:h})]})}var H=l(19284);let{confirm:Y}=c.default;function $(e){var t;let l=(0,u.useRouter)(),{t:a}=(0,z.$G)(),{space:n,getSpaces:c}=e,r=()=>{Y({title:a("Tips"),icon:(0,s.jsx)(p.Z,{}),content:"".concat(a("Del_Knowledge_Tips"),"?"),okText:"Yes",okType:"danger",cancelText:"No",async onOk(){await (0,S.Vx)((0,S.XK)({name:null==n?void 0:n.name})),c()}})},x=async e=>{e.stopPropagation();let[t,s]=await (0,S.Vx)((0,S.sW)({chat_mode:"chat_knowledge"}));(null==s?void 0:s.conv_uid)&&l.push("/chat?scene=chat_knowledge&id=".concat(null==s?void 0:s.conv_uid,"&db_param=").concat(n.name))};return(0,s.jsx)(o.ZP,{theme:{components:{Popover:{zIndexPopup:90}}},children:(0,s.jsx)(d.Z,{className:"dark:hover:border-white transition-all hover:shadow-md bg-[#FFFFFF] dark:bg-[#484848] cursor-pointer rounded-[10px] border border-gray-200 border-solid",placement:"bottom",trigger:"click",content:(0,s.jsx)(L,{space:n,onAddDoc:e.onAddDoc,onDeleteDoc:function(){c()}}),children:(0,s.jsxs)(m.Z,{className:"mr-4 mb-4 min-w-[200px] sm:w-60 lg:w-72",count:n.docs||0,children:[(0,s.jsxs)("div",{className:"flex justify-between mx-6 mt-3",children:[(0,s.jsxs)("div",{className:"text-lg font-bold text-black truncate",children:[(t=n.vector_type,(0,s.jsx)(h(),{className:"rounded-full w-8 h-8 border border-gray-200 object-contain bg-white inline-block",width:36,height:136,src:H.l[t]||"/models/knowledge-default.jpg",alt:"llm"})),(0,s.jsx)("span",{className:"dark:text-white ml-2",children:null==n?void 0:n.name})]}),(0,s.jsx)(_.Z,{onClick:e=>{e.stopPropagation(),e.nativeEvent.stopImmediatePropagation(),r()},twoToneColor:"#CD2029",className:"!text-2xl"})]}),(0,s.jsxs)("div",{className:"text-sm mt-2 p-6 pt-2 h-40",children:[(0,s.jsxs)("p",{className:"font-semibold",children:[a("Owner"),":"]}),(0,s.jsx)("p",{className:" truncate",children:null==n?void 0:n.owner}),(0,s.jsxs)("p",{className:"font-semibold mt-2",children:[a("Description"),":"]}),(0,s.jsx)("p",{className:" line-clamp-2",children:null==n?void 0:n.desc}),(0,s.jsx)("p",{className:"font-semibold mt-2",children:"Last modify:"}),(0,s.jsx)("p",{className:" truncate",children:F()(n.gmt_modified).format("YYYY-MM-DD HH:MM:SS")})]}),(0,s.jsx)("div",{className:"flex justify-center",children:(0,s.jsx)(i.ZP,{size:"middle",onClick:x,className:"mr-4 dark:text-white mb-2",shape:"round",icon:(0,s.jsx)(j.Z,{}),children:a("Chat")})})]})})})}var X=l(31365),K=l(2453),W=l(72269),B=l(64082);let{Dragger:Q}=X.default,{TextArea:J}=D.default;function ee(e){let{handleStepChange:t,spaceName:l,docType:n}=e,{t:c}=(0,z.$G)(),[r]=A.Z.useForm(),[o,d]=(0,a.useState)(!1),m=async e=>{let s;let{synchChecked:a,docName:i,textSource:c,originFileObj:r,text:o,webPageUrl:m}=e;switch(d(!0),n){case"webPage":s=await (0,S.Vx)((0,S.H_)(l,{doc_name:i,content:m,doc_type:"URL"}));break;case"file":let x=new FormData;x.append("doc_name",i||r.file.name),x.append("doc_file",r.file),x.append("doc_type","DOCUMENT"),s=await (0,S.Vx)((0,S.iG)(l,x));break;default:s=await (0,S.Vx)((0,S.H_)(l,{doc_name:i,source:c,content:o,doc_type:"TEXT"}))}a&&(null==u||u(l,null==s?void 0:s[1])),d(!1),t({label:"finish"})},u=async(e,t)=>{await (0,S.Vx)((0,S.Hx)(e,{doc_ids:[t]}))},x=e=>{let{file:t,fileList:l}=e;r.getFieldsValue().docName||r.setFieldValue("docName",t.name),0===l.length&&r.setFieldValue("originFileObj",null)},h=()=>{let e=r.getFieldsValue().originFileObj;return!!e&&(K.ZP.warning(c("Limit_Upload_File_Count_Tips")),X.default.LIST_IGNORE)},p=()=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(A.Z.Item,{label:"".concat(c("Text_Source"),":"),name:"textSource",rules:[{required:!0,message:c("Please_input_the_text_source")}],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:c("Please_input_the_text_source")})}),(0,s.jsx)(A.Z.Item,{label:"".concat(c("Text"),":"),name:"text",rules:[{required:!0,message:c("Please_input_the_description")}],children:(0,s.jsx)(J,{rows:4})})]}),_=()=>(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(A.Z.Item,{label:"".concat(c("Web_Page_URL"),":"),name:"webPageUrl",rules:[{required:!0,message:c("Please_input_the_owner")}],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:c("Please_input_the_Web_Page_URL")})})}),j=()=>(0,s.jsx)(s.Fragment,{children:(0,s.jsx)(A.Z.Item,{name:"originFileObj",rules:[{required:!0,message:c("Please_input_the_owner")}],children:(0,s.jsxs)(Q,{onChange:x,beforeUpload:h,multiple:!1,accept:".pdf,.ppt,.pptx,.xls,.xlsx,.doc,.docx,.txt,.md",children:[(0,s.jsx)("p",{className:"ant-upload-drag-icon",children:(0,s.jsx)(B.Z,{})}),(0,s.jsx)("p",{style:{color:"rgb(22, 108, 255)",fontSize:"20px"},children:c("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,"})]})})});return(0,s.jsx)(y.Z,{spinning:o,children:(0,s.jsxs)(A.Z,{form:r,size:"large",className:"mt-4",layout:"vertical",name:"basic",initialValues:{remember:!0},autoComplete:"off",onFinish:m,children:[(0,s.jsx)(A.Z.Item,{label:"".concat(c("Name"),":"),name:"docName",rules:[{required:!0,message:c("Please_input_the_name")}],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:c("Please_input_the_name")})}),(()=>{switch(n){case"webPage":return _();case"file":return j();default:return p()}})(),(0,s.jsx)(A.Z.Item,{label:"".concat(c("Synch"),":"),name:"synchChecked",initialValue:!0,children:(0,s.jsx)(W.Z,{className:"bg-slate-400",defaultChecked:!0})}),(0,s.jsxs)(A.Z.Item,{children:[(0,s.jsx)(i.ZP,{onClick:()=>{t({label:"back"})},className:"mr-4",children:"".concat(c("Back"))}),(0,s.jsx)(i.ZP,{type:"primary",htmlType:"submit",children:c("Finish")})]})]})})}function et(e){let{t}=(0,z.$G)(),{handleStepChange:l}=e,[n,c]=(0,a.useState)(!1),r=async e=>{let{spaceName:t,owner:s,description:a}=e;c(!0);let[n,i,r]=await (0,S.Vx)((0,S.be)({name:t,vector_type:"Chroma",owner:s,desc:a}));c(!1),(null==r?void 0:r.success)&&l({label:"forward",spaceName:t})};return(0,s.jsx)(y.Z,{spinning:n,children:(0,s.jsxs)(A.Z,{size:"large",className:"mt-4",layout:"vertical",name:"basic",initialValues:{remember:!0},autoComplete:"off",onFinish:r,children:[(0,s.jsx)(A.Z.Item,{label:t("Knowledge_Space_Name"),name:"spaceName",rules:[{required:!0,message:t("Please_input_the_name")},()=>({validator:(e,l)=>/[^\u4e00-\u9fa50-9a-zA-Z_-]/.test(l)?Promise.reject(Error(t("the_name_can_only_contain"))):Promise.resolve()})],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:t("Please_input_the_name")})}),(0,s.jsx)(A.Z.Item,{label:t("Owner"),name:"owner",rules:[{required:!0,message:t("Please_input_the_owner")}],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:t("Please_input_the_owner")})}),(0,s.jsx)(A.Z.Item,{label:t("Description"),name:"description",rules:[{required:!0,message:t("Please_input_the_description")}],children:(0,s.jsx)(D.default,{className:"mb-5 h-12",placeholder:t("Please_input_the_description")})}),(0,s.jsx)(A.Z.Item,{children:(0,s.jsx)(i.ZP,{type:"primary",htmlType:"submit",children:t("Next")})})]})})}function el(e){let{t}=(0,z.$G)(),{handleStepChange:l}=e,a=[{type:"text",title:t("Text"),subTitle:t("Fill your raw text"),iconType:"TEXT"},{type:"webPage",title:t("URL"),subTitle:t("Fetch_the_content_of_a_URL"),iconType:"WEBPAGE"},{type:"file",title:t("Document"),subTitle:t("Upload_a_document"),iconType:"DOCUMENT"}];return(0,s.jsx)(s.Fragment,{children:a.map((e,t)=>(0,s.jsxs)(g.Z,{className:"mt-4 mb-4 cursor-pointer",onClick:()=>{l({label:"forward",docType:e.type})},children:[(0,s.jsxs)("div",{className:"font-semibold",children:[(0,s.jsx)(G.Z,{type:e.iconType}),e.title]}),(0,s.jsx)("div",{children:e.subTitle})]},t))})}var es=()=>{let[e,t]=(0,a.useState)([]),[l,o]=(0,a.useState)(!1),[d,m]=(0,a.useState)(0),[u,x]=(0,a.useState)(""),[h,p]=(0,a.useState)(""),{t:_}=(0,z.$G)(),j=[{title:_("Knowledge_Space_Config")},{title:_("Choose_a_Datasource_type")},{title:_("Setup_the_Datasource")}];async function f(){let[e,l]=await (0,S.Vx)((0,S.Vm)());t(l)}(0,a.useEffect)(()=>{f()},[]);let b=e=>{let{label:t,spaceName:l,docType:s}=e;"finish"===t?(o(!1),f(),x(""),p("")):"forward"===t?(0===d&&f(),m(e=>e+1)):m(e=>e-1),l&&x(l),s&&p(s)};function g(e){x(e),m(1),o(!0)}return(0,s.jsxs)("div",{className:"bg-[#FAFAFA] dark:bg-[#212121] w-full h-full",children:[(0,s.jsxs)("div",{className:"page-body p-4 md:p-6 h-full overflow-auto",children:[(0,s.jsx)(i.ZP,{type:"primary",className:"flex items-center",icon:(0,s.jsx)(n.Z,{}),onClick:()=>{o(!0)},children:"Create"}),(0,s.jsx)("div",{className:"flex flex-wrap mt-4",children:null==e?void 0:e.map(e=>(0,s.jsx)($,{space:e,onAddDoc:g,getSpaces:f},e.id))})]}),(0,s.jsxs)(c.default,{title:"Add Knowledge",centered:!0,open:l,destroyOnClose:!0,onCancel:()=>{o(!1)},width:1e3,afterClose:()=>{m(0)},footer:null,children:[(0,s.jsx)(r.Z,{current:d,items:j}),0===d&&(0,s.jsx)(et,{handleStepChange:b}),1===d&&(0,s.jsx)(el,{handleStepChange:b}),2===d&&(0,s.jsx)(ee,{spaceName:u,docType:h,handleStepChange:b})]})]})}}},function(e){e.O(0,[885,64,479,442,365,813,924,411,109,774,888,179],function(){return e(e.s=54681)}),_N_E=e.O()}]); \ No newline at end of file