书生.浦江大模型实战训练营——(十四)MindSearch 快速部署

本文主要是介绍书生.浦江大模型实战训练营——(十四)MindSearch 快速部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

最近在学习书生.浦江大模型实战训练营,所有课程都免费,以关卡的形式学习,也比较有意思,提供免费的算力实战,真的很不错(无广)!欢迎大家一起学习,打开LLM探索大门:邀请连接,PS,邀请有算力哈哈
在这里插入图片描述

文章目录

  • 一、创建开发机 & 环境配置
  • 二、获取硅基流动 API Key
  • 三、启动 MindSearch
  • 四、部署到 HuggingFace Space

一、创建开发机 & 环境配置

打开codespace主页,选择blank template。
在这里插入图片描述
新建一个目录用于存放 MindSearch 的相关代码,并把 MindSearch 仓库 clone 下来。在终端中运行下面的命令:

mkdir -p /workspaces/mindsearch
cd /workspaces/mindsearch
git clone https://github.com/InternLM/MindSearch.git
cd MindSearch && git checkout b832275 && cd ..

接下来,创建一个 conda 环境来安装相关依赖。

# 创建环境
conda create -n mindsearch python=3.10 -y
# 激活环境
conda activate mindsearch
# 安装依赖
pip install -r /workspaces/mindsearch/MindSearch/requirements.txt

二、获取硅基流动 API Key

首先,我们打开https://account.siliconflow.cn/login 来注册硅基流动的账号。在完成注册后,打开 https://cloud.siliconflow.cn/account/ak 来准备 API Key。首先创建新 API 密钥,然后点击密钥进行复制,以备后续使用。
在这里插入图片描述

三、启动 MindSearch

可以直接执行下面的代码来启动 MindSearch 的后端:

export SILICON_API_KEY=第二步中复制的密钥
conda activate mindsearch
cd /workspaces/mindsearch/MindSearch
python -m mindsearch.app --lang cn --model_format internlm_silicon --search_engine DuckDuckGoSearch

打开新终端运行如下命令来启动 MindSearch 的前端:

conda activate mindsearch
cd /workspaces/mindsearch/MindSearch
python frontend/mindsearch_gradio.py

可以看到github自动为这两个进程做端口转发。
在这里插入图片描述
在弹出的弹窗中打开窗口,即可体验。
在这里插入图片描述

四、部署到 HuggingFace Space

首先打开 https://huggingface.co/spaces ,并点击 Create new Space,如下图所示。

在这里插入图片描述

在输入 Space name 并选择 License 后,选择配置如下所示:
在这里插入图片描述

入 Settings,配置硅基流动的 API Key。如下图所示:
在这里插入图片描述
选择 New secrets,name 一栏输入 SILICON_API_KEY,value 一栏输入你的 API Key 的内容,点击save保存。
最后,新建一个目录,准备提交到 HuggingFace Space 的全部文件。

# 创建新目录
mkdir -p /workspaces/mindsearch/mindsearch_deploy
# 准备复制文件
cd /workspaces/mindsearch
cp -r /workspaces/mindsearch/MindSearch/mindsearch /workspaces/mindsearch/mindsearch_deploy
cp /workspaces/mindsearch/MindSearch/requirements.txt /workspaces/mindsearch/mindsearch_deploy
# 创建 app.py 作为程序入口
touch /workspaces/mindsearch/mindsearch_deploy/app.py

app.py 的内容如下:

import json
import osimport gradio as gr
import requests
from lagent.schema import AgentStatusCodeos.system("python -m mindsearch.app --lang cn --model_format internlm_silicon &")PLANNER_HISTORY = []
SEARCHER_HISTORY = []def rst_mem(history_planner: list, history_searcher: list):'''Reset the chatbot memory.'''history_planner = []history_searcher = []if PLANNER_HISTORY:PLANNER_HISTORY.clear()return history_planner, history_searcherdef format_response(gr_history, agent_return):if agent_return['state'] in [AgentStatusCode.STREAM_ING, AgentStatusCode.ANSWER_ING]:gr_history[-1][1] = agent_return['response']elif agent_return['state'] == AgentStatusCode.PLUGIN_START:thought = gr_history[-1][1].split('```')[0]if agent_return['response'].startswith('```'):gr_history[-1][1] = thought + '\n' + agent_return['response']elif agent_return['state'] == AgentStatusCode.PLUGIN_END:thought = gr_history[-1][1].split('```')[0]if isinstance(agent_return['response'], dict):gr_history[-1][1] = thought + '\n' + f'```json\n{json.dumps(agent_return["response"], ensure_ascii=False, indent=4)}\n```'  # noqa: E501elif agent_return['state'] == AgentStatusCode.PLUGIN_RETURN:assert agent_return['inner_steps'][-1]['role'] == 'environment'item = agent_return['inner_steps'][-1]gr_history.append([None,f"```json\n{json.dumps(item['content'], ensure_ascii=False, indent=4)}\n```"])gr_history.append([None, ''])returndef predict(history_planner, history_searcher):def streaming(raw_response):for chunk in raw_response.iter_lines(chunk_size=8192,decode_unicode=False,delimiter=b'\n'):if chunk:decoded = chunk.decode('utf-8')if decoded == '\r':continueif decoded[:6] == 'data: ':decoded = decoded[6:]elif decoded.startswith(': ping - '):continueresponse = json.loads(decoded)yield (response['response'], response['current_node'])global PLANNER_HISTORYPLANNER_HISTORY.append(dict(role='user', content=history_planner[-1][0]))new_search_turn = Trueurl = 'http://localhost:8002/solve'headers = {'Content-Type': 'application/json'}data = {'inputs': PLANNER_HISTORY}raw_response = requests.post(url,headers=headers,data=json.dumps(data),timeout=20,stream=True)for resp in streaming(raw_response):agent_return, node_name = respif node_name:if node_name in ['root', 'response']:continueagent_return = agent_return['nodes'][node_name]['detail']if new_search_turn:history_searcher.append([agent_return['content'], ''])new_search_turn = Falseformat_response(history_searcher, agent_return)if agent_return['state'] == AgentStatusCode.END:new_search_turn = Trueyield history_planner, history_searcherelse:new_search_turn = Trueformat_response(history_planner, agent_return)if agent_return['state'] == AgentStatusCode.END:PLANNER_HISTORY = agent_return['inner_steps']yield history_planner, history_searcherreturn history_planner, history_searcherwith gr.Blocks() as demo:gr.HTML("""<h1 align="center">MindSearch Gradio Demo</h1>""")gr.HTML("""<p style="text-align: center; font-family: Arial, sans-serif;">MindSearch is an open-source AI Search Engine Framework with Perplexity.ai Pro performance. You can deploy your own Perplexity.ai-style search engine using either closed-source LLMs (GPT, Claude) or open-source LLMs (InternLM2.5-7b-chat).</p>""")gr.HTML("""<div style="text-align: center; font-size: 16px;"><a href="https://github.com/InternLM/MindSearch" style="margin-right: 15px; text-decoration: none; color: #4A90E2;">🔗 GitHub</a><a href="https://arxiv.org/abs/2407.20183" style="margin-right: 15px; text-decoration: none; color: #4A90E2;">📄 Arxiv</a><a href="https://huggingface.co/papers/2407.20183" style="margin-right: 15px; text-decoration: none; color: #4A90E2;">📚 Hugging Face Papers</a><a href="https://huggingface.co/spaces/internlm/MindSearch" style="text-decoration: none; color: #4A90E2;">🤗 Hugging Face Demo</a></div>""")with gr.Row():with gr.Column(scale=10):with gr.Row():with gr.Column():planner = gr.Chatbot(label='planner',height=700,show_label=True,show_copy_button=True,bubble_full_width=False,render_markdown=True)with gr.Column():searcher = gr.Chatbot(label='searcher',height=700,show_label=True,show_copy_button=True,bubble_full_width=False,render_markdown=True)with gr.Row():user_input = gr.Textbox(show_label=False,placeholder='帮我搜索一下 InternLM 开源体系',lines=5,container=False)with gr.Row():with gr.Column(scale=2):submitBtn = gr.Button('Submit')with gr.Column(scale=1, min_width=20):emptyBtn = gr.Button('Clear History')def user(query, history):return '', history + [[query, '']]submitBtn.click(user, [user_input, planner], [user_input, planner],queue=False).then(predict, [planner, searcher],[planner, searcher])emptyBtn.click(rst_mem, [planner, searcher], [planner, searcher],queue=False)demo.queue()
demo.launch(server_name='0.0.0.0',server_port=7860,inbrowser=True,share=True)

最后,将 /root/mindsearch/mindsearch_deploy 目录下的文件(使用 git)提交到 HuggingFace Space 即可完成部署了。将代码提交到huggingface space的流程如下:首先创建一个有写权限的token。
在这里插入图片描述
然后从huggingface把空的代码仓库clone到codespace。

cd /workspaces/codespaces-blank
git clone https://huggingface.co/spaces/<你的名字>/<仓库名称>
# 把token挂到仓库上,让自己有写权限
git remote set-url space https://<你的名字>:<上面创建的token>@huggingface.co/spaces/<你的名字>/<仓库名称>

在这里插入图片描述
现在codespace就是本地仓库,huggingface space是远程仓库,接下来使用方法就和常规的git一样了。

cd <仓库名称>
# 把刚才准备的文件都copy进来
cp /workspaces/mindsearch/mindsearch_deploy/* .

这是最终目录:
在这里插入图片描述
最后把代码提交到huggingface space会自动启动项目:

git add .
git commit -m "update"
git push

支持在线访问:MindSearch Gradio Demo,下面进行测试:
在这里插入图片描述
至此,MindSearch 快速部署完成!

这篇关于书生.浦江大模型实战训练营——(十四)MindSearch 快速部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1112199

相关文章

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

Spring AI Alibaba接入大模型时的依赖问题小结

《SpringAIAlibaba接入大模型时的依赖问题小结》文章介绍了如何在pom.xml文件中配置SpringAIAlibaba依赖,并提供了一个示例pom.xml文件,同时,建议将Maven仓... 目录(一)pom.XML文件:(二)application.yml配置文件(一)pom.xml文件:首

nginx部署https网站的实现步骤(亲测)

《nginx部署https网站的实现步骤(亲测)》本文详细介绍了使用Nginx在保持与http服务兼容的情况下部署HTTPS,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录步骤 1:安装 Nginx步骤 2:获取 SSL 证书步骤 3:手动配置 Nginx步骤 4:测

在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程

《在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程》本文介绍了在Java中使用ModelMapper库简化Shapefile属性转JavaBean的过程,对比... 目录前言一、原始的处理办法1、使用Set方法来转换2、使用构造方法转换二、基于ModelMapper

Tomcat高效部署与性能优化方式

《Tomcat高效部署与性能优化方式》本文介绍了如何高效部署Tomcat并进行性能优化,以确保Web应用的稳定运行和高效响应,高效部署包括环境准备、安装Tomcat、配置Tomcat、部署应用和启动T... 目录Tomcat高效部署与性能优化一、引言二、Tomcat高效部署三、Tomcat性能优化总结Tom

Java实战之自助进行多张图片合成拼接

《Java实战之自助进行多张图片合成拼接》在当今数字化时代,图像处理技术在各个领域都发挥着至关重要的作用,本文为大家详细介绍了如何使用Java实现多张图片合成拼接,需要的可以了解下... 目录前言一、图片合成需求描述二、图片合成设计与实现1、编程语言2、基础数据准备3、图片合成流程4、图片合成实现三、总结前

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

本地私有化部署DeepSeek模型的详细教程

《本地私有化部署DeepSeek模型的详细教程》DeepSeek模型是一种强大的语言模型,本地私有化部署可以让用户在自己的环境中安全、高效地使用该模型,避免数据传输到外部带来的安全风险,同时也能根据自... 目录一、引言二、环境准备(一)硬件要求(二)软件要求(三)创建虚拟环境三、安装依赖库四、获取 Dee