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…

KEYENCE Programming Contest 2024(AtCoder Beginner Contest 374) 题解

A - Takahashi san 2 Problem Statement KEYENCE has a culture of addressing everyone with the suffix “-san,” regardless of roles, age, or positions. You are given a string S consisting of lowercase English letters. If S ends with san, print Yes; otherwi…

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…

微服务(Microservices),服务网格(Service Mesh)以及无服务器运算Serverless简单介绍

文章目录 什么是微服务?一、定义与特点二、优势三、组件与架构四、应用场景五、挑战与解决方案什么是服务网格?一、定义与特点二、核心组件三、主要功能四、实现工具五、应用场景六、优势与挑战什么是Serverless?一、定义与特点二、主要领域三、优势四、应用场景五、挑战三者…

C++项目工程代码自动检查

引言 在现代软件开发中&#xff0c;代码质量是成功的关键。特别是在C项目中&#xff0c;开发人员面临着复杂的代码管理和维护挑战。随着技术的不断进步&#xff0c;代码自动检查工具已成为提高代码质量、减少错误和提升开发效率的有效手段。本文将深入探讨C项目中的代码自动检…

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

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

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

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

解决Vue应用中遇到路由刷新后出现 404 错误

解释&#xff1a; Vue 应用中遇到路由刷新后出现 404 错误&#xff0c;通常是因为 Vue 应用是个单页应用&#xff08;SPA&#xff09;&#xff0c;它通过 Vue Router 管理路由&#xff0c;通过 HTML5 History Mode 实现页面导航无需重新加载页面。当直接访问非首页的路由或者刷…

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;就是命令行参数 总结&#…

WPF入门教学二十二 多线程与异步编程

在WPF&#xff08;Windows Presentation Foundation&#xff09;中&#xff0c;多线程和异步编程是非常重要的概念&#xff0c;因为它们可以帮助你创建响应性更好的应用程序。WPF的UI线程负责处理所有的用户界面操作&#xff0c;如果你的代码在UI线程上执行耗时操作&#xff0c…