书生浦语-MindSearch

news2024/9/21 14:04:40

1.目的

利用SiliconCloud提供的免费Intern2.5-7B-ChatAPI部署MindSearch

2.过程

2.1 在GitHub上打开codespace主页

我们首先在GitHub上打开codespace,选择blank template

在这里插入图片描述
然后打开一个Web端的vscode,将MindSearch进行clone

mkdir -p /workspaces/mindsearch
cd /workspaces/mindsearch
git clone https://github.com/InternLM/MindSearch.git
cd MindSearch && git checkout b832275 && cd ..
2.2 安装依赖
# 创建环境
conda create -n mindsearch python=3.10 -y
# 激活环境
conda activate mindsearch
# 安装依赖
pip install -r /workspaces/mindsearch/MindSearch/requirements.txt
2.3 获取SiliconFlow的Key

网址: https://cloud.siliconflow.cn/account/ak

2.4 启动后台MindSearch

SiliconFlow的key相关配置已经集成在了MindSearch中,直接python -m mindsearch.app 启动即可

export SILICON_API_KEY=第二步中复制的密钥
conda activate mindsearch
cd /workspaces/mindsearch/MindSearch
# -m:启动mindsearch模块下的app模块下的main方法
python -m mindsearch.app --lang cn --model_format internlm_silicon --search_engine DuckDuckGoSearch

在这里插入图片描述

2.5 启动MindSearch的前端
conda activate mindsearch
cd /workspaces/mindsearch/MindSearch
python frontend/mindsearch_gradio.py

在这里插入图片描述

2.6部署到hugging face

打开 https://huggingface.co/spaces ,然后创建自己的空间Space,选择完Gradio采用空模板后。在Settings中创建一个新的Secret并添加SiliconFlow的免费API Key。最后创建一个新目录,将原来MindSearch下的文件放在新目录下,并以app.py作为程序入口。

# 创建新目录
mkdir -p /root/mindsearch/mindsearch_deploy
# 准备复制文件
cd /root/mindsearch
cp -r /root/mindsearch/MindSearch/mindsearch /root/mindsearch/mindsearch_deploy
cp /root/mindsearch/MindSearch/requirements.txt /root/mindsearch/mindsearch_deploy
# 创建 app.py 作为程序入口
touch /root/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;">🔗 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)

在这里插入图片描述

在这里插入图片描述
链接: https://huggingface.co/spaces/Wuyuhang11/mindsearch

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2092427.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

二叉树详解(进阶)

目录 1. 二叉搜索树 1.1 基本概念 1.2 基本操作 1.3 性能分析 1.4 键值对 2. AVL树和红黑树 2.1 AVL树 2.2 红黑树 3. 红黑树模拟实现STL中的map与set 1. 二叉搜索树 1.1 基本概念 二叉搜索树&#xff08;BST&#xff0c;Binary Search Tree&#xff09;&#xff1a…

记录一次安装Studio卸载后再次安装反复打不开的问题

先说问题表现&#xff0c;低版本的安装后点击没反应&#xff0c;高版本的报错&#xff0c;如下图&#xff0c;反复卸载安装都没有用&#xff0c;网上也找了各种彻底卸载安卓Studio的方法也不行 Error occurred during initialization of VMagent library failed Agent OnLoad:…

【C++】unordered_set 容器的最全解析(什么是unordered_set?unordered_set的常用接口有那些?)

目录 一、前言 二、预备知识 &#x1f4a2;关联式容器&#x1f4a2; &#x1f4a2;键值对&#x1f4a2; &#x1f4a2;哈希结构的关联式容器&#x1f4a2; 三、unordered_set 详解 &#x1f525;unordered_set 的介绍 &#x1f525;unordered_set 的构造 &am…

解除 Excel 表格的文档保护全攻略

在日常工作和学习中&#xff0c;我们可能会遇到 Excel 表格被保护无法编辑的情况。别担心&#xff0c;今天就为大家分享几种解除 Excel 表格文档保护的方法。 一、导入腾讯文档 可以将受保护的 Excel 表格上传到腾讯文档。在部分情况下&#xff0c;腾讯文档会尝试自动解除表…

零基础国产GD32单片机编程入门(九)低功耗模式实战含源码

文章目录 一.概要二.GD32单片机低功耗基本介绍三.GD32单片机待机模式介绍四.待机低功耗例程实验五.工程源代码下载六.小结 一.概要 在生活中通过关掉用电器可以实现省电节能的目的&#xff0c;同样的道理单片机也可以通过这种方法实现降低功耗。单片机是由许多部件组成&#x…

ruoyi-vue-plus服务端打包报错的问题

对idea不熟&#xff0c;不知道在哪里输入打包命令&#xff0c;只会用手点击进行打包&#xff0c;然后就报错了 官方文档给的打包命令是 mvn clean package -D maven.test.skiptrue -P prod 从命令中可以看到跳过了maven测试&#xff0c;那么就要设置idea打包时跳过测试&…

k8s单master多node环境搭建-k8s版本低于1.24,容器运行时为docker

k8s 1.20.6单master多node环境搭建 1.环境规划2.初始化服务器1&#xff09;配置主机名2&#xff09;设置IP为静态IP3&#xff09;关闭selinux4&#xff09;配置主机hosts文件5&#xff09;配置三台主机之间免密登录6&#xff09;关闭交换分区swap&#xff0c;提升性能7&#xf…

【Python基础】字符串类型

本文收录于 《Python编程入门》专栏&#xff0c;从零基础开始&#xff0c;分享一些Python编程基础知识&#xff0c;欢迎关注&#xff0c;谢谢&#xff01; 文章目录 一、前言二、Python 字符串类型2.1 Python访问字符串中的值2.2 Python 转义字符2.3 Python 字符串运算符2.4 Py…

Bluetooth: gatt profile

Gatt 主要是描述了attribute的排列方式&#xff1b; Attribute caching 这个机制允许client只搜索一次server即可&#xff0c;当重连后不需要再搜索直接使用之前的。如果server的服务发生了变化&#xff0c;需要通过 service change indication 告诉client&#xff1b; client…

网优学习干货:2.6G仿真操作(2)

导入仿真区域图层 建立仿真站点组 设置仿真任务-结果图层和楼宇仿真高度 仿真结果统计-结果图层渲染 仿真结果统计-结果导出 目录 导入天线文件-导入方法与覆盖仿真相同&#xff0c;但天线文件需要包含PDSCH波束文件 将Beamforming天线添加到基站 如果在步骤④中没有找到Beamfo…

Web自动化测试实战--博客系统

&#x1f3a5; 个人主页&#xff1a;Dikz12&#x1f525;个人专栏&#xff1a;测试&#x1f4d5;格言&#xff1a;吾愚多不敏&#xff0c;而愿加学欢迎大家&#x1f44d;点赞✍评论⭐收藏 目录 1.项目效果展示 2.编写web测试用例 3.自动化测试脚本开发 3.1创建空项目 引…

构建大师:深入理解Linux下的Make和Makefile

引言 在软件开发的世界里&#xff0c;构建过程是一项繁琐而重要的任务。无论是简单的脚本还是复杂的软件项目&#xff0c;都需要一种方式来自动化编译、链接以及测试等过程。在Linux环境下&#xff0c;Make工具和它的配置文件——Makefile&#xff0c;成为了许多开发者构建项目…

计算机硬件的组成

目录 前言 计算机系统组成 计算机硬件的组成 1、控制器 2、运算器 3、主存储器 4、辅助存储器 5、输入设备 6、输出设备 最后 前言 计算机已成为不可或缺的工具。无论是个人电脑还是服务器集群&#xff0c;其背后都是由一系列硬件组件协同工作的结果。 本文讲介绍计…

ssrf攻击本地fastcgi漏洞复现

目录 环境&#xff1a;UbuntuNginxphp 代码 开始测试 查看 环境搭建 环境&#xff1a;UbuntuNginxphp 代码 <?php highlight_file(__FILE__); $url $_GET[url]; $curl curl_init($url);curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($curl, CURLOPT_HEADER, 0…

滚雪球学MyBatis-Plus(02):环境准备

环境准备 本地开发环境参考如下&#xff1a; 开发工具&#xff1a;IntelliJ IDEA 2021.3.2JDK版本&#xff1a; JDK 1.8Spring Boot版本&#xff1a;2.3.1.RELEASEMaven版本&#xff1a;Apache Maven 3.8.2MySQL&#xff1a;5.6 前言 在上期内容中&#xff0c;我们系统地介绍了…

【多线程】设计模式之单例模式

&#x1f490;个人主页&#xff1a;初晴~ &#x1f4da;相关专栏&#xff1a;多线程 / javaEE初阶 一、什么是设计模式 设计模式好⽐象棋中的 "棋谱". 红⽅当头炮, ⿊⽅⻢来跳. 针对红⽅的⼀些⾛法, ⿊⽅应招的时候有⼀些固定的套路. 按照套路来⾛局势就不会吃亏. …

【微服务】接口的幂等性怎么设计?

一、什么是幂等&#xff1f; 幂等性&#xff1a;短时间内&#xff0c;对于相同输入的请求&#xff0c;无论进行多少次重复操作&#xff0c;都应该和单次调用的结果一致。 二、幂等问题产生的原因是什么&#xff1f;(或者说为什么需要实现幂等性?) 1、前端重复提交 在用户注…

高频Postman接口测试面试题

一、Postman在工作中使用流程是什么样的&#xff1f; 新建集合管理根据接口所属的模块&#xff0c;在集合中不同模块下编写接口测试用例处理接口之间的数据关联操作添加环境变量在tests tab下中增加断言调试接口&#xff0c;确保接口能被正常调用批量运行用例或者导出通过Newm…

STM32H750VBT6烧录源码无反应的问题

当烧录后出现这种情况下&#xff0c;点击魔术棒里面 Linker,勾选第一个方框后再次烧录即可。

【机器学习】聚类算法的基本概念和实例代码以及局部度量学习的概念和实例代码

引言 聚类算法在许多领域都有广泛的应用&#xff0c;例如数据挖掘、生物信息学、图像处理等。 文章目录 引言一、聚类算法1.1 K-Means算法1.2 DBSCAN算法1.3 层次聚类&#xff08;Hierarchical Clustering&#xff09;算法1.4 高斯混合模型&#xff08;Gaussian Mixture Model&…