MindSearch 部署到Github Codespace 和 Hugging Face Space

        一:概述

                MindSearch是一个创新的AI搜索框架,由中国科技大学的科学家以及上海人工智能实验室的学者联合研发。

        

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

        二:部署实践

                <1>创建开发机 & 环境配置

                                打开codespace主页icon-default.png?t=O83Ahttps://github.com/codespaces,选择blank template。

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

        

        注意如果第一次使用这个codespace,在创建好环境之后,激活你创建的环境之前需要进行conda的初始化。

conda init

        <2>获取硅基流动 API Key

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

                首先,我们打开 硅基流动统一登录硅基流动统一登录 硅基流动用户系统,统一登录 SSOicon-default.png?t=O83Ahttps://account.siliconflow.cn/login 来注册硅基流动的账号(如果注册过,则直接登录即可)。

        在完成注册后,打开 硅基流动统一登录硅基流动统一登录 硅基流动用户系统,统一登录 SSOicon-default.png?t=O83Ahttps://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 的问题,可以按照 文档icon-default.png?t=O83Ahttps://github.com/InternLM/Tutorial/blob/camp3/docs/L2/MindSearch/readme_gpu.md#2-%E4%BD%BF%E7%94%A8-bing-%E7%9A%84%E6%8E%A5%E5%8F%A3         换用 Bing 的搜索接口。

               <4>部署到 HuggingFace Space

        我们首先打开 https://huggingface.co/spacesicon-default.png?t=O83Ahttps://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 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把空的代码仓库克隆到codespace。

/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

        记住一定要在requiremens里面添加一个下面所示依赖class_registry,要不然累死你你也跑不出来。

duckduckgo_search==5.3.1b1
einops
fastapi
class_registry
git+https://github.com/InternLM/lagent.git
gradio
janus
lmdeploy
pyvis
sse-starlette
termcolor
transformers==4.41.0
uvicorn

        经过漫长的部署,最后终于完成。接下来问几个问题看看效果吧!询问几个问题!

                

        

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

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

相关文章

Spring Cloud之OpenFeign的具体实践

1 基本概念 OpenFeign基于Feign框架开发&#xff0c;而Feign是Netflix开源的一个声明式Web服务客户端。OpenFeign通过定义接口、注解和动态代理等方式&#xff0c;将服务调用的过程封装起来&#xff0c;使得开发者只需要定义服务接口&#xff0c;而无需关心底层的HTTP请求和序列…

1688商品详情关键词数据-API

要利用 Python 爬虫采集 1688 商品详情数据&#xff0c;需要先了解 1688 网站的页面结构和数据请求方式。一般使用 requests 库请求网站的数据&#xff0c;使用 BeautifulSoup 库解析网页中的数据。 以下是一个简单的 Python 爬虫采集 1688 商品详情数据的示例代码&#xff1a…

YOLO11改进|注意力机制篇|引入上下文锚注意力机制CAA

目录 一、【CAA】注意力机制1.1【CAA】注意力介绍1.2【CAA】核心代码 二、添加【CAA】注意力机制2.1STEP12.2STEP22.3STEP32.4STEP4 三、yaml文件与运行3.1yaml文件3.2运行成功截图 一、【CAA】注意力机制 1.1【CAA】注意力介绍 CAA注意力机制的结构图如下&#xff0c;下面根据…

RAG:检索增强生成技术概览

Why 将大模型应用于实际业务场景时会发现&#xff0c;通用的基础大模型基本无法满足我们的实际业务需求&#xff0c;主要有以下几方面原因&#xff1a; 知识的局限性&#xff1a;大模型对于一些实时性的、非公开的或离线的数据是无法获取到的。幻觉问题&#xff1a;所有的AI模…

828华为云征文 | 利用FIO工具测试Flexus云服务器X实例存储性能

目录 一、Flexus云服务器X实例概要 1.1 Flexus云服务器X实例摘要 1.2 产品特点 1.3 存储方面性能 1.4 测评服务器规格 二、FIO工具 2.1 安装部署FIO 2.2 主要性能指标概要 三、进行压测 3.1 测试全盘随机读IO延迟 3.2 测试全盘随机写IO延迟 3.3 测试随机读IOPS 3.4…

R包:ggheatmap热图

加载R包 # devtools::install_github("XiaoLuo-boy/ggheatmap")library(ggheatmap) library(tidyr)数据 set.seed(123) df <- matrix(runif(225,0,10),ncol 15) colnames(df) <- paste("sample",1:15,sep "") rownames(df) <- sapp…

云中红队系列 | 使用 Azure FrontDoor 混淆 C2 基础设施

重定向器是充当 C2 服务器和目标网络之间中间人的服务器。其主要功能是重定向 C2 和受感染目标之间的所有通信。重定向器通常用于隐藏 C2 服务器流量的来源&#xff0c;使防御者更难以检测和阻止 C2 基础设施。 基于云的重定向器提供了一个很好的机会&#xff0c;通过内容分发…

安卓使用memtester进行内存压力测试

memteser简介 memtester 是一个用于测试内存可靠性的工具。 它可以对计算机的内存进行压力测试&#xff0c;以检测内存中的错误&#xff0c;例如位翻转、随机存取错误等。memtester 可以在不同的操作系统上运行&#xff0c;并且可以针对不同大小的内存进行测试。 下载源码 m…

[单master节点k8s部署]29.Istio流量管理(五)

测试istio熔断管理。 采用httpbin镜像和fortio镜像&#xff0c;其中httpbin作为服务端&#xff0c;fortio是请求端。这两个的配置yaml文件都在istio的samples/httpbin目录下&#xff0c;fortio的配置文件在samples-client目录下。 [rootmaster httpbin]# ls gateway-api ht…

国外电商系统开发-运维系统执行设备属性

为了方便使用&#xff0c;开发了双击网络设备图标&#xff0c;就进入交互式命令终端&#xff0c;在这里您可以执行如cd&#xff0c;top&#xff0c;ping这样的交互命令&#xff0c;但仍然不支持部分交互命令&#xff0c;比如vim等。 您可以双击设备图标&#xff0c;或者是右键&…

如何从计算机的硬盘中恢复照片 - 成功

如何从计算机硬盘恢复图片&#xff1f; 与所有电子和机械设备一样&#xff0c;硬盘驱动器也可能由于任何原因而死机。如果您的系统硬盘驱动器已停止工作或在启动系统时听到振动声&#xff0c;则它有可能已死机。如果是这样的话&#xff0c;上面的数据呢&#xff1f; 不要惊慌…

Python使用matplotlib绘制图形大全(曲线图、条形图、饼图等)

matplotlib 的主要组成部分是 pyplot&#xff0c;它是一个类似于 MATLAB 的绘图框架。pyplot 提供了一个 MATLAB 式的接口&#xff0c;可以隐式地创建图形和轴&#xff0c;使得绘图变得简单。 以下是一个简单的 matplotlib 使用示例&#xff0c;用于绘制一条简单的折线图&…

高考选择在何方?揭秘空军、海军、民航三大招飞神秘机遇

空军招飞、海军招飞和民航招飞在全国普通高校招生体系中举足轻重&#xff0c;为国家培育众多优秀飞行人才。 空军招飞在国家多部门领导下&#xff0c;由空军与相关省&#xff08;区&#xff09;教育、公安部门组织实施&#xff0c;设有七个招飞中心。自 1987 年空军自主招飞以来…

28 基于51单片机的两路电压检测(ADC0808)

目录 一、主要功能 二、硬件资源 三、程序编程 四、实现现象 一、主要功能 基于51单片机&#xff0c;通过ADC0808获取两路电压&#xff0c;通过LCD1602显示 二、硬件资源 基于KEIL5编写C代码&#xff0c;PROTEUS8.15进行仿真&#xff0c;全部资源在页尾&#xff0c;提供…

springboot中配置优先级

先来看在idea当中运行程序时&#xff0c;如何来指定Java系统属性和命令行参数。 系统属性 1、右键启动类&#xff0c;点击Edit Configuration 点击Modify options 选择Add VM options&#xff0c;就是系统属性 选择Program arguements&#xff0c;就是命令行参数 总结&#…

OpenAI 开发者大会!实时语音功能有API了,GPT-4o支持多模态微调,上下文cache功能上线

家人们&#xff01;十一假期第1天&#xff0c; OpenAI一年一度的开发者大会又来了惹&#xff01;今年的开发者大会分成三部分分别在美国、英国、新加坡三个地点举办&#xff0c;刚刚结束的是第一场。 去年的OpenAI开发者大会公布了GPT-4 Turbo和GPTs&#xff0c;今年没有大更新…

win10不想被强制更新win11怎么办?

还有一种办法是可以去联想官网下载一个工具&#xff0c;确实可行但是不能访问联想商店了&#xff0c;不过会限制一些微软游戏&#xff0c;比如我喜欢的腐烂国度2&#xff0c;所以我选择了这一种方式&#xff0c;亲测可行

外贸网站怎么搭建对谷歌seo比较好?

外贸网站怎么搭建对谷歌seo比较好&#xff1f;搭建一个网站自然不复杂&#xff0c;但要想搭建一个符合谷歌seo规范的网站&#xff0c;那就要多注意了&#xff0c;你的网站做的再酷炫&#xff0c;再花里胡哨&#xff0c;但如果页面都是js代码&#xff0c;或者页面没有源代码内容…

认识动态规划算法和实践(java)

前言 动态规划算法里面最有意思的一个东西之一。动态规划初学肯定会有一定晦涩难懂。如果我们去网上搜索&#xff0c;动态规划的资料&#xff0c;它一开始都是将很多的理论&#xff0c;导致会认为很难&#xff0c;但是这个东西实际上是有套路的。 动态规划的英语是Dynamic Pr…

Centos Stream 9备份与恢复、实体小主机安装PVE系统、PVE安装Centos Stream 9

最近折腾小主机&#xff0c;搭建项目环境&#xff0c;记录相关步骤 数据无价&#xff0c;丢失难复 1. Centos Stream 9备份与恢复 1.1 系统备份 root权限用户执行进入根目录&#xff1a; cd /第一种方式备份命令&#xff1a; tar cvpzf backup.tgz / --exclude/proc --exclu…