From 55de16374b0a3780a4e4347466747a3e32e61d7c Mon Sep 17 00:00:00 2001 From: liukuikun <24622904+Harold-lkk@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:23:40 +0800 Subject: [PATCH] enchance app.py (#9) --- README.md | 21 ++++++++++++++++++--- README_zh-CN.md | 18 +++++++++++++++--- frontend/React/src/config/cgi.ts | 2 +- frontend/React/src/pages/render/index.tsx | 2 +- mindsearch/agent/__init__.py | 6 ++++-- mindsearch/agent/mindsearch_agent.py | 2 +- mindsearch/app.py | 15 ++++++++++++++- 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 231734e..2ce8102 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,15 @@ 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: @@ -61,6 +67,15 @@ 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 @@ -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}, } ``` diff --git a/README_zh-CN.md b/README_zh-CN.md index b9ac647..b8b658e 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -51,9 +51,15 @@ 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 前端 提供以下几种前端界面: @@ -61,6 +67,12 @@ python -m mindsearch.app - 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 @@ -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}, } ``` diff --git a/frontend/React/src/config/cgi.ts b/frontend/React/src/config/cgi.ts index fe7ba7f..5fa5395 100644 --- a/frontend/React/src/config/cgi.ts +++ b/frontend/React/src/config/cgi.ts @@ -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'; diff --git a/frontend/React/src/pages/render/index.tsx b/frontend/React/src/pages/render/index.tsx index 515b648..d37bbe0 100644 --- a/frontend/React/src/pages/render/index.tsx +++ b/frontend/React/src/pages/render/index.tsx @@ -579,7 +579,7 @@ const RenderTest = () => { 发送 -
如果想要更丝滑的体验,请在本地搭建-Lagent
+
如果想要更丝滑的体验,请在本地搭建-MindSearch
{showRight &&
{ diff --git a/mindsearch/agent/__init__.py b/mindsearch/agent/__init__.py index 753f999..da95594 100644 --- a/mindsearch/agent/__init__.py +++ b/mindsearch/agent/__init__.py @@ -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 @@ -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.'), diff --git a/mindsearch/agent/mindsearch_agent.py b/mindsearch/agent/mindsearch_agent.py index c0f2ad3..957da44 100644 --- a/mindsearch/agent/mindsearch_agent.py +++ b/mindsearch/agent/mindsearch_agent.py @@ -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 diff --git a/mindsearch/app.py b/mindsearch/app.py index 8483a75..ede1dcc 100644 --- a/mindsearch/app.py +++ b/mindsearch/app.py @@ -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, @@ -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())