Skip to content

Commit dbe386d

Browse files
authored
[Refactor] modify_directory_structure (InternLM#5)
1 parent 5bc152e commit dbe386d

36 files changed

+53
-44
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exclude: ^(tests/data|scripts|ftdp/protocols|ftdp/template_configs|ftdp/tool_dicts)/
1+
exclude: ^(tests/data|scripts|frontend/React)/
22
repos:
33
- repo: https://github.com/PyCQA/flake8
44
rev: 7.0.0

frontend/.gitignore frontend/React/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
npm-debug.log*
1919
yarn-debug.log*
20-
yarn-error.log*
20+
yarn-error.log*

frontend/.prettierignore frontend/React/.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ values
44
node_modules
55
.gitignore
66
.prettierignore
7-
.husky
7+
.husky
File renamed without changes.

frontend/README.md frontend/React/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
## 开始
2+
23
### 准备node.js开发环境
4+
35
如需安装环境,可参照:https://nodejs.org/zh-cn/download/package-manager,从官网下载对应平台的安装程序并安装。
46

57
如环境已经准备好,跳转下一步
68

79
### 安装依赖
10+
811
npm install
912

1013
### 启动
14+
1115
npm start
1216

1317
启动成功后,界面将出现可访问的本地url
1418

1519
### 配置
20+
1621
#### 接口请求配置
22+
1723
- 如您需要配置的服务支持跨域,可至/src/config/cgi.ts中修改请求链接,请求链接为http://ip:port/path;
24+
1825
- 如您需要配置的服务不支持跨域,可至vite.config.ts中配置proxy,示例如下
1926

2027
```
@@ -30,4 +37,5 @@ npm start
3037
```
3138

3239
### 知悉
33-
- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/
40+
41+
- 前端服务基于react开发,如需了解react相关知识,可参考:https://react.dev/
File renamed without changes.
File renamed without changes.

frontend/package.json frontend/React/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@
4646
"lint-staged": {
4747
"**/*.{ts, tsx, less, module.less, json, md, .html}": "prettier --write ."
4848
}
49-
}
49+
}

frontend/src/App.module.less frontend/React/src/App.module.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
display: flex;
5252
align-items: center;
5353
}
54-
}
54+
}
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.

frontend/React/src/global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'event-source-polyfill';

frontend/src/index.less frontend/React/src/index.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ li> :nth-last-child(1).f {
5959
line-height: 14px;
6060
position: relative;
6161
top: -2px;
62-
}
62+
}
File renamed without changes.

frontend/src/pages/render/index.module.less frontend/React/src/pages/render/index.module.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,4 +845,4 @@ ul {
845845
transform: scale(1);
846846
opacity: 1;
847847
}
848-
}
848+
}

frontend/src/pages/render/index.tsx frontend/React/src/pages/render/index.tsx

+26-26
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const RenderTest = () => {
7979
}
8080

8181
if (node.children) {
82-
// 递归地在子节点中查找
82+
// 递归地在子节点中查找
8383
node.children = findAndUpdateStatus(node.children, targetNode);
8484
}
8585

@@ -88,20 +88,20 @@ const RenderTest = () => {
8888
}
8989

9090
const generateEndStyle = () => {
91-
// 获取所有class为endline的div元素
91+
// 获取所有class为endline的div元素
9292
const endlineDivs = document.getElementsByClassName('endline');
9393
const mindMap = document.getElementById("mindMap");
94-
// 确保至少有两个元素
94+
// 确保至少有两个元素
9595
if (endlineDivs.length >= 2 && mindMap) {
96-
// 获取第一个和最后一个元素的边界框(bounding rectangle)
96+
// 获取第一个和最后一个元素的边界框(bounding rectangle)
9797
const firstRect = endlineDivs[0].getBoundingClientRect();
9898
const lastRect = endlineDivs[endlineDivs.length - 1].getBoundingClientRect();
9999
const mindMapRect = mindMap?.getBoundingClientRect();
100-
// 计算y值的差值
100+
// 计算y值的差值
101101
const yDiff = lastRect.top - firstRect.top;
102102
// const top = firstRect.top - mindMapRect.top;
103-
// 如果需要包含元素的完整高度(不仅仅是顶部位置),可以加上元素的高度
104-
// const yDiffWithHeight = yDiff + (lastRect.height - firstRect.height);
103+
// 如果需要包含元素的完整高度(不仅仅是顶部位置),可以加上元素的高度
104+
// const yDiffWithHeight = yDiff + (lastRect.height - firstRect.height);
105105
return {
106106
top: firstRect.top - mindMapRect.top,
107107
height: yDiff + 1
@@ -116,7 +116,7 @@ const RenderTest = () => {
116116

117117
const generateWidth = () => {
118118
const articles = document.querySelectorAll('article');
119-
// 确保至少有两个元素
119+
// 确保至少有两个元素
120120
if (articles?.length) {
121121
let maxRight = 0;
122122
articles.forEach((item, index) => {
@@ -137,20 +137,20 @@ const RenderTest = () => {
137137

138138
// 逐字渲染
139139
const renderDraft = (str: string, type: string, endCallback: () => void) => {
140-
// 已经输出的字符数量
140+
// 已经输出的字符数量
141141
let outputIndex = 0;
142142

143-
// 输出字符的函数
143+
// 输出字符的函数
144144
const outputText = () => {
145145
// 给出高亮后draft输出的结束标志
146146
if (type === 'stepDraft-1' && outputIndex + 3 > str?.length) {
147147
nodeDraftRender.current = true;
148148
}
149-
// 如果还有字符未输出
149+
// 如果还有字符未输出
150150
if (outputIndex < str?.length) {
151-
// 获取接下来要输出的1个字符(或剩余字符,如果不足3个)
151+
// 获取接下来要输出的1个字符(或剩余字符,如果不足3个)
152152
let chunk = str.slice(outputIndex, Math.min(outputIndex + 10, str.length));
153-
// 更新已输出字符的索引
153+
// 更新已输出字符的索引
154154
outputIndex += chunk.length;
155155
if (type === 'thought') {
156156
setDraft(str.slice(0, outputIndex));
@@ -164,13 +164,13 @@ const RenderTest = () => {
164164
setResponse(str.slice(0, outputIndex));
165165
}
166166
} else {
167-
// 如果没有更多字符需要输出,则清除定时器
167+
// 如果没有更多字符需要输出,则清除定时器
168168
clearInterval(intervalId);
169169
endCallback && endCallback()
170170
}
171171
}
172172

173-
// 设定定时器ID
173+
// 设定定时器ID
174174
let intervalId = setInterval(outputText, TEXT_INTERVAL);
175175
}
176176

@@ -191,7 +191,7 @@ const RenderTest = () => {
191191
clearInterval(intervalId);
192192
}
193193
};
194-
// 设定定时器ID
194+
// 设定定时器ID
195195
let intervalId = setInterval(outputText, SEARCHLIST_INTERVAL);
196196
};
197197

@@ -210,16 +210,16 @@ const RenderTest = () => {
210210
if (item1.highLight === item2.highLight) {
211211
return 0;
212212
}
213-
// 如果item1是highlight,放在前面
213+
// 如果item1是highlight,放在前面
214214
if (item1.highLight) {
215215
return -1;
216216
}
217-
// 如果item2是highlight,放在后面
217+
// 如果item2是highlight,放在后面
218218
return 1;
219219
})
220220
setSearchList(highlightArr);
221221
renderDraft(currentNode.actions[1].thought, `stepDraft-1`, () => { });
222-
hasHighlight.current = true; // 标记为高亮已执行
222+
hasHighlight.current = true; // 标记为高亮已执行
223223
};
224224

225225
// 渲染结论
@@ -274,12 +274,12 @@ const RenderTest = () => {
274274

275275
// 渲染过程中保持渲染文字可见
276276
const keepScrollTop = (divA: any, divB: any) => {
277-
// 获取 divB 的当前高度
277+
// 获取 divB 的当前高度
278278
const bHeight = divB.offsetHeight;
279279

280-
// 检查 divA 是否需要滚动(即 divB 的高度是否大于 divA 的可视高度)
280+
// 检查 divA 是否需要滚动(即 divB 的高度是否大于 divA 的可视高度)
281281
if (bHeight > divA.offsetHeight) {
282-
// 滚动到 divB 的底部在 divA 的可视区域内
282+
// 滚动到 divB 的底部在 divA 的可视区域内
283283
divA.scrollTop = bHeight - divA.offsetHeight;
284284
}
285285
};
@@ -392,12 +392,12 @@ const RenderTest = () => {
392392
setShowEndNode(true);
393393
}, 300);
394394
} else if (responseTimer.current) {
395-
// 如果 isEnd 变为 false,清除定时器
395+
// 如果 isEnd 变为 false,清除定时器
396396
clearInterval(responseTimer.current);
397397
responseTimer.current = null;
398398
}
399399

400-
// 返回清理函数,确保组件卸载时清除定时器
400+
// 返回清理函数,确保组件卸载时清除定时器
401401
return () => {
402402
if (responseTimer.current) {
403403
clearInterval(responseTimer.current);
@@ -514,7 +514,7 @@ const RenderTest = () => {
514514

515515
const abortEventSource = () => {
516516
if (eventSource) {
517-
eventSource.close(); // 或使用其他方法关闭连接,具体取决于库的API
517+
eventSource.close(); // 或使用其他方法关闭连接,具体取决于库的API
518518
eventSource = null;
519519
console.log('EventSource connection aborted due to timeout.');
520520
message.error('连接中断,2s后即将刷新页面---');
@@ -678,4 +678,4 @@ const RenderTest = () => {
678678
</div>
679679
};
680680

681-
export default RenderTest;
681+
export default RenderTest;

frontend/src/pages/render/mindMapItem.tsx frontend/React/src/pages/render/mindMapItem.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import styles from './index.module.less';
22
import classNames from 'classnames';
33

4-
// 递归组件用于渲染mindMap中的节点
4+
// 递归组件用于渲染mindMap中的节点
55
const MindMapItem = ({ item, isEnd }: any) => {
6-
// 递归渲染子节点
6+
// 递归渲染子节点
77
const renderChildren = () => {
88
if (item.children && item.children.length > 0) {
99
return (
@@ -36,4 +36,4 @@ const MindMapItem = ({ item, isEnd }: any) => {
3636
);
3737
};
3838

39-
export default MindMapItem;
39+
export default MindMapItem;
File renamed without changes.

frontend/src/utils/tools.ts frontend/React/src/utils/tools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const isInWhiteList = (url: string = "", list: string[] = []) => {
1818

1919
export const replaceStr = (str: string) => {
2020
return str.replace(/\[\[(\d+)\]\]/g, (match: any, number: any) => {
21-
// 创建一个带有class为'fnn2'的span元素,并将数字作为文本内容
21+
// 创建一个带有class为'fnn2'的span元素,并将数字作为文本内容
2222
return `<i class='f'>${number}</i>`;
2323
});
24-
};
24+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.

frontend/src/global.d.ts

-1
This file was deleted.

src/agent/__init__.py mindsearch/agent/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
from lagent.actions import ActionExecutor, BingBrowser
55

6-
import src.agent.models as llm_factory
7-
from src.agent.mindsearch_agent import MindSearchAgent, MindSearchProtocol
8-
from src.agent.mindsearch_prompt import (
6+
import mindsearch.agent.models as llm_factory
7+
from mindsearch.agent.mindsearch_agent import (MindSearchAgent,
8+
MindSearchProtocol)
9+
from mindsearch.agent.mindsearch_prompt import (
910
FINAL_RESPONSE_CN, FINAL_RESPONSE_EN, GRAPH_PROMPT_CN, GRAPH_PROMPT_EN,
1011
searcher_context_template_cn, searcher_context_template_en,
1112
searcher_input_template_cn, searcher_input_template_en,
File renamed without changes.
File renamed without changes.
File renamed without changes.

app.py mindsearch/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pydantic import BaseModel
1212
from sse_starlette.sse import EventSourceResponse
1313

14-
from src.agent import init_agent
14+
from mindsearch.agent import init_agent
1515

1616
app = FastAPI(docs_url='/')
1717

0 commit comments

Comments
 (0)