# 大模型的快思慢想：适配自己的LLM使用场景II--在Mac/Edge设备及微信上运行Flux

> 本文详解在Mac Mini M1和树莓派5B上使用WasmEdge（LlamaEdge）部署FLUX.1[schnell]模型，实现边缘设备本地文本到图像生成，并通过Dify+CoW项目在微信上搭建提示词绘图应用，为无N卡场景提供实用方案。

- 来源: https://www.waytoagi.com/kb/learning-path/flux-on-mac-edge-wechat
- 飞书原文: https://waytoagi.feishu.cn/wiki/A5HvwWa5liMF1ckPtxTcP8tynOg
- 更新于: 2026-10-23

---

> **作者：ZimaBlueAI 齐码蓝** 
>
> https://mp.weixin.qq.com/s/Ut_qr5qYe-P6bMyApBvqNQ

**导语**

在边缘设备上运行LlamaEdge（WasmEdge）结合FLUX.1的应用实例。FLUX.1是一款由Black Forest Labs推出的先进文本到图像生成模型，拥有三种变体版本：FLUX.1 [pro]、FLUX.1 [dev]和FLUX.1 [schnell]，适用于不同需求的用户，支持开源和企业定制。

文章详细描述了如何在Mac Mini M1和树莓派5B上部署FLUX.1 [schnell]，结合WasmEdge框架实现高效的文本到图像生成。具体步骤涵盖了模型文件下载、WasmEdge插件安装及API服务器的启动。此外，文章还探讨了通过Dify和CoW项目实现微信平台上的图像生成实例，为LlamaEdge的边缘计算应用提供了实践案例。

**关键词：FLUX.1、M1、Raspberry PI5B、Edge、LlamaEdge、Dify、CoW**

![](https://www.waytoagi.com/api/kb-media/ROb7bv19zo0DPwxOROGckqHbnYb)

Zima **| 作者**

![](https://www.waytoagi.com/api/kb-media/I0QCb6G2koYL57xg6rOczwy5nyg)

> 继续讲述LlamaEdge(wasmedge)的应用实例

> ZimaBlueAI，公众号：齐码蓝 [大模型的快思慢想：适配自己的LLM使用场景--在树莓派和手机上架设大语言模型](https://mp.weixin.qq.com/s?__biz=MzkzMDQxNDI5NA==&mid=2247484890&idx=1&sn=b6de5dfd82ca2532720ae52791124387&chksm=c27bee63f50c6775732805024cc61e170da44b1f4d6edbe207cf9fcd6e2d98019f4bcffb0bc5&token=261222795&lang=zh_CN#rd)

FLUX.1

FLUX.1是由Black Forest Labs推出的一款先进的文本到图像生成模型套件，它包含三种不同的变体版本： FLUX.1 [pro]、FLUX.1 [dev]和FLUX.1 [schnell]，以满足不同用户的需求 。

**FLUX.1 [pro]** 是闭源模型，提供最高质量的图像生成，包括先进的提示跟随能力、视觉质量、图像细节和输出多样性。它可以通过官方API申请访问权限，并支持企业定制。

**FLUX.1 [dev]** 是开源模型，不可商用，直接从FLUX.1 [pro]蒸馏而来，具备相似的图像质量和提示词遵循能力，但更高效。它在HuggingFace上提供，可以在Replicate或fal.ai等平台上试用。

**FLUX.1 [schnell]** 是开源模型，可商用，专门为本地开发和个人使用量身定制，生成速度最快，内存占用也最小。它在Apache 2.0许可下公开提供，适合快速原型制作和个人项目。

FLUX.1的训练参数高达120亿，远超SD3 Medium的20亿。它在图像质量、提示词跟随、尺寸适应、排版和输出多样性等方面超越了Midjourney v6.0、DALL·E 3 (HD)和SD3-Ultra等流行模型，定义了新的图像合成的最先进水平。

FLUX.1 AI的工作原理基于混合架构，结合了变换器和扩散技术，能够根据文本提示生成准确的图像。它采用尖端技术，如流匹配和优化，以生成高质量图像。

FLUX.1 AI的关键特性包括尖端性能、文本处理能力、复杂构图能力和改进的人手生成。它支持在Replicate、fal.ai和Comfy UI等平台上使用，并且有明确的定价详情和使用限制。

此外，FLUX.1 AI支持用户根据自己的数据集进行微调，以生成特定风格或主题的图像。

本文我们尝试分别在没有N卡，不使用类似Comfy UI这样复杂的工作流搭建工具上使用Mac Mini M1上运行FLUX.1[schnell]。然后我们尝试在边缘设备Raspberry PI5B上看看是否可行，最后我们使用dify+CoW项目在微信上搭建一个通过微信发送提示词来画图的应用实例。

### 

### **Mac Mini M1运行FLUX.1**

**建议32GB内存以上运行**

**0x01 安装WasmEdge和SD(Stable Diffusion)插件** 

需要安装wasmedge>=0.14.1和最新的SD插件

```
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install_v2.sh | bash -s -- -v 0.14.1
```

Mac Silicon M1上安装

```
# 下载适用于 Mac Apple Silicon 的 Stable Diffusion 插件：curl -LO https://github.com/WasmEdge/WasmEdge/releases/download/0.14.1/WasmEdge-plugin-wasmedge_stablediffusion-metal-0.14.1-darwin_arm64.tar.gz
# 将插件解压到 $HOME/.wasmedge/plugin(安装wasmedge后自动创建）tar -xzf WasmEdge-plugin-wasmedge_stablediffusion-metal-0.14.1-darwin_arm64.tar.gz -C $HOME/.wasmedge/plugin
```

**0x02 下载FLUX.1[schnell]模型文件**

> 建议使用hfd.sh安装或者直接使用aria2

> ZimaBlueAI，公众号：齐码蓝 [大模型的快思慢想：适配自己的LLM使用场景--在树莓派和手机上架设大语言模型](https://mp.weixin.qq.com/s?__biz=MzkzMDQxNDI5NA==&mid=2247484890&idx=1&sn=b6de5dfd82ca2532720ae52791124387&chksm=c27bee63f50c6775732805024cc61e170da44b1f4d6edbe207cf9fcd6e2d98019f4bcffb0bc5&token=261222795&lang=zh_CN#rd)

这里我们使用hfd.sh

```
hfd.sh second-state/FLUX.1-schnell-GGUF --tool aria2c -x 4
```

如果不想将模型文件全下载了，可以使用aria2或curl下载

```
# Main modelaria2c -x 4 -s 4 -k 1M -c "https://hf-mirror.com/second-state/FLUX.1-schnell-GGUF/resolve/main/flux1-schnell-Q4_0.gguf" -d "." -o "flux1-schnell-Q4_0.gguf"
# VAE filearia2c -x 4 -s 4 -k 1M -c "https://hf-mirror.com/second-state/FLUX.1-schnell-GGUF/resolve/main/ae-f16.gguf" -d "." -o "ae-f16.gguf"
# clip_l encoderaria2c -x 4 -s 4 -k 1M -c "https://hf-mirror.com/second-state/FLUX.1-schnell-GGUF/resolve/main/clip_l-Q8_0.gguf" -d "." -o "clip_l-Q8_0.gguf"
# t5xxl encoderaria2c -x 4 -s 4 -k 1M -c "https://hf-mirror.com/second-state/FLUX.1-schnell-GGUF/resolve/main/t5xxl-Q4_K.gguf" -d "." -o "t5xxl-Q4_K.gguf"
```

 **0x03 下载API Server程序**

API server 是一个跨平台的 Wasm 应用，可以在不同的 CPU 和 GPU 设备上运行。

```
curl -LO https://github.com/LlamaEdge/sd-api-server/releases/latest/download/sd-api-server.wasm
```

**0x04 启动API Server**

在包含模型和 sd-api-server .wasm 的目录下运行：

FLUX.1-schnell-GGUF

├── ae-f16.gguf

├── clip_l-Q8_0.gguf

├── flux1-schnell-Q4_0.gguf

├── sd-api-server.wasm

└── t5xxl-Q4_K.gguf

```
wasmedge --dir .:. sd-api-server.wasm \ --model-name flux1-schnell \ --diffusion-model flux1-schnell-Q4_0.gguf \ --vae ae-f16.gguf \ --clip-l clip_l-Q8_0.gguf \ --t5xxl t5xxl-Q4_K.gguf
```

加载成功后，当看到显示：

```
Listening on 0.0.0.0:8080
```

表示已经启动正常了。

**0x05 文生图Text-to-Image**

```
curl -X POST 'http://localhost:8080/v1/images/generations' \  --header 'Content-Type: application/json' \  --data '{      "model": "flux1-schnell",      "prompt": "Astronaut, wearing futuristic astonaut outfit with space helmet, beautiful body and face, very breathtaking beautiful image, cinematic, 4k, epic Steven Spielberg movie still, sharp focus, emitting diodes, smoke, artillery, sparks, racks, system unit, motherboard, by pascal blanche rutkowski repin artstation hyperrealism painting concept art of detailed character design matte painting, 4 k resolution blade runner",      "cfg_scale": 1.0,      "sample_method": "euler",      "steps": 4  }'
```

如果一切正确，几分钟后终端将输出以下内容并将生成的图像保存为 “output.png”：

```
{"created":1728015570,"data":[{"url":"/archives/file_68f82479-f0db-44ed-adfc-ef2463796fcb/output.png","prompt":"Astronaut, wearing futuristic astonaut outfit with space helmet, beautiful body and face, very breathtaking beautiful image, cinematic, 4k, epic Steven Spielberg movie still, sharp focus, emitting diodes, smoke, artillery, sparks, racks, system unit, motherboard, by pascal blanche rutkowski repin artstation hyperrealism painting concept art of detailed character design matte painting, 4 k resolution blade runner"}]}
```

![](https://www.waytoagi.com/api/kb-media/VyRdbfdmPo4FroxzZlYcjE5tn0e)

### **Raspberry PI 5B运行FLUX.1**

在树莓派上运行，我们需要要改变上面的 0x01中的下载的Stable Diffusion 插件：

```
# 下载适用于 Raspberry PI5B aarch64 的 Stable Diffusion 插件：curl -LO https://github.com/WasmEdge/WasmEdge/releases/download/0.14.1/WasmEdge-plugin-wasmedge_stablediffusion-0.14.1-manylinux_2_28_aarch64.tar.gz
# 将插件解压到 $HOME/.wasmedge/plugin(安装wasmedge后自动创建）tar -xzf WasmEdge-plugin-wasmedge_stablediffusion-0.14.1-manylinux_2_28_aarch64.tar.gz -C $HOME/.wasmedge/plugin
```

然后运行0x04时，尽量选量化小一点的模型（或者可以自己下载safetensors文件使用llama.cpp重新量化）：

```
wasmedge --dir .:. sd-api-server.wasm \ --model-name flux1-schnell \ --diffusion-model flux1-schnell-Q4_0.gguf \ --vae ae-f16.gguf \ --clip-l clip_l-Q8_0.gguf \ --t5xxl t5xxl-Q2_K.gguf
```

发现内存报错，等下一个版本或量化到Q2再试。

```
Segmentation fault
```

或者下载

```
aria2c -x 4 -s 4 -k 1M -c "https://huggingface.co/lllyasviel/FLUX.1-schnell-gguf/resolve/08fc03e0dc5c1466c60fb7e108974ded1124c515/flux1-schnell-Q2_K.gguf" -d "." -o "flux1-schnell-Q2_K.gguf"
```

需要精算显存和内存需求的，可以参考公式：

![](https://www.waytoagi.com/api/kb-media/KAcibEYH1o7vdzxDiN0cZ5bpngd)

| 字段 | 解释 |
| --- | --- |
| M | GPU 内存（以 Gigabyte 为单位） |
| P | 模型中的参数数量。例如，7B 模型有 70 亿个参数。 |
| 4B | 4个字节，表示每个参数使用的字节数 |
| 32 | 每个字节有32位（bit） |
| Q | 加载模型时使用的位数，4，8或者16位 |
| 1.2 | 表示内存加载过程中额外的消耗 |

### 

再次测试

- 

```
wasmedge --dir .:. sd-api-server.wasm \ --model-name flux1-schnell \ --diffusion-model flux1-schnell-Q2_K.gguf \ --vae ae-f16.gguf \ --clip-l clip_l-Q8_0.gguf \ --t5xxl t5xxl-Q2_K.gguf
```

成功了！！！

![](https://www.waytoagi.com/api/kb-media/J0fDbu7b6oqMtuxRYcHc3DPtnmb)

但内存还是不够，报错概率极高，试提示词：

`A dramatic landscape on an exoplanet with a breathtaking view of a ringed gas giant in the sky. The planet surface is rugged and alien, with strange rock formations and vibrant, otherworldly vegetation. The rings of the gas giant cast colorful shadows and reflections, creating a surreal and captivating environment.` 

### 

### **Dify+CoW实现微信上调用FLUX.1**

以下实例，依赖环境：

CPU：Intel 13th Gen 13900KF

RAM: 64GB

显卡：nVidia RTX 4900 24GB

OS：win11 pro+WSL2+Ubuntu 20.04

Dify

**Dify.AI** 是一个开源的大规模语言模型（LLM）应用开发平台，它允许用户编排从代理到复杂AI工作流的LLM应用，并且配备了一个RAG引擎（Retrieval-Augmented Generation）。Dify.AI 旨在为特定行业提供聊天机器人和AI助手，这些助手可以嵌入领域知识，以促进人与AI的合作。

以下是Dify.AI的一些关键特性和优势：

1. **快速部署** ：用户可以在5分钟内部署定制化的聊天机器人或AI助手。

2. **创意文档生成** ：Dify.AI 能够从知识库生成清晰、逻辑性强的文档，并且没有长度限制。

3. **长文档摘要** ：它能够轻松地对长文档进行摘要。

4. **自定义API** ：Dify.AI 提供自定义API，可以安全地连接业务知识，解锁更深层次的LLM洞察。

5. **连接全球LLM** ：它能够连接到全球的LLM（Large Language Models）。

6. **生产就绪** ：Dify.AI 比LangChain更接近生产环境。

7. **开源** ：Dify.AI 是一个开源项目，这意味着它可以被社区广泛地使用和改进。

可以从 Dify.AI的GitHub仓库 https://github.com/langgenius/dify.gi t 和 https://docs.dify.ai/ 获取开发者和用户可以找到项目的源代码、文档、安装指南、使用说明和贡献指南等资源。

CoW

**c hatgpt-on-wechat** （简称CoW）是一个基于大型语言模型的智能对话机器人项目，旨在提供多平台部署和丰富的功能。以下是CoW项目的一些关键特性和优势：

1. **多端部署** ：CoW支持在多个平台部署，包括微信公众号、企业微信应用、飞书、钉钉等。

2. **基础对话** ：CoW能够智能回复私聊和群聊消息，支持多轮会话上下文记忆，并支持多种语言模型，如GPT-3.5, GPT-4, GPT-4o, Claude, Gemini, 文心一言, 讯飞星火, 通义千问，ChatGLM-4，Kimi（月之暗面）。

3. **语音识别** ：CoW可以识别语音消息，并以文字或语音形式回复，支持多种语音模型，如azure, baidu, google, openai(whisper/tts)。

4. **图片生成** ：CoW支持图片生成、图片识别、图生图（如照片修复），可选择Dall-E-3, stable diffusion, replicate, midjourney, CogView-3, vision等模型。

5. **丰富插件** ：CoW支持个性化插件扩展，已实现多角色切换、文字冒险、敏感词过滤、聊天记录总结、文档总结和对话、联网搜索等插件。

6. **Tool工具** ：CoW可以与操作系统和互联网交互，支持最新信息搜索、数学计算、天气和资讯查询、网页总结等功能。

7. **知识库** ：CoW允许用户上传知识库文件来自定义专属机器人，可作为数字分身、智能客服、私域助手使用。

8. **开源** ：CoW项目在GitHub和Gitee上开源，这意味着开发者和用户可以自由地访问、使用、修改和分发代码。

项目地址如下：

- **GitHub** : https://github.com/zhayujie/chatgpt-on-wechat

- **Gitee** : https://gitee.com/zhayujie/chatgpt-on-wechat

这里先暂时不过多介绍Dify，它跟AutoGPT, MetaGPT, FastGPT等等都是可以自己构建Agent，工作流的LLM应用开发平台。AM就是搭建在Dify上面的。以下是它的节点流预览图：

![](https://www.waytoagi.com/api/kb-media/IOj4bDkxKoLRVyxtHj0cL5vpn2g)

说回LlamaEdge，我们可以自建一个API扩展来实现调用上面的FLUX.1 API Server（套娃）

![](https://www.waytoagi.com/api/kb-media/DlgXbGdoBolQgMxG10hcRu95nBh)

API扩展说明，可以查看：https://docs.dify.ai/zh-hans/guides/extension/api-based-extension，但貌似0.8.3的版本不再使用了（dify里面有不少功能更新缺陷或版本冲突，所以使用时需要自行修改或提交PR）

也可以引入[dify-on-wechat](https://github.com/hanfangyuan4396/dify-on-wechat)项目，在bot/dify/新建一个dify_image.py的程序，将画图程序的调用过程写到dify bot中，如用query“画”开头接提示来触发调用。dify_image.py我将后面更新到我的代码仓库中。

- 

```
    def create_img(self, query, retry_count=0):        query_en = translate_text(query)
        # 定义请求参数        text_to_image_url = conf().get("dify_text_to_image_url", self.dify_api_image_base + "/images/generations")
        headers = {            'Content-Type': 'application/json'        }        data = {            "model": "flux1-schnell",            "prompt": query_en,            "cfg_scale": 1.0,            "sample_method": "euler",            "steps": 4        }
        try:            # 发送 POST 请求            response = requests.post(text_to_image_url, headers=headers, json=data)                     # 解析 JSON 响应            parsed_json = response.json()
            # 获取 URL            url = parsed_json["data"][0]["url"]            # 打印响应状态码和内容            print("URL:", url)            return True, "http://host.docker.internal:5000/" + url  ##建了一个图片服务器，用于转发本地图片URL
        except Exception as e:            logger.warn(e)            if retry_count < 3:                time.sleep(15)                logger.warn("[DIFY] ImgCreate RateLimit exceed, 第{}次重试".format(retry_count + 1))                return self.create_img(query, retry_count + 1)            else:                return False, "画图出现问题，请休息一下再问我吧"        except Exception as e:            logger.exception(e)            return False, "画图出现问题，请休息一下再问我吧"
```

图片服务器，很简单，分别写一个Flask app程序和一个html：

**app.py** 

- 

```
import osfrom flask import Flask, render_template, send_from_directory, requestfrom PIL import Imagefrom io import BytesIO
app = Flask(__name__)
# 图片存储路径IMAGE_FOLDER = '图片本地存储路径'
def walk_images(folder):    images = []    folders = []    for root, dirs, files in os.walk(folder):        for file in files:            if file.lower().endswith(('.png', '.jpg', '.jpeg')):                img_path = os.path.join(root, file)                img = Image.open(img_path)                thumb = img.copy()                thumb.thumbnail((100, 100))                output = BytesIO()                thumb.save(output, format='JPEG')                images.append({                    'type': 'image',                    'path': os.path.relpath(img_path, IMAGE_FOLDER),                    'thumb': output.getvalue()                })        for dir_name in dirs:            folders.append(os.path.join(root, dir_name))    return images, folders
@app.route('/')def index():    images, folders = walk_images(IMAGE_FOLDER)    return render_template('index.html', images=images, folders=folders)
@app.route('/<path:path>')def get_file(path):    return send_from_directory(IMAGE_FOLDER, path)
@app.route('/thumbs/<path:path>')def get_thumb(path):    img_path = os.path.join(IMAGE_FOLDER, path)    img = Image.open(img_path)    output = BytesIO()    img.thumbnail((300, 300))    img.save(output, format='JPEG')    return output.getvalue()
if __name__ == '__main__':    app.run(debug=True, host="host.docker.internal", port=5000)
```

**template/index.html**

- 

```
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Image Gallery</title>    <style>        .thumbnail {            width: 100px;            height: 100px;            object-fit: cover;        }        .gallery {            display: grid;            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));            gap: 10px;        }        .folder-icon {            background-color: #f0f0f0;            padding: 10px;            border-radius: 5px;            text-align: center;            cursor: pointer;        }        .folder-icon:hover {            background-color: #e0e0e0;        }</style></head><body>    <h1>Image Gallery</h1>    <div class="gallery">        {% for item in files %}            {% if item.type == 'folder' %}                <div class="folder-icon" onclick="location.href='/{{ item.name }}';">{{ item.name }}</div>            {% else %}                <img src="{{ url_for('get_thumb', path=item.name) }}" alt="{{ item.name }}">            {% endif %}        {% endfor %}    </div></body></html>
```

以上代码都可以由Phind, Copilot, Cursor, Zed+ollama+一个代码大模型代劳，但架构感觉整复杂了不够优雅，后面整理好打包一个解决方案再提交一个repo。

见效果图：

![](https://www.waytoagi.com/api/kb-media/OEoBbGv9Roz4plxKnuPcy1xLnug)

![](https://www.waytoagi.com/api/kb-media/Cq97bqdY2oBVx8x18jecbOvMnmf)

下回试试image-to-image和whisper及rag的wasm api server.

**介绍**

齐码蓝智能

![](https://www.waytoagi.com/api/kb-media/FifVbLaNxoG8L4xroGlczX2znUg)

Focusing on Technology, Life, and Truth
