ChatGPT 挂了,已经习惯了用大模型的我怎么办

ChatGPT 宕机了,习惯了用 ChatGPT 的我寸步难行,坐立难安,救救孩子!急,在线等。

你是不是已经习惯了 ChatGPT 的存在?是不是感觉离了 ChatGPT 寸步难行,很难再进行自己的工作?今天 ChatGPT 大面积宕机,服务直到文章发布(下午5点)时尚未恢复,已经习惯了用 AI 的我们该怎么办呢?

答案就是自己在本地运行一个大模型,只要电脑不关机,服务就一直在!

那么怎么在自己电脑上轻松方便地运行这些大模型呢?一般来说,运行这些模型的 Python / PyTorch 往往包含有 3GB 以上的相互依赖的包。即使设法安装了这些包,也总会与你的 GPU 或其他硬件加速器不兼容,导致非常糟糕的性能。

其实大可不必这样艰难!我们可以使用 Rust 和 WasmEdge,在本地创建和部署非常快速和轻量级的 LLM 推理应用。安装文件也非常小,是一个只有几 MB 的简单二进制可执行文件。更赞的是,这个负责推理的应用程序完全可以跨广泛的 CPU、GPU 和操作系统移植。最赞的是,它完全没有 Python 依赖。让我们开始吧!

这个教程,我们将覆盖:

  1. 在日常使用的 macOS 或几乎任何平台上运行 LLM,包括 Llama2 7b 和各种其他 LLM;
  2. 在几分钟内为你的大模型构建一个轻量级的 AI Agent ;
  3. 在 LLM 之外的 AI 上使用 WasmEdge。

第 1 部分:运行 LLM 和 AI 模型的超简单方法

1. 安装具有 LLM 支持的 WasmEdge

可以从一个命令行开始,安装完整的 LLM 支持的 WasmEdge runtime。

bash 复制代码
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --plugin wasi_nn-ggml

或者可以按照这里的安装指南手动下载和复制 WasmEdge 安装文件。

2. 下载 Wasm 格式的 LLM 推理应用

接下来,获取超小的 2MB 跨平台二进制文件 ------ llama-chat.wasm。这是效率的证明,无需其他依赖,并能在不同环境中无缝操作。这个小的 Wasm 文件是从 Rust 编译的。想要构建自己的 AI 推理 应用,请查看 llama-utils Repo。

perl 复制代码
curl -LO https://github.com/second-state/llama-utils/raw/main/chat/llama-chat.wasm

3. 下载 Llama2 7b chat 模型

ruby 复制代码
curl -LO https://huggingface.co/wasmedge/llama2/blob/main/llama-2-7b-chat-q5_k_m.gguf

WasmEdge 还支持 Llama2、CodeLlama、Llemma、Codeshell、Mistrial、MistrialLite、TinyLlama、Baichuan、BELLE、Alpaca、Vicuna、OpenChat、Starcoder、OpenBuddy 等更多!

4. 在 CLI 上与 Llama2 7b chat

现在你已经准备好了一切,可以开始使用命令行与 Llama2 7b chat 模型聊天。

ruby 复制代码
wasmedge --dir .:. --nn-preload default:GGML:AUTO:llama-2-7b-chat-wasm-q5_k_m.gguf 
llama-chat.wasm

现在,可以和 Llama2 7b chat 对话啦。让 Llama2 7b chat 模型帮我写代码,解决一些看起来比较枯燥的工作!

less 复制代码
[USER]: 
I want to combine all the txt files in the local directory. write a python program for me.

[ASSISTANT]:
Of course! Here is a simple Python program that can combine all the text files in the current directory:

import os

for filename in os.listdir(): if filename.endswith('.txt'): with open(filename, 'a') as f: f.write('')

vbnet 复制代码
This program uses the `os` module to list all the files in the current directory, and then checks if each file ends with the `.txt` extension using the `endswith()` method. If a `.txt` file is found, it is opened in append mode (`'a'`) using the `open()` function, and the contents are written to the file using the `write()` method.

Please let me know if you have any questions or if you need further assistance!

[USER]: 
How can I run this program? I'm not familar with python.

[ASSISTANT]:
Of course! Here are the steps to run the Python program:

1. Open a terminal or command prompt on your computer.
2. Navigate to the directory where the text files are located using the `cd` command. For example, if the text files are located in the `Documents` directory, you would type `cd Documents`.
3. Type `python combine_txt_files.py` and press Enter. This will run the `combine_txt_files.py` program.
4. The program will combine all the text files in the current directory and write the combined contents to a new file called `combined_txt_files.txt`.

If you are using a Python IDE (Integrated Development Environment) such as PyCharm or Visual Studio Code, you can open the `combine_txt_files.py` file and run it by clicking the "Run" button or pressing `F5`.

I hope this helps! Let me know if you have any questions.

就这样!你还可以使用同样的 llama-chat.wasm 文件来运行其他 LLM,如 OpenChat、CodeLlama、Mistral 等。

资源:

通过以下额外资源,探索可以在 WasmEdge 上运行的各种 LLM:

第 2 部分:构建超轻量级 AI Agent

1. 创建一个与 OpenAI 兼容的 API 服务

当用你的领域知识微调了一个模型或你想要运行一个私有模型时,仅使用 CLI 运行模型是不够的。我们通常需要依靠这个大模型构建 Agent,让 LLM 更好的帮我工作。接下来,让我们为大模型设置兼容 OpenAI 的 API 服务,然后我们可以将这个私有模型集成到其他 SaaS 工作流程中。这样即便 ChatGPT 宕机,你的 Agent 依然可以正常为你工作!

这里假设你已经安装了带有 ggml 插件的 WasmEdge 并下载了你需要的模型。

首先,通过终端下载构建 API 服务器的 Wasm 文件。

perl 复制代码
curl -LO https://github.com/second-state/llama-utils/raw/main/api-server/llama-api-server.wasm

接下来,用基于 WasmEdge 的API 服务运行模型。

ruby 复制代码
wasmedge --dir .:. --nn-preload default:GGML:AUTO:llama-2-7b-chat-wasm-q5_k_m.gguf llama-api-server.wasm -p llama-2-chat -s 0.0.0.0:8080

在看到连接建立后,可以使用以下命令行来尝试你的模型。

rust 复制代码
curl -X POST http://localhost:8080/v1/chat/completions \
 -H 'accept: application/json' \
 -H 'Content-Type: application/json' \
 -d '{"messages":[{"role":"system", "content": "You are a helpful assistant. Answer each question in one sentence."}, {"role":"user", "content": "**What is Wasm?**"}], "model":"llama-2-chat"}'

2. 部署连接 API 服务的聊天机器人 UI

接下来,让我们将你的 API 服务链接到由 Second State 提供的 Chatbot-UI,为用户提供丝滑的对话体验。

需要做的就是将你的 Chat API 复制并粘贴到左下角侧边栏的 Chat API URL 中。请注意,你的 API URL 必须是一个 HTTPs 代理。nike可以使用 ngrok 来实现 HTTPs 代理,或者绑定你的域名。

接下来,就可以通过 Chatbot-UI 与模型聊天啦。

3. 围绕模型构建 RAG 机器人和 Agent

如果我们将模型的能力应用到现实世界的工作流程中,LLM Agent 比 Web 聊天机器人更有帮助。Flows.network 是一个 Severless 平台,用 Rust 和 Wasm 构建 LLM Agent 和机器人。flows.network 平台允许开发者将像 ChatGPT 和 Claude 的大模型连接到不同的 SaaS 提供商。由于模型已经具备与 OpenAI 兼容的 API,我们可以像在 OpenAI 上做的那样,轻松地将模型与 Telegram、Slack 和 Discord 等其他 SaaS 集成。查看如何构建基于 RAG 的 LLM Agent

或者,可以使用 LangChainLlamaIndex 来构建 RAG(检索增强生成)应用程序。

来试一试使用这种方式构建的 RAG 机器人,帮助你学习 Rust 语言 👉flows.network/learn-rust

第 3 部分:不止于大语言模型

WasmEdge 的 AI 不仅限于 LLM 任务;它还扩展到视觉和音频领域。除了 ggml 后端,WasmEdge 运行时还支持 PyTorch、TensorFlow 和 OpenVINO AI 框架。为了使 AI 推理更加流畅,WasmEdge 还支持使用流行的 OpenCV 和 FFmpeg 库进行图像处理。

了解如何借助 mediapipe-rs 开发图像和音频 AI 应用,并上手尝试其他 WASI-NN 示例。

结论

在有了强大的 ChatGPT 后,我们是不是还需要一个私有的模型?答案是肯定的!WasmEdge 为运行最先进的 LLM,包括你自己微调的 Llama 2 模型,提供了一个轻量级、安全、可靠和高效的环境。无论你是希望部署 AI 应用的开发者,还是寻求将智能 Agent 集成到你的服务中,使用 Rust + WasmEdge 都将为你提供价值。

加入 WasmEdge discord 的讨论,来 GitHub 为 WasmEdge 做贡献吧。

相关推荐
哪 吒4 小时前
吊打ChatGPT4o!大学生如何用上原版O1辅助论文写作(附论文教程)
人工智能·ai·自然语言处理·chatgpt·aigc
爱喝白开水a4 小时前
关于大模型在企业生产环境中的独立部署问题
人工智能·深度学习·llm·大语言模型·ai大模型·计算机技术·本地部署大模型
姜学迁4 小时前
Rust-枚举
开发语言·后端·rust
凌云行者4 小时前
rust的迭代器方法——collect
开发语言·rust
Langchain5 小时前
不可错过!CMU最新《生成式人工智能大模型》课程:从文本、图像到多模态大模型
人工智能·自然语言处理·langchain·大模型·llm·大语言模型·多模态大模型
幽影相随6 小时前
构建llama.cpp并在linux上使用gpu
llm·llama.cpp
AAI机器之心7 小时前
LLM大模型:开源RAG框架汇总
人工智能·chatgpt·开源·大模型·llm·大语言模型·rag
XiaoLiuLB11 小时前
ChatGPT Canvas:交互式对话编辑器
人工智能·自然语言处理·chatgpt·编辑器·aigc
QMCY_jason11 小时前
Ubuntu 安装RUST
linux·ubuntu·rust
BigYe程普11 小时前
我开发了一个出海全栈SaaS工具,还写了一套全栈开发教程
开发语言·前端·chrome·chatgpt·reactjs·个人开发