Skip to content

Commit

Permalink
[Refactor] modify_directory_structure (InternLM#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harold-lkk authored Jul 29, 2024
1 parent 5bc152e commit dbe386d
Show file tree
Hide file tree
Showing 36 changed files with 53 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/.gitignore → frontend/React/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn-error.log*
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ values
node_modules
.gitignore
.prettierignore
.husky
.husky
File renamed without changes.
10 changes: 9 additions & 1 deletion frontend/README.md → frontend/React/README.md
Original file line number Diff line number Diff line change
@@ -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,示例如下

```
Expand All @@ -30,4 +37,5 @@ npm start
```

### 知悉
- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/

- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/package.json → frontend/React/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
"lint-staged": {
"**/*.{ts, tsx, less, module.less, json, md, .html}": "prettier --write ."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
display: flex;
align-items: center;
}
}
}
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions frontend/React/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'event-source-polyfill';
2 changes: 1 addition & 1 deletion frontend/src/index.less → frontend/React/src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ li> :nth-last-child(1).f {
line-height: 14px;
position: relative;
top: -2px;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,4 @@ ul {
transform: scale(1);
opacity: 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const RenderTest = () => {
}

if (node.children) {
// 递归地在子节点中查找
// 递归地在子节点中查找
node.children = findAndUpdateStatus(node.children, targetNode);
}

Expand All @@ -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
Expand All @@ -116,7 +116,7 @@ const RenderTest = () => {

const generateWidth = () => {
const articles = document.querySelectorAll('article');
// 确保至少有两个元素
// 确保至少有两个元素
if (articles?.length) {
let maxRight = 0;
articles.forEach((item, index) => {
Expand All @@ -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));
Expand All @@ -164,13 +164,13 @@ const RenderTest = () => {
setResponse(str.slice(0, outputIndex));
}
} else {
// 如果没有更多字符需要输出,则清除定时器
// 如果没有更多字符需要输出,则清除定时器
clearInterval(intervalId);
endCallback && endCallback()
}
}

// 设定定时器ID
// 设定定时器ID
let intervalId = setInterval(outputText, TEXT_INTERVAL);
}

Expand All @@ -191,7 +191,7 @@ const RenderTest = () => {
clearInterval(intervalId);
}
};
// 设定定时器ID
// 设定定时器ID
let intervalId = setInterval(outputText, SEARCHLIST_INTERVAL);
};

Expand All @@ -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; // 标记为高亮已执行
};

// 渲染结论
Expand Down Expand Up @@ -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;
}
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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后即将刷新页面---');
Expand Down Expand Up @@ -678,4 +678,4 @@ const RenderTest = () => {
</div>
};

export default RenderTest;
export default RenderTest;
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -36,4 +36,4 @@ const MindMapItem = ({ item, isEnd }: any) => {
);
};

export default MindMapItem;
export default MindMapItem;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<i class='f'>${number}</i>`;
});
};
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion frontend/src/global.d.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/agent/__init__.py → mindsearch/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app.py → mindsearch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='/')

Expand Down

0 comments on commit dbe386d

Please sign in to comment.