首页 > 其他分享 >MindSearch 快速部署

MindSearch 快速部署

时间:2024-09-19 14:24:00浏览次数:1  
标签:MindSearch return gr 部署 agent mindsearch 快速 history

基础任务(完成此任务即完成闯关)

  • 按照教程,将 MindSearch 部署到 HuggingFace 并美化 Gradio 的界面,并提供截图和 Hugging Face 的Space的链接。

MindSearch 部署到Github Codespace 和 Hugging Face Space

原有的CPU版本相比区别是把internstudio换成了github codespace。

随着硅基流动提供了免费的 InternLM2.5-7B-Chat 服务(免费的 InternLM2.5-7B-Chat 真的很香),MindSearch 的部署与使用也就迎来了纯 CPU 版本,进一步降低了部署门槛。那就让我们来一起看看如何使用硅基流动的 API 来部署 MindSearch 吧。

1. 创建开发机 & 环境配置

打开codespace主页,选择blank template。

我一直打不开

我一直都打不开,所以直接用开发机了

浏览器会自动在新的页面打开一个web版的vscode。

接下来的操作就和我们使用vscode基本没差别了。

然后我们新建一个目录用于存放 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

2. 获取硅基流动 API Key

因为要使用硅基流动的 API Key,所以接下来便是注册并获取 API Key 了。

首先,我们打开 https://account.siliconflow.cn/login 来注册硅基流动的账号(如果注册过,则直接登录即可)。

在完成注册后,打开 https://cloud.siliconflow.cn/account/ak 来准备 API Key。首先创建新 API 密钥,然后点击密钥进行复制,以备后续使用。

3. 启动 MindSearch

3.1 启动后端

由于硅基流动 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

问题

3.2 启动前端

在后端启动完成后,我们打开新终端运行如下命令来启动 MindSearch 的前端。

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

前后端都启动后,我们应该可以看到github自动为这两个进程做端口转发。

由于使用codespace,这里我们不需要使用ssh端口转发了,github会自动提示我们打开一个在公网的前端地址。

然后就可以即刻体验啦。

如果遇到了 timeout 的问题,可以按照 文档 换用 Bing 的搜索接口。

4. 部署到 HuggingFace Space

最后,我们来将 MindSearch 部署到 HuggingFace Space。

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

在输入 Space name 并选择 License 后,选择配置如下所示。

然后,我们进入 Settings,配置硅基流动的 API Key。如下图所示。

选择 New secrets,name 一栏输入 SILICON_API_KEY,value 一栏输入你的 API Key 的内容。

最后,我们先新建一个目录,准备提交到 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 os

import gradio as gr
import requests
from lagent.schema import AgentStatusCode

os.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_searcher


def 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: E501
    elif 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, ''])
    return


def 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':
                    continue
                if decoded[:6] == 'data: ':
                    decoded = decoded[6:]
                elif decoded.startswith(': ping - '):
                    continue
                response = json.loads(decoded)
                yield (response['response'], response['current_node'])

    global PLANNER_HISTORY
    PLANNER_HISTORY.append(dict(role='user', content=history_planner[-1][0]))
    new_search_turn = True

    url = '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 = resp
        if node_name:
            if node_name in ['root', 'response']:
                continue
            agent_return = agent_return['nodes'][node_name]['detail']
            if new_search_turn:
                history_searcher.append([agent_return['content'], ''])
                new_search_turn = False
            format_response(history_searcher, agent_return)
            if agent_return['state'] == AgentStatusCode.END:
                new_search_turn = True
            yield history_planner, history_searcher
        else:
            new_search_turn = True
            format_response(history_planner, agent_return)
            if agent_return['state'] == AgentStatusCode.END:
                PLANNER_HISTORY = agent_return['inner_steps']
            yield history_planner, history_searcher
    return history_planner, history_searcher


with 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;">

标签:MindSearch,return,gr,部署,agent,mindsearch,快速,history
From: https://www.cnblogs.com/ztyniubi/p/18420523

相关文章

  • QDUOJ手动部署心得
    手动QDUOJ部署[更推荐官网一键部署,手动有失败率,但是能更深入理解部署过程]目录★标记的部分很重要一、需求环境Docker,Docker-compose,python=3.8[推荐]#查看版本docker-vdocker-compose-v环境配置[Ubuntu20.04,不推荐22原因:前端很多前置包22不支持]:#1.docker安装#......
  • 阿里云服务器手动部署LNMP环境(Alibaba Cloud Linux 3/2、CentOS 7/8)
    LNMP是目前主流的网站服务器架构之一,适合运行大型和高并发的网站应用,例如电子商务网站、社交网络、内容管理系统等。LNMP分别代表Linux、Nginx、MySQL和PHP。本文介绍如何在AlibabaCloudLinux3/2、CentOS7/8操作系统的ECS实例上搭建LNMP环境。部署环境的实例要求手动部署LNMP环......
  • 快速创建一台阿里云服务器并远程连接!
    云服务器ECS(ElasticComputeService)是阿里云提供的性能卓越、稳定可靠、弹性扩展的IaaS(InfrastructureasaService)级别云计算服务。云服务器ECS免去了您采购IT硬件的前期准备,让您像使用水、电、天然气等公共资源一样便捷、高效地使用服务器,实现计算资源的即开即用和弹性伸缩。阿......
  • 快速比较两个数据库所有表的字段是否一致
    背景在开发时,常常会有开发环境,测试环境,生产环境。当开发环境中的数据库结构发生变化时,往往需要同步到测试环境和生产环境,但是有时候会忘记同步了。那么,如何快速判断两个数据库的所有表字段是否一致呢?需要工具:navicat(或类似数据库工具),BeyondComapre(或类似文本比较工具)。导出数......
  • 南大通用GBase 8s 高可用性集群搭建部署指南(上)
    在企业级应用中,数据库的稳定性和可用性是至关重要的。GBase8s作为一款高性能的国产数据库系统,提供了HAC(高可用性集群)功能,确保业务连续性和数据安全性。本篇将详细介绍如何在主节点和辅节点上安装并配置GBase8s,为搭建HAC集群打下坚实基础。1、安装GBase8s数据库首先,我们需要分别......
  • 南大通用GBase 8s 高可用集群搭建部署指南(下)
    在上篇文章中,我们完成了GBase8sHAC集群搭建的初步配置。本文将重点介绍如何配置主节点和辅节点之间的互信关系,以及如何搭建并验证HAC集群的状态。1、配置互信互信是集群节点间通信的基础。我们可以通过配置.rhosts文件或使用REMOTE_SERVER_CFG参数两种方式来实现互信。根据企业的......
  • 新程序码山侠泛程序 快速收录
    ‌‌快速收录蜘蛛池的定义‌‌‌快速收录蜘蛛池‌是一种基于高效算法的技术手段,旨在使网页在发布后能够迅速被‌搜索引擎的爬虫检索到并收录,实现秒级曝光。这种技术通过智能化的爬虫程序和强大的数据处理能力,提高了网页的收录速度和效率。打开码山侠i5i.net‌快速收录蜘蛛......
  • 即时通讯框架MobileIMSDK的H5端开发快速入门
    ► 相关链接:① MobileIMSDK-H5端的详细介绍② MobileIMSDK-H5端的开发手册new(* 精编PDF版)一、技术准备您是否已对Web端即时通讯技术有所了解?1)新手入门贴:史上最全Web端即时通讯技术原理详解2)Web端即时通讯技术盘点:短轮询、Comet、Websocket、SSE您需要对WebSocket技......
  • 【Gateway 快速入门】
    Gateway快速入门要求:通过浏览器访问api网关,然后通过网关将请求转发到商品微服务基础版第1步:创建一个api-gateway的模块,导入相关依赖<dependencies><!--gateway网关--><dependency><groupId>org.springframework.cloud</groupId>......
  • 一件部署安装百度开源数字人项目Hallo!图片视频!效果炸裂!含整合包!开源免费使用阿里蚂蚁
    一件部署安装百度开源数字人项目Hallo!图片视频!效果炸裂!含整合包!开源免费使用阿里蚂蚁集团推出的EchoMimic开源项目:为唱歌和对话提供支持的AI数字人技术(附代码)。近日,AI领域迎来了一个重磅消息——百度联合复旦大学、苏黎世联邦理工学院和南京大学共同推出一个开源项目,名为"Hallo"。......