Skip to content

Commit

Permalink
enchance app.py (InternLM#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harold-lkk authored Jul 30, 2024
1 parent d26875b commit 55de163
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,31 @@ pip install -r requirements.txt
Setup FastAPI Server.

```bash
python -m mindsearch.app
python -m mindsearch.app --lang en --model_format internlm_server
```

- `--lang`: language of the model, `en` for English and `zh` for Chinese.
- `--model_format`: format of the model.
`internlm_server` for InternLM2.5-7b-chat with local server.
`gpt4` for GPT4.
if you want to use other models, please modify [models](mindsearch\agent\models.py)

### Setup MindSearch Frontend

Providing following frontend interfaces:

- React

```bash
# Install Node.js and npm
# for Ubuntu
sudo apt install nodejs npm

# for windows
# download from https://nodejs.org/zh-cn/download/prebuilt-installer

# Install dependencies

cd frontend/React
npm install
npm start
Expand Down Expand Up @@ -94,12 +109,12 @@ If you find this project useful in your research, please consider cite:

```
@misc{chen2024mindsearchmimickinghumanminds,
title={MindSearch: Mimicking Human Minds Elicits Deep AI Searcher},
title={MindSearch: Mimicking Human Minds Elicits Deep AI Searcher},
author={Zehui Chen and Kuikun Liu and Qiuchen Wang and Jiangning Liu and Wenwei Zhang and Kai Chen and Feng Zhao},
year={2024},
eprint={2407.20183},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2407.20183},
url={https://arxiv.org/abs/2407.20183},
}
```
18 changes: 15 additions & 3 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,28 @@ pip install -r requirements.txt
启动 FastAPI 服务器

```bash
python -m mindsearch.app
python -m mindsearch.app --lang en --model_format internlm_server
```

- `--lang`: 模型的语言,`en` 为英语,`zh` 为中文。
- `--model_format`: 模型的格式。
`internlm_server` 为 InternLM2.5-7b-chat 本地服务器。
`gpt4` 为 GPT4。
如果您想使用其他模型,请修改 [models](mindsearch\agent\models.py)

### 启动 MindSearch 前端

提供以下几种前端界面:

- React

```bash
# 安装 Node.js 和 npm
# 对于 Ubuntu
sudo apt install nodejs npm
# 对于 Windows
# 从 https://nodejs.org/zh-cn/download/prebuilt-installer 下载

cd frontend/React
npm install
npm start
Expand Down Expand Up @@ -94,12 +106,12 @@ python mindsearch/terminal.py

```
@misc{chen2024mindsearchmimickinghumanminds,
title={MindSearch: Mimicking Human Minds Elicits Deep AI Searcher},
title={MindSearch: Mimicking Human Minds Elicits Deep AI Searcher},
author={Zehui Chen and Kuikun Liu and Qiuchen Wang and Jiangning Liu and Wenwei Zhang and Kai Chen and Feng Zhao},
year={2024},
eprint={2407.20183},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2407.20183},
url={https://arxiv.org/abs/2407.20183},
}
```
2 changes: 1 addition & 1 deletion frontend/React/src/config/cgi.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const mode = import.meta.env.MODE;
export const GET_SSE_DATA = '/solve';
export const GET_SSE_DATA = 'http://127.0.0.1:8002/solve';
2 changes: 1 addition & 1 deletion frontend/React/src/pages/render/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ const RenderTest = () => {
发送
</button>
</div>
<div className={styles.notice}>如果想要更丝滑的体验,请在本地搭建-<a href='https://github.com/InternLM/lagent' target='_blank'>Lagent <IconFont type='icon-GithubFilled' /></a></div>
<div className={styles.notice}>如果想要更丝滑的体验,请在本地搭建-<a href='https://github.com/InternLM/MindSearch' target='_blank'>MindSearch <IconFont type='icon-GithubFilled' /></a></div>
</div>
{showRight && <div className={styles.progressContent}>
{
Expand Down
6 changes: 4 additions & 2 deletions mindsearch/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def init_agent(lang='cn', model_format='internlm_server'):
llm_cfg = getattr(llm_factory, model_format)
if llm_cfg is None:
raise NotImplementedError
llm_cfg = llm_cfg.copy()
llm = llm_cfg.pop('type')(**llm_cfg)
LLM[model_format] = llm

Expand All @@ -35,9 +36,10 @@ def init_agent(lang='cn', model_format='internlm_server'):
searcher_cfg=dict(
llm=llm,
plugin_executor=ActionExecutor(
BingBrowser(topk=6,
BingBrowser(searcher_type='DuckDuckGoSearch',
topk=6,
api_key=os.environ.get('BING_API_KEY',
'YOUR_BING_API'))),
'YOUR BING API'))),
protocol=MindSearchProtocol(
meta_prompt=datetime.now().strftime(
'The current date is %Y-%m-%d.'),
Expand Down
2 changes: 1 addition & 1 deletion mindsearch/agent/mindsearch_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def __init__(self,
llm,
searcher_cfg,
protocol=MindSearchProtocol(),
max_turn=3):
max_turn=10):
self.local_dict = {}
self.ptr = 0
self.llm = llm
Expand Down
15 changes: 14 additions & 1 deletion mindsearch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

from mindsearch.agent import init_agent


def parse_arguments():
import argparse
parser = argparse.ArgumentParser(description='MindSearch API')
parser.add_argument('--lang', default='cn', type=str, help='Language')
parser.add_argument('--model_format',
default='internlm_server',
type=str,
help='Model format')
return parser.parse_args()


args = parse_arguments()
app = FastAPI(docs_url='/')

app.add_middleware(CORSMiddleware,
Expand Down Expand Up @@ -97,7 +110,7 @@ async def async_generator_wrapper():
# yield f'data: {response_json}\n\n'

inputs = request.inputs
agent = init_agent(**request.agent_cfg)
agent = init_agent(lang=args.lang, model_format=args.model_format)
return EventSourceResponse(generate())


Expand Down

0 comments on commit 55de163

Please sign in to comment.