From dbe386dbd5f7b7f7a0fa83f1d03177b5df04a4f7 Mon Sep 17 00:00:00 2001 From: liukuikun <24622904+Harold-lkk@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:21:02 +0800 Subject: [PATCH] [Refactor] modify_directory_structure (#5) --- .pre-commit-config.yaml | 2 +- frontend/{ => React}/.gitignore | 2 +- frontend/{ => React}/.prettierignore | 2 +- frontend/{ => React}/.prettierrc.json | 0 frontend/{ => React}/README.md | 10 +++- frontend/{ => React}/index.html | 0 frontend/{ => React}/package-lock.json | 0 frontend/{ => React}/package.json | 2 +- frontend/{ => React}/src/App.module.less | 2 +- frontend/{ => React}/src/App.tsx | 0 .../{ => React}/src/assets/background.png | Bin frontend/{ => React}/src/assets/fold-icon.svg | 0 frontend/{ => React}/src/assets/logo.svg | 0 frontend/{ => React}/src/assets/pack-up.svg | 0 frontend/{ => React}/src/assets/sendIcon.svg | 0 .../src/assets/show-right-icon.png | Bin .../{ => React}/src/assets/unflod-icon.svg | 0 .../src/components/iconfont/index.tsx | 0 frontend/{ => React}/src/config/cgi.ts | 0 frontend/React/src/global.d.ts | 1 + frontend/{ => React}/src/index.less | 2 +- frontend/{ => React}/src/index.tsx | 0 .../src/pages/render/index.module.less | 2 +- .../{ => React}/src/pages/render/index.tsx | 52 +++++++++--------- .../src/pages/render/mindMapItem.tsx | 6 +- frontend/{ => React}/src/routes/routes.tsx | 0 frontend/{ => React}/src/utils/tools.ts | 4 +- frontend/{ => React}/src/vite-env.d.ts | 0 frontend/{ => React}/tsconfig.json | 0 frontend/{ => React}/vite.config.ts | 0 frontend/src/global.d.ts | 1 - {src => mindsearch}/agent/__init__.py | 7 ++- {src => mindsearch}/agent/mindsearch_agent.py | 0 .../agent/mindsearch_prompt.py | 0 {src => mindsearch}/agent/models.py | 0 app.py => mindsearch/app.py | 2 +- 36 files changed, 53 insertions(+), 44 deletions(-) rename frontend/{ => React}/.gitignore (93%) rename frontend/{ => React}/.prettierignore (89%) rename frontend/{ => React}/.prettierrc.json (100%) rename frontend/{ => React}/README.md (95%) rename frontend/{ => React}/index.html (100%) rename frontend/{ => React}/package-lock.json (100%) rename frontend/{ => React}/package.json (99%) rename frontend/{ => React}/src/App.module.less (99%) rename frontend/{ => React}/src/App.tsx (100%) rename frontend/{ => React}/src/assets/background.png (100%) rename frontend/{ => React}/src/assets/fold-icon.svg (100%) rename frontend/{ => React}/src/assets/logo.svg (100%) rename frontend/{ => React}/src/assets/pack-up.svg (100%) rename frontend/{ => React}/src/assets/sendIcon.svg (100%) rename frontend/{ => React}/src/assets/show-right-icon.png (100%) rename frontend/{ => React}/src/assets/unflod-icon.svg (100%) rename frontend/{ => React}/src/components/iconfont/index.tsx (100%) rename frontend/{ => React}/src/config/cgi.ts (100%) create mode 100644 frontend/React/src/global.d.ts rename frontend/{ => React}/src/index.less (99%) rename frontend/{ => React}/src/index.tsx (100%) rename frontend/{ => React}/src/pages/render/index.module.less (99%) rename frontend/{ => React}/src/pages/render/index.tsx (96%) rename frontend/{ => React}/src/pages/render/mindMapItem.tsx (91%) rename frontend/{ => React}/src/routes/routes.tsx (100%) rename frontend/{ => React}/src/utils/tools.ts (96%) rename frontend/{ => React}/src/vite-env.d.ts (100%) rename frontend/{ => React}/tsconfig.json (100%) rename frontend/{ => React}/vite.config.ts (100%) delete mode 100644 frontend/src/global.d.ts rename {src => mindsearch}/agent/__init__.py (89%) rename {src => mindsearch}/agent/mindsearch_agent.py (100%) rename {src => mindsearch}/agent/mindsearch_prompt.py (100%) rename {src => mindsearch}/agent/models.py (100%) rename app.py => mindsearch/app.py (98%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a00b6c1..da8ac62 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: ^(tests/data|scripts|ftdp/protocols|ftdp/template_configs|ftdp/tool_dicts)/ +exclude: ^(tests/data|scripts|frontend/React)/ repos: - repo: https://github.com/PyCQA/flake8 rev: 7.0.0 diff --git a/frontend/.gitignore b/frontend/React/.gitignore similarity index 93% rename from frontend/.gitignore rename to frontend/React/.gitignore index 02ff3d2..32199e6 100644 --- a/frontend/.gitignore +++ b/frontend/React/.gitignore @@ -17,4 +17,4 @@ npm-debug.log* yarn-debug.log* -yarn-error.log* \ No newline at end of file +yarn-error.log* diff --git a/frontend/.prettierignore b/frontend/React/.prettierignore similarity index 89% rename from frontend/.prettierignore rename to frontend/React/.prettierignore index 040a249..8b8d095 100644 --- a/frontend/.prettierignore +++ b/frontend/React/.prettierignore @@ -4,4 +4,4 @@ values node_modules .gitignore .prettierignore -.husky \ No newline at end of file +.husky diff --git a/frontend/.prettierrc.json b/frontend/React/.prettierrc.json similarity index 100% rename from frontend/.prettierrc.json rename to frontend/React/.prettierrc.json diff --git a/frontend/README.md b/frontend/React/README.md similarity index 95% rename from frontend/README.md rename to frontend/React/README.md index 4b4b98e..897a0ca 100644 --- a/frontend/README.md +++ b/frontend/React/README.md @@ -1,20 +1,27 @@ ## 开始 + ### 准备node.js开发环境 + 如需安装环境,可参照:https://nodejs.org/zh-cn/download/package-manager,从官网下载对应平台的安装程序并安装。 如环境已经准备好,跳转下一步 ### 安装依赖 + npm install ### 启动 + npm start 启动成功后,界面将出现可访问的本地url ### 配置 + #### 接口请求配置 + - 如您需要配置的服务支持跨域,可至/src/config/cgi.ts中修改请求链接,请求链接为http://ip:port/path; + - 如您需要配置的服务不支持跨域,可至vite.config.ts中配置proxy,示例如下 ``` @@ -30,4 +37,5 @@ npm start ``` ### 知悉 -- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/ \ No newline at end of file + +- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/ diff --git a/frontend/index.html b/frontend/React/index.html similarity index 100% rename from frontend/index.html rename to frontend/React/index.html diff --git a/frontend/package-lock.json b/frontend/React/package-lock.json similarity index 100% rename from frontend/package-lock.json rename to frontend/React/package-lock.json diff --git a/frontend/package.json b/frontend/React/package.json similarity index 99% rename from frontend/package.json rename to frontend/React/package.json index 5206950..2b00425 100644 --- a/frontend/package.json +++ b/frontend/React/package.json @@ -46,4 +46,4 @@ "lint-staged": { "**/*.{ts, tsx, less, module.less, json, md, .html}": "prettier --write ." } -} \ No newline at end of file +} diff --git a/frontend/src/App.module.less b/frontend/React/src/App.module.less similarity index 99% rename from frontend/src/App.module.less rename to frontend/React/src/App.module.less index 6fcb0cc..d23de93 100644 --- a/frontend/src/App.module.less +++ b/frontend/React/src/App.module.less @@ -51,4 +51,4 @@ display: flex; align-items: center; } -} \ No newline at end of file +} diff --git a/frontend/src/App.tsx b/frontend/React/src/App.tsx similarity index 100% rename from frontend/src/App.tsx rename to frontend/React/src/App.tsx diff --git a/frontend/src/assets/background.png b/frontend/React/src/assets/background.png similarity index 100% rename from frontend/src/assets/background.png rename to frontend/React/src/assets/background.png diff --git a/frontend/src/assets/fold-icon.svg b/frontend/React/src/assets/fold-icon.svg similarity index 100% rename from frontend/src/assets/fold-icon.svg rename to frontend/React/src/assets/fold-icon.svg diff --git a/frontend/src/assets/logo.svg b/frontend/React/src/assets/logo.svg similarity index 100% rename from frontend/src/assets/logo.svg rename to frontend/React/src/assets/logo.svg diff --git a/frontend/src/assets/pack-up.svg b/frontend/React/src/assets/pack-up.svg similarity index 100% rename from frontend/src/assets/pack-up.svg rename to frontend/React/src/assets/pack-up.svg diff --git a/frontend/src/assets/sendIcon.svg b/frontend/React/src/assets/sendIcon.svg similarity index 100% rename from frontend/src/assets/sendIcon.svg rename to frontend/React/src/assets/sendIcon.svg diff --git a/frontend/src/assets/show-right-icon.png b/frontend/React/src/assets/show-right-icon.png similarity index 100% rename from frontend/src/assets/show-right-icon.png rename to frontend/React/src/assets/show-right-icon.png diff --git a/frontend/src/assets/unflod-icon.svg b/frontend/React/src/assets/unflod-icon.svg similarity index 100% rename from frontend/src/assets/unflod-icon.svg rename to frontend/React/src/assets/unflod-icon.svg diff --git a/frontend/src/components/iconfont/index.tsx b/frontend/React/src/components/iconfont/index.tsx similarity index 100% rename from frontend/src/components/iconfont/index.tsx rename to frontend/React/src/components/iconfont/index.tsx diff --git a/frontend/src/config/cgi.ts b/frontend/React/src/config/cgi.ts similarity index 100% rename from frontend/src/config/cgi.ts rename to frontend/React/src/config/cgi.ts diff --git a/frontend/React/src/global.d.ts b/frontend/React/src/global.d.ts new file mode 100644 index 0000000..aadc7d3 --- /dev/null +++ b/frontend/React/src/global.d.ts @@ -0,0 +1 @@ +declare module 'event-source-polyfill'; diff --git a/frontend/src/index.less b/frontend/React/src/index.less similarity index 99% rename from frontend/src/index.less rename to frontend/React/src/index.less index f48ba61..a0714ec 100644 --- a/frontend/src/index.less +++ b/frontend/React/src/index.less @@ -59,4 +59,4 @@ li> :nth-last-child(1).f { line-height: 14px; position: relative; top: -2px; -} \ No newline at end of file +} diff --git a/frontend/src/index.tsx b/frontend/React/src/index.tsx similarity index 100% rename from frontend/src/index.tsx rename to frontend/React/src/index.tsx diff --git a/frontend/src/pages/render/index.module.less b/frontend/React/src/pages/render/index.module.less similarity index 99% rename from frontend/src/pages/render/index.module.less rename to frontend/React/src/pages/render/index.module.less index 8e41331..0486986 100644 --- a/frontend/src/pages/render/index.module.less +++ b/frontend/React/src/pages/render/index.module.less @@ -845,4 +845,4 @@ ul { transform: scale(1); opacity: 1; } -} \ No newline at end of file +} diff --git a/frontend/src/pages/render/index.tsx b/frontend/React/src/pages/render/index.tsx similarity index 96% rename from frontend/src/pages/render/index.tsx rename to frontend/React/src/pages/render/index.tsx index 0c881ea..515b648 100644 --- a/frontend/src/pages/render/index.tsx +++ b/frontend/React/src/pages/render/index.tsx @@ -79,7 +79,7 @@ const RenderTest = () => { } if (node.children) { - // 递归地在子节点中查找 + // 递归地在子节点中查找 node.children = findAndUpdateStatus(node.children, targetNode); } @@ -88,20 +88,20 @@ const RenderTest = () => { } const generateEndStyle = () => { - // 获取所有class为endline的div元素 + // 获取所有class为endline的div元素 const endlineDivs = document.getElementsByClassName('endline'); const mindMap = document.getElementById("mindMap"); - // 确保至少有两个元素 + // 确保至少有两个元素 if (endlineDivs.length >= 2 && mindMap) { - // 获取第一个和最后一个元素的边界框(bounding rectangle) + // 获取第一个和最后一个元素的边界框(bounding rectangle) const firstRect = endlineDivs[0].getBoundingClientRect(); const lastRect = endlineDivs[endlineDivs.length - 1].getBoundingClientRect(); const mindMapRect = mindMap?.getBoundingClientRect(); - // 计算y值的差值 + // 计算y值的差值 const yDiff = lastRect.top - firstRect.top; // const top = firstRect.top - mindMapRect.top; - // 如果需要包含元素的完整高度(不仅仅是顶部位置),可以加上元素的高度 - // const yDiffWithHeight = yDiff + (lastRect.height - firstRect.height); + // 如果需要包含元素的完整高度(不仅仅是顶部位置),可以加上元素的高度 + // const yDiffWithHeight = yDiff + (lastRect.height - firstRect.height); return { top: firstRect.top - mindMapRect.top, height: yDiff + 1 @@ -116,7 +116,7 @@ const RenderTest = () => { const generateWidth = () => { const articles = document.querySelectorAll('article'); - // 确保至少有两个元素 + // 确保至少有两个元素 if (articles?.length) { let maxRight = 0; articles.forEach((item, index) => { @@ -137,20 +137,20 @@ const RenderTest = () => { // 逐字渲染 const renderDraft = (str: string, type: string, endCallback: () => void) => { - // 已经输出的字符数量 + // 已经输出的字符数量 let outputIndex = 0; - // 输出字符的函数 + // 输出字符的函数 const outputText = () => { // 给出高亮后draft输出的结束标志 if (type === 'stepDraft-1' && outputIndex + 3 > str?.length) { nodeDraftRender.current = true; } - // 如果还有字符未输出 + // 如果还有字符未输出 if (outputIndex < str?.length) { - // 获取接下来要输出的1个字符(或剩余字符,如果不足3个) + // 获取接下来要输出的1个字符(或剩余字符,如果不足3个) let chunk = str.slice(outputIndex, Math.min(outputIndex + 10, str.length)); - // 更新已输出字符的索引 + // 更新已输出字符的索引 outputIndex += chunk.length; if (type === 'thought') { setDraft(str.slice(0, outputIndex)); @@ -164,13 +164,13 @@ const RenderTest = () => { setResponse(str.slice(0, outputIndex)); } } else { - // 如果没有更多字符需要输出,则清除定时器 + // 如果没有更多字符需要输出,则清除定时器 clearInterval(intervalId); endCallback && endCallback() } } - // 设定定时器ID + // 设定定时器ID let intervalId = setInterval(outputText, TEXT_INTERVAL); } @@ -191,7 +191,7 @@ const RenderTest = () => { clearInterval(intervalId); } }; - // 设定定时器ID + // 设定定时器ID let intervalId = setInterval(outputText, SEARCHLIST_INTERVAL); }; @@ -210,16 +210,16 @@ const RenderTest = () => { if (item1.highLight === item2.highLight) { return 0; } - // 如果item1是highlight,放在前面 + // 如果item1是highlight,放在前面 if (item1.highLight) { return -1; } - // 如果item2是highlight,放在后面 + // 如果item2是highlight,放在后面 return 1; }) setSearchList(highlightArr); renderDraft(currentNode.actions[1].thought, `stepDraft-1`, () => { }); - hasHighlight.current = true; // 标记为高亮已执行 + hasHighlight.current = true; // 标记为高亮已执行 }; // 渲染结论 @@ -274,12 +274,12 @@ const RenderTest = () => { // 渲染过程中保持渲染文字可见 const keepScrollTop = (divA: any, divB: any) => { - // 获取 divB 的当前高度 + // 获取 divB 的当前高度 const bHeight = divB.offsetHeight; - // 检查 divA 是否需要滚动(即 divB 的高度是否大于 divA 的可视高度) + // 检查 divA 是否需要滚动(即 divB 的高度是否大于 divA 的可视高度) if (bHeight > divA.offsetHeight) { - // 滚动到 divB 的底部在 divA 的可视区域内 + // 滚动到 divB 的底部在 divA 的可视区域内 divA.scrollTop = bHeight - divA.offsetHeight; } }; @@ -392,12 +392,12 @@ const RenderTest = () => { setShowEndNode(true); }, 300); } else if (responseTimer.current) { - // 如果 isEnd 变为 false,清除定时器 + // 如果 isEnd 变为 false,清除定时器 clearInterval(responseTimer.current); responseTimer.current = null; } - // 返回清理函数,确保组件卸载时清除定时器 + // 返回清理函数,确保组件卸载时清除定时器 return () => { if (responseTimer.current) { clearInterval(responseTimer.current); @@ -514,7 +514,7 @@ const RenderTest = () => { const abortEventSource = () => { if (eventSource) { - eventSource.close(); // 或使用其他方法关闭连接,具体取决于库的API + eventSource.close(); // 或使用其他方法关闭连接,具体取决于库的API eventSource = null; console.log('EventSource connection aborted due to timeout.'); message.error('连接中断,2s后即将刷新页面---'); @@ -678,4 +678,4 @@ const RenderTest = () => { }; -export default RenderTest; \ No newline at end of file +export default RenderTest; diff --git a/frontend/src/pages/render/mindMapItem.tsx b/frontend/React/src/pages/render/mindMapItem.tsx similarity index 91% rename from frontend/src/pages/render/mindMapItem.tsx rename to frontend/React/src/pages/render/mindMapItem.tsx index e37618f..79aa17f 100644 --- a/frontend/src/pages/render/mindMapItem.tsx +++ b/frontend/React/src/pages/render/mindMapItem.tsx @@ -1,9 +1,9 @@ import styles from './index.module.less'; import classNames from 'classnames'; -// 递归组件用于渲染mindMap中的节点 +// 递归组件用于渲染mindMap中的节点 const MindMapItem = ({ item, isEnd }: any) => { - // 递归渲染子节点 + // 递归渲染子节点 const renderChildren = () => { if (item.children && item.children.length > 0) { return ( @@ -36,4 +36,4 @@ const MindMapItem = ({ item, isEnd }: any) => { ); }; -export default MindMapItem; \ No newline at end of file +export default MindMapItem; diff --git a/frontend/src/routes/routes.tsx b/frontend/React/src/routes/routes.tsx similarity index 100% rename from frontend/src/routes/routes.tsx rename to frontend/React/src/routes/routes.tsx diff --git a/frontend/src/utils/tools.ts b/frontend/React/src/utils/tools.ts similarity index 96% rename from frontend/src/utils/tools.ts rename to frontend/React/src/utils/tools.ts index 0c50925..cc7864f 100644 --- a/frontend/src/utils/tools.ts +++ b/frontend/React/src/utils/tools.ts @@ -18,7 +18,7 @@ export const isInWhiteList = (url: string = "", list: string[] = []) => { export const replaceStr = (str: string) => { return str.replace(/\[\[(\d+)\]\]/g, (match: any, number: any) => { - // 创建一个带有class为'fnn2'的span元素,并将数字作为文本内容 + // 创建一个带有class为'fnn2'的span元素,并将数字作为文本内容 return `${number}`; }); -}; \ No newline at end of file +}; diff --git a/frontend/src/vite-env.d.ts b/frontend/React/src/vite-env.d.ts similarity index 100% rename from frontend/src/vite-env.d.ts rename to frontend/React/src/vite-env.d.ts diff --git a/frontend/tsconfig.json b/frontend/React/tsconfig.json similarity index 100% rename from frontend/tsconfig.json rename to frontend/React/tsconfig.json diff --git a/frontend/vite.config.ts b/frontend/React/vite.config.ts similarity index 100% rename from frontend/vite.config.ts rename to frontend/React/vite.config.ts diff --git a/frontend/src/global.d.ts b/frontend/src/global.d.ts deleted file mode 100644 index 8bb1c80..0000000 --- a/frontend/src/global.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'event-source-polyfill'; \ No newline at end of file diff --git a/src/agent/__init__.py b/mindsearch/agent/__init__.py similarity index 89% rename from src/agent/__init__.py rename to mindsearch/agent/__init__.py index cbb665f..d1d69fd 100644 --- a/src/agent/__init__.py +++ b/mindsearch/agent/__init__.py @@ -3,9 +3,10 @@ from lagent.actions import ActionExecutor, BingBrowser -import src.agent.models as llm_factory -from src.agent.mindsearch_agent import MindSearchAgent, MindSearchProtocol -from src.agent.mindsearch_prompt import ( +import mindsearch.agent.models as llm_factory +from mindsearch.agent.mindsearch_agent import (MindSearchAgent, + MindSearchProtocol) +from mindsearch.agent.mindsearch_prompt import ( FINAL_RESPONSE_CN, FINAL_RESPONSE_EN, GRAPH_PROMPT_CN, GRAPH_PROMPT_EN, searcher_context_template_cn, searcher_context_template_en, searcher_input_template_cn, searcher_input_template_en, diff --git a/src/agent/mindsearch_agent.py b/mindsearch/agent/mindsearch_agent.py similarity index 100% rename from src/agent/mindsearch_agent.py rename to mindsearch/agent/mindsearch_agent.py diff --git a/src/agent/mindsearch_prompt.py b/mindsearch/agent/mindsearch_prompt.py similarity index 100% rename from src/agent/mindsearch_prompt.py rename to mindsearch/agent/mindsearch_prompt.py diff --git a/src/agent/models.py b/mindsearch/agent/models.py similarity index 100% rename from src/agent/models.py rename to mindsearch/agent/models.py diff --git a/app.py b/mindsearch/app.py similarity index 98% rename from app.py rename to mindsearch/app.py index 700910a..dcc8781 100644 --- a/app.py +++ b/mindsearch/app.py @@ -11,7 +11,7 @@ from pydantic import BaseModel from sse_starlette.sse import EventSourceResponse -from src.agent import init_agent +from mindsearch.agent import init_agent app = FastAPI(docs_url='/')