id: ea726bb644c64041818b1bc2b5d734cd
parent_id: 
item_type: 1
item_id: 1453b5b3e2f748e1b56e431db2116508
item_updated_time: 1764345512669
title_diff: "[{\"diffs\":[[1,\"Mac mini 大模型部署完全指南：7种方法从入门到精通\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":29}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>Mac mini 大模型部署完全指南：7种方法从入门到精通</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"46043\\\"></a>\\\r\\\n<h1>Mac mini 大模型部署完全指南：7种方法从入门到精通</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"https://mp.weixin.qq.com/s?__biz=MzI5NDExOTk5MA==&amp;mid=2247484129&amp;idx=1&amp;sn=ea1bf78b6c61c12d13f4db4e0f854043&amp;chksm=ed1212f2cc68f0e3990b8b016a06ed987861acc9c0ca2285bc47b7830e79084dc867e10ee2fe&amp;mpshare=1&amp;scene=1&amp;srcid=0920pnwAFlSWemazMRw5vvaB&amp;sharer_shareinfo=a559af9027a5bd1db85925fe77197889&amp;sharer_shareinfo_first=a559af9027a5bd1db85925fe77197889#rd\\\"><span>https://mp.weixin.qq.com/s?__biz=MzI5NDExOTk5MA==&amp;mid=224748...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"\\\"><div><div><h1 style=\\\"margin:0\\\"> Mac mini 大模型部署完全指南：7种方法从入门到精通</h1><div><span style=\\\"position:relative\\\">原创</span><span> Ailln </span><span><a style=\\\"position:relative\\\"> 通用智能体 </a></span><span><em></em></span></div><div style=\\\";\\\"><span style=\\\"font-size: 16px;color: black;padding: 25px 30px;line-height: 1.6;word-spacing: 0px;letter-spacing: 0px;word-break: break-word;word-wrap: break-word;text-align: justify;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;margin-top: -10px;\\\"><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>前言</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>随着大模型技术的快速发展，越来越多的人希望在本地部署大模型，既能保护数据隐私，又能避免网络延迟。Mac mini 作为苹果的入门级桌面设备，凭借其出色的能效比和 Apple Silicon 芯片的强大性能，成为了本地部署大模型的理想选择。</span></p><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>本文将介绍 7 种不同的部署方法，从最简单的一键安装到高级的自定义部署，满足不同用户的需求。</span></p><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>硬件要求</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>在开始之前，让我们先了解一下 Mac mini 的硬件配置要求：</span></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>最低配置</span></strong><span>：8GB 统一内存（可运行 3B-7B 参数模型）</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>推荐配置</span></strong><span>：16GB 统一内存（可运行 7B-13B 参数模型）</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>高端配置</span></strong><span>：24GB+ 统一内存（可运行 13B+ 参数模型）</span></span></li></ul><blockquote style=\\\"display: block;font-size: 0.9em;overflow: auto;overflow-scrolling: touch;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: #6a737d;padding-top: 10px;padding-bottom: 10px;padding-left: 20px;padding-right: 10px;margin-bottom: 20px;margin-top: 20px;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;color:black;line-height:26px\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>注意</span></strong><span>：Apple Silicon 的统一内存架构使得内存既用于系统运行，也用于模型推理，因此内存大小直接决定了能运行的模型规模。</span></p></blockquote><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法一：Ollama - 最简单易用的方案</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>Ollama 是目前最受欢迎的本地大模型部署工具，支持一键下载和运行各种开源模型。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>安装 Ollama</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 方法1：使用官方安装脚本</span></div><div><span>curl -fsSL https://ollama.ai/install.sh | sh</span></div><div><span><br/></span></div><div><span># 方法2：使用 Homebrew</span></div><div><span>brew install ollama</span></div><div><span><br/></span></div><div><span># 方法3：从官网下载 .pkg 安装包</span></div><div><span># 访问 https://ollama.ai/download 下载</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>启动 Ollama 服务</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 启动 Ollama 服务</span></div><div><span>ollama serve</span></div><div><span><br/></span></div><div><span># 或者在后台运行</span></div><div><span>nohup ollama serve &gt; ollama.log 2&gt;&amp;1 &amp;</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>下载和运行模型</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 下载并运行 Llama 3.2 3B 模型（适合 8GB 内存）</span></div><div><span>ollama run llama3.2:3b</span></div><div><span><br/></span></div><div><span># 下载并运行 Llama 3.1 8B 模型（适合 16GB 内存）</span></div><div><span>ollama run llama3.1:8b</span></div><div><span><br/></span></div><div><span># 下载并运行 Qwen2.5 7B 模型</span></div><div><span>ollama run qwen2.5:7b</span></div><div><span><br/></span></div><div><span># 下载并运行 CodeLlama 7B 代码模型</span></div><div><span>ollama run codellama:7b</span></div><div><span><br/></span></div><div><span># 查看已下载的模型</span></div><div><span>ollama list</span></div><div><span><br/></span></div><div><span># 删除不需要的模型</span></div><div><span>ollama rm model_name</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>通过 API 调用</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 使用 curl 调用 API</span></div><div><span>curl http://localhost:11434/api/generate -d '{</span></div><div><span>  &quot;model&quot;: &quot;llama3.2:3b&quot;,</span></div><div><span>  &quot;prompt&quot;: &quot;为什么天空是蓝色的？&quot;,</span></div><div><span>  &quot;stream&quot;: false</span></div><div><span>}'</span></div><div><span><br/></span></div><div><span># 使用 Python 调用</span></div><div><span>pip install requests</span></div><div><span><br/></span></div><div><span>cat &gt; test_ollama.py &lt;&lt; 'EOF'</span></div><div><span>import requests</span></div><div><span>import json</span></div><div><span><br/></span></div><div><span>def chat_with_ollama(prompt, model=&quot;llama3.2:3b&quot;):</span></div><div><span>    url = &quot;http://localhost:11434/api/generate&quot;</span></div><div><span>    data = {</span></div><div><span>        &quot;model&quot;: model,</span></div><div><span>        &quot;prompt&quot;: prompt,</span></div><div><span>        &quot;stream&quot;: False</span></div><div><span>    }</span></div><div><span><br/></span></div><div><span>    response = requests.post(url, json=data)</span></div><div><span>    if response.status_code == 200:</span></div><div><span>        return json.loads(response.text)[&quot;response&quot;]</span></div><div><span>    else:</span></div><div><span>        return f&quot;错误: {response.status_code}&quot;</span></div><div><span><br/></span></div><div><span># 测试</span></div><div><span>result = chat_with_ollama(&quot;用中文解释什么是人工智能&quot;)</span></div><div><span>print(result)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span>python test_ollama.py</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>Ollama 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>安装简单，一键部署</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持众多开源模型</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>自动处理模型量化和优化</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>提供 REST API 接口</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>社区活跃，更新频繁</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>模型选择相对有限</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>自定义配置选项较少</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>依赖网络下载模型</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法二：LM Studio - 图形化界面的选择</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>LM Studio 提供了友好的图形化界面，特别适合不熟悉命令行的用户。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>安装 LM Studio</span></span></h3><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>访问 LM Studio 官网</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>下载 macOS 版本</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>拖拽到 Applications 文件夹完成安装</span></span></li></ol><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>使用步骤</span></span></h3><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>启动 LM Studio</span></strong></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>浏览模型</span></strong><span>：在 &quot;Discover&quot; 标签页浏览可用模型</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>下载模型</span></strong><span>：选择适合你内存大小的模型版本</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>加载模型</span></strong><span>：在 &quot;Chat&quot; 标签页加载已下载的模型</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>开始对话</span></strong><span>：直接在界面中与模型对话</span></span></li></ol><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>推荐模型配置</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span>8GB 内存 Mac mini：</span></div><div><span>- Llama 3.2 3B Instruct (Q4_K_M)</span></div><div><span>- Phi-3 Mini 4K Instruct (Q4_K_M)</span></div><div><span>- Gemma 2 2B Instruct (Q4_K_M)</span></div><div><span><br/></span></div><div><span>16GB 内存 Mac mini：</span></div><div><span>- Llama 3.1 8B Instruct (Q4_K_M)</span></div><div><span>- Mistral 7B Instruct (Q4_K_M)</span></div><div><span>- CodeLlama 7B Instruct (Q4_K_M)</span></div><div><span><br/></span></div><div><span>24GB+ 内存 Mac mini：</span></div><div><span>- Llama 3.1 8B Instruct (Q6_K)</span></div><div><span>- Mixtral 8x7B Instruct (Q4_K_M)</span></div><div><span>- CodeLlama 13B Instruct (Q4_K_M)</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>本地服务器模式</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>LM Studio 还可以作为本地服务器运行：</span></p><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>在 &quot;Local Server&quot; 标签页</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>选择要加载的模型</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>点击 &quot;Start Server&quot;</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>使用 </span><code style=\\\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\\\"><span>http://localhost:1234</span></code><span> 访问 API</span></span></li></ol><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>LM Studio 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>图形化界面，操作简单</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>模型管理方便</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持多种量化格式</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>内置性能监控</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持本地 API 服务</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>软件体积较大</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>免费版功能有限</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>更新频率不如 Ollama</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法三：llamafile - 单文件部署方案</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>llamafile 将模型和运行时打包成单个可执行文件，无需安装任何依赖。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>下载 llamafile</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建工作目录</span></div><div><span>mkdir ~/llamafiles &amp;&amp; cd ~/llamafiles</span></div><div><span><br/></span></div><div><span># 下载 Llama 3.2 3B llamafile（约 2GB）</span></div><div><span>wget https://huggingface.co/Mozilla/Llama-3.2-3B-Instruct-llamafile/resolve/main/Llama-3.2-3B-Instruct.Q6_K.llamafile</span></div><div><span><br/></span></div><div><span># 或者下载其他模型</span></div><div><span># TinyLlama 1.1B（约 700MB）</span></div><div><span>wget https://huggingface.co/jartine/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/TinyLlama-1.1B-Chat-v1.0.Q5_K_M.llamafile</span></div><div><span><br/></span></div><div><span># Phi-3 Mini（约 2.4GB）</span></div><div><span>wget https://huggingface.co/Mozilla/Phi-3-mini-4k-instruct-llamafile/resolve/main/Phi-3-mini-4k-instruct.Q6_K.llamafile</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>运行 llamafile</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 给文件执行权限</span></div><div><span>chmod +x *.llamafile</span></div><div><span><br/></span></div><div><span># 运行模型（会自动启动 Web 界面）</span></div><div><span>./Llama-3.2-3B-Instruct.Q6_K.llamafile</span></div><div><span><br/></span></div><div><span># 在后台运行</span></div><div><span>nohup ./Llama-3.2-3B-Instruct.Q6_K.llamafile --port 8080 &gt; llamafile.log 2&gt;&amp;1 &amp;</span></div><div><span><br/></span></div><div><span># 指定更多参数</span></div><div><span>./Llama-3.2-3B-Instruct.Q6_K.llamafile \\\\</span></div><div><span>  --port 8080 \\\\</span></div><div><span>  --threads 8 \\\\</span></div><div><span>  --ctx-size 4096 \\\\</span></div><div><span>  --batch-size 512</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>访问 Web 界面</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>打开浏览器访问 </span><code style=\\\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\\\"><span>http://localhost:8080</span></code><span>，你会看到一个简洁的聊天界面。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>使用 API</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 测试 API</span></div><div><span>curl http://localhost:8080/v1/chat/completions \\\\</span></div><div><span>  -H &quot;Content-Type: application/json&quot; \\\\</span></div><div><span>  -d '{</span></div><div><span>    &quot;model&quot;: &quot;LLaMA_CPP&quot;,</span></div><div><span>    &quot;messages&quot;: [</span></div><div><span>      {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;你好，请介绍一下自己&quot;}</span></div><div><span>    ],</span></div><div><span>    &quot;temperature&quot;: 0.7,</span></div><div><span>    &quot;max_tokens&quot;: 500</span></div><div><span>  }'</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>llamafile 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>单文件部署，无需安装</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>跨平台兼容</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>内置 Web 界面</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持 OpenAI 兼容 API</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>启动速度快</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>文件体积较大</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>模型选择有限</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>自定义选项较少</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法四：MLX - Apple Silicon 专用优化框架</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>MLX 是苹果专门为 Apple Silicon 芯片优化的机器学习框架，能够充分利用统一内存架构。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>安装 MLX</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 安装 Python 3.8+</span></div><div><span>brew install python@3.11</span></div><div><span><br/></span></div><div><span># 创建虚拟环境</span></div><div><span>python3.11 -m venv mlx_env</span></div><div><span>source mlx_env/bin/activate</span></div><div><span><br/></span></div><div><span># 安装 MLX 相关包</span></div><div><span>pip install mlx-lm</span></div><div><span>pip install huggingface_hub</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>下载和转换模型</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 下载并转换 Llama 3.2 3B 模型</span></div><div><span>python -m mlx_lm.convert \\\\</span></div><div><span>  --hf-path meta-llama/Llama-3.2-3B-Instruct \\\\</span></div><div><span>  --mlx-path ./models/llama-3.2-3b-mlx \\\\</span></div><div><span>  --quantize</span></div><div><span><br/></span></div><div><span># 下载 Qwen2.5 7B 模型</span></div><div><span>python -m mlx_lm.convert \\\\</span></div><div><span>  --hf-path Qwen/Qwen2.5-7B-Instruct \\\\</span></div><div><span>  --mlx-path ./models/qwen2.5-7b-mlx \\\\</span></div><div><span>  --quantize</span></div><div><span><br/></span></div><div><span># 列出可用的预转换模型</span></div><div><span>python -c &quot;</span></div><div><span>from mlx_lm.utils import get_model_path</span></div><div><span>from mlx_lm import list_models</span></div><div><span>print('可用模型:')</span></div><div><span>for model in list_models():</span></div><div><span>    print(f'  {model}')</span></div><div><span>&quot;</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>运行模型</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 直接运行对话</span></div><div><span>python -m mlx_lm.generate \\\\</span></div><div><span>  --model ./models/llama-3.2-3b-mlx \\\\</span></div><div><span>  --prompt &quot;解释一下什么是机器学习&quot; \\\\</span></div><div><span>  --max-tokens 500 \\\\</span></div><div><span>  --temp 0.7</span></div><div><span><br/></span></div><div><span># 交互式对话</span></div><div><span>python -c &quot;</span></div><div><span>from mlx_lm import load, generate</span></div><div><span><br/></span></div><div><span>model, tokenizer = load('./models/llama-3.2-3b-mlx')</span></div><div><span><br/></span></div><div><span>while True:</span></div><div><span>    prompt = input('用户: ')</span></div><div><span>    if prompt.lower() in ['quit', 'exit', '退出']:</span></div><div><span>        break</span></div><div><span><br/></span></div><div><span>    response = generate(model, tokenizer, prompt, max_tokens=500)</span></div><div><span>    print(f'助手: {response}')</span></div><div><span>&quot;</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>创建 MLX 服务</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建 mlx_server.py</span></div><div><span>cat &gt; mlx_server.py &lt;&lt; 'EOF'</span></div><div><span>from flask import Flask, request, jsonify</span></div><div><span>from mlx_lm import load, generate</span></div><div><span>import threading</span></div><div><span>import time</span></div><div><span><br/></span></div><div><span>app = Flask(__name__)</span></div><div><span><br/></span></div><div><span># 全局变量存储模型</span></div><div><span>model = None</span></div><div><span>tokenizer = None</span></div><div><span>model_lock = threading.Lock()</span></div><div><span><br/></span></div><div><span>def load_model(model_path):</span></div><div><span>    global model, tokenizer</span></div><div><span>    print(f&quot;正在加载模型: {model_path}&quot;)</span></div><div><span>    start_time = time.time()</span></div><div><span>    model, tokenizer = load(model_path)</span></div><div><span>    load_time = time.time() - start_time</span></div><div><span>    print(f&quot;模型加载完成，耗时: {load_time:.2f}秒&quot;)</span></div><div><span><br/></span></div><div><span>@app.route('/v1/chat/completions', methods=['POST'])</span></div><div><span>def chat_completions():</span></div><div><span>    global model, tokenizer</span></div><div><span><br/></span></div><div><span>    if model is None or tokenizer is None:</span></div><div><span>        return jsonify({&quot;error&quot;: &quot;模型未加载&quot;}), 500</span></div><div><span><br/></span></div><div><span>    data = request.json</span></div><div><span>    messages = data.get('messages', [])</span></div><div><span>    max_tokens = data.get('max_tokens', 500)</span></div><div><span>    temperature = data.get('temperature', 0.7)</span></div><div><span><br/></span></div><div><span>    # 构建提示词</span></div><div><span>    prompt = &quot;&quot;</span></div><div><span>    for msg in messages:</span></div><div><span>        role = msg.get('role', '')</span></div><div><span>        content = msg.get('content', '')</span></div><div><span>        if role == 'user':</span></div><div><span>            prompt += f&quot;用户: {content}\\\\\n助手: &quot;</span></div><div><span>        elif role == 'assistant':</span></div><div><span>            prompt += f&quot;{content}\\\\\n&quot;</span></div><div><span><br/></span></div><div><span>    # 生成回复</span></div><div><span>    with model_lock:</span></div><div><span>        response = generate(</span></div><div><span>            model, </span></div><div><span>            tokenizer, </span></div><div><span>            prompt, </span></div><div><span>            max_tokens=max_tokens,</span></div><div><span>            temp=temperature</span></div><div><span>        )</span></div><div><span><br/></span></div><div><span>    return jsonify({</span></div><div><span>        &quot;choices&quot;: [{</span></div><div><span>            &quot;message&quot;: {</span></div><div><span>                &quot;role&quot;: &quot;assistant&quot;,</span></div><div><span>                &quot;content&quot;: response</span></div><div><span>            }</span></div><div><span>        }]</span></div><div><span>    })</span></div><div><span><br/></span></div><div><span>@app.route('/health', methods=['GET'])</span></div><div><span>def health():</span></div><div><span>    return jsonify({&quot;status&quot;: &quot;healthy&quot;, &quot;model_loaded&quot;: model is not None})</span></div><div><span><br/></span></div><div><span>if __name__ == '__main__':</span></div><div><span>    import sys</span></div><div><span>    if len(sys.argv) &gt; 1:</span></div><div><span>        model_path = sys.argv[1]</span></div><div><span>        load_model(model_path)</span></div><div><span>    else:</span></div><div><span>        print(&quot;使用方法: python mlx_server.py &lt;模型路径&gt;&quot;)</span></div><div><span>        sys.exit(1)</span></div><div><span><br/></span></div><div><span>    app.run(host='0.0.0.0', port=8080, threaded=True)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span># 运行服务</span></div><div><span>python mlx_server.py ./models/llama-3.2-3b-mlx</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>MLX 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>专为 Apple Silicon 优化</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>内存使用效率高</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>推理速度快</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持量化和优化</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>与 PyTorch 兼容</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>仅支持 Apple Silicon</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>需要手动转换模型</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>社区相对较小</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>文档相对较少</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法五：Docker 容器化部署</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>使用 Docker 可以实现环境隔离和便捷的部署管理。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>安装 Docker</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 下载 Docker Desktop for Mac</span></div><div><span># 访问 https://www.docker.com/products/docker-desktop</span></div><div><span><br/></span></div><div><span># 或使用 Homebrew</span></div><div><span>brew install --cask docker</span></div><div><span><br/></span></div><div><span># 启动 Docker Desktop</span></div><div><span>open /Applications/Docker.app</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>使用 Ollama Docker 镜像</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 拉取 Ollama 镜像</span></div><div><span>docker pull ollama/ollama</span></div><div><span><br/></span></div><div><span># 运行 Ollama 容器</span></div><div><span>docker run -d \\\\</span></div><div><span>  --name ollama \\\\</span></div><div><span>  -p 11434:11434 \\\\</span></div><div><span>  -v ollama:/root/.ollama \\\\</span></div><div><span>  ollama/ollama</span></div><div><span><br/></span></div><div><span># 在容器中下载模型</span></div><div><span>docker exec -it ollama ollama pull llama3.2:3b</span></div><div><span><br/></span></div><div><span># 测试模型</span></div><div><span>docker exec -it ollama ollama run llama3.2:3b &quot;你好，介绍一下自己&quot;</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>Docker Compose 部署</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建 docker-compose.yml</span></div><div><span>cat &gt; docker-compose.yml &lt;&lt; 'EOF'</span></div><div><span>version: '3.8'</span></div><div><span><br/></span></div><div><span>services:</span></div><div><span>  ollama:</span></div><div><span>    image: ollama/ollama</span></div><div><span>    container_name: ollama</span></div><div><span>    ports:</span></div><div><span>      - &quot;11434:11434&quot;</span></div><div><span>    volumes:</span></div><div><span>      - ollama_data:/root/.ollama</span></div><div><span>    restart: unless-stopped</span></div><div><span>    environment:</span></div><div><span>      - OLLAMA_HOST=0.0.0.0</span></div><div><span><br/></span></div><div><span>  ollama-webui:</span></div><div><span>    image: ghcr.io/open-webui/open-webui:main</span></div><div><span>    container_name: ollama-webui</span></div><div><span>    ports:</span></div><div><span>      - &quot;3000:8080&quot;</span></div><div><span>    environment:</span></div><div><span>      - OLLAMA_BASE_URL=http://ollama:11434</span></div><div><span>    volumes:</span></div><div><span>      - open-webui:/app/backend/data</span></div><div><span>    depends_on:</span></div><div><span>      - ollama</span></div><div><span>    restart: unless-stopped</span></div><div><span><br/></span></div><div><span>volumes:</span></div><div><span>  ollama_data:</span></div><div><span>  open-webui:</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span># 启动服务</span></div><div><span>docker-compose up -d</span></div><div><span><br/></span></div><div><span># 查看日志</span></div><div><span>docker-compose logs -f</span></div><div><span><br/></span></div><div><span># 停止服务</span></div><div><span>docker-compose down</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>Docker 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>环境隔离，避免依赖冲突</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>便于部署和迁移</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持多服务编排</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>资源限制和监控</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>版本管理方便</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>额外的资源开销</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>学习成本较高</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>在 macOS 上性能略有损失</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法六：Cherry Studio - 开源 AI 客户端</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>Cherry Studio 是一款开源的 AI 客户端，提供了现代化的界面和丰富的功能，支持本地模型部署和知识库管理。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>安装 Cherry Studio</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 方法1：从 GitHub 下载最新版本</span></div><div><span># 访问 https://github.com/CherryHQ/cherry-studio/releases</span></div><div><span># 下载 Cherry-Studio-x.x.x-mac.dmg</span></div><div><span><br/></span></div><div><span># 方法2：使用 Homebrew（如果可用）</span></div><div><span>brew install --cask cherry-studio</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>手动安装步骤</span></span></h3><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>下载安装包</span></strong></p></span></li><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>访问 Cherry Studio GitHub</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>在 Releases 页面下载最新的 macOS 版本</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>下载 </span><code style=\\\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\\\"><span>.dmg</span></code><span> 文件</span></span></li></ul><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>安装应用</span></strong></p></span></li><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>双击 </span><code style=\\\"font-size: 14px;word-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin: 0 2px;color: #1e6bb8;background-color: rgba(27,31,35,.05);font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;word-break: break-all;\\\"><span>.dmg</span></code><span> 文件</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>将 Cherry Studio 拖拽到 Applications 文件夹</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>首次启动时可能需要在系统偏好设置中允许运行</span></span></li></ul></ol><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>配置本地模型</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 确保 Ollama 已安装并运行</span></div><div><span>ollama serve</span></div><div><span><br/></span></div><div><span># 下载推荐模型</span></div><div><span>ollama pull llama3.2:3b</span></div><div><span>ollama pull qwen2.5:7b</span></div><div><span>ollama pull deepseek-r1:1.5b</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>在 Cherry Studio 中配置</span></span></h3><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>启动 Cherry Studio</span></strong></p></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>添加模型服务</span></strong><span>：</span></p></span></li><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>点击设置图标</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>选择 &quot;模型服务&quot;</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>点击 &quot;添加服务&quot;</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>选择 &quot;Ollama&quot;</span></span></li></ul><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>配置连接</span></strong><span>：</span></p><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>服务名称: Ollama Local</span><div><span>API 地址: http://localhost:11434</span></div><div><span>API 密钥: 留空（本地服务不需要）</span></div></div></pre></span></span></li><ul style=\\\"margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;counter-reset:line;flex-shrink:0;height:100%;padding:1em;list-style-type:none;padding:16px;margin:0\\\"><li style=\\\"list-style-type: none;text-align: right;line-height: 26px;color: black;margin: 0;\\\"><span style=\\\"min-width: 1.5em;text-align: right;left: -2.5em;counter-increment: line;display: inline;color: rgba(0,0,0,0.3);\\\"><span>ounter(line</span></span></li><li style=\\\"list-style-type: none;text-align: right;line-height: 26px;color: black;margin: 0;\\\"><span style=\\\"min-width: 1.5em;text-align: right;left: -2.5em;counter-increment: line;display: inline;color: rgba(0,0,0,0.3);\\\"><span>ounter(line</span></span></li><li style=\\\"list-style-type: none;text-align: right;line-height: 26px;color: black;margin: 0;\\\"><span style=\\\"min-width: 1.5em;text-align: right;left: -2.5em;counter-increment: line;display: inline;color: rgba(0,0,0,0.3);\\\"><span>ounter(line</span></span></li></ul><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>测试连接</span></strong><span>：</span></p></span></li><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>点击 &quot;测试连接&quot;</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>确认连接成功后保存</span></span></li></ul></ol><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>使用 Cherry Studio</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建对话</span></div><div><span># 1. 点击 &quot;新建对话&quot;</span></div><div><span># 2. 选择已配置的本地模型</span></div><div><span># 3. 开始对话</span></div><div><span><br/></span></div><div><span># 知识库功能</span></div><div><span># 1. 点击 &quot;知识库&quot; 标签</span></div><div><span># 2. 创建新的知识库</span></div><div><span># 3. 上传文档（支持 PDF、TXT、MD 等格式）</span></div><div><span># 4. 在对话中引用知识库内容</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>高级功能</span></span></h3><h4 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:18px\\\"><span><span>1. 批量处理</span></span></h4><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># Cherry Studio 支持批量处理任务</span></div><div><span># 创建批量任务脚本</span></div><div><span>cat &gt; batch_process.py &lt;&lt; 'EOF'</span></div><div><span>import requests</span></div><div><span>import json</span></div><div><span><br/></span></div><div><span>def batch_process_with_cherry_studio(prompts, model=&quot;llama3.2:3b&quot;):</span></div><div><span>    &quot;&quot;&quot;批量处理多个提示&quot;&quot;&quot;</span></div><div><span>    results = []</span></div><div><span><br/></span></div><div><span>    for i, prompt in enumerate(prompts):</span></div><div><span>        print(f&quot;处理第 {i+1}/{len(prompts)} 个任务...&quot;)</span></div><div><span><br/></span></div><div><span>        # 通过 Ollama API 调用（Cherry Studio 使用相同接口）</span></div><div><span>        response = requests.post(&quot;http://localhost:11434/api/generate&quot;, json={</span></div><div><span>            &quot;model&quot;: model,</span></div><div><span>            &quot;prompt&quot;: prompt,</span></div><div><span>            &quot;stream&quot;: False</span></div><div><span>        })</span></div><div><span><br/></span></div><div><span>        if response.status_code == 200:</span></div><div><span>            result = response.json()[&quot;response&quot;]</span></div><div><span>            results.append({</span></div><div><span>                &quot;prompt&quot;: prompt,</span></div><div><span>                &quot;response&quot;: result</span></div><div><span>            })</span></div><div><span>        else:</span></div><div><span>            results.append({</span></div><div><span>                &quot;prompt&quot;: prompt,</span></div><div><span>                &quot;error&quot;: f&quot;请求失败: {response.status_code}&quot;</span></div><div><span>            })</span></div><div><span><br/></span></div><div><span>    return results</span></div><div><span><br/></span></div><div><span># 使用示例</span></div><div><span>prompts = [</span></div><div><span>    &quot;解释什么是机器学习&quot;,</span></div><div><span>    &quot;Python 和 JavaScript 的主要区别&quot;,</span></div><div><span>    &quot;如何优化网站性能&quot;</span></div><div><span>]</span></div><div><span><br/></span></div><div><span>results = batch_process_with_cherry_studio(prompts)</span></div><div><span>for result in results:</span></div><div><span>    print(f&quot;问题: {result['prompt']}&quot;)</span></div><div><span>    print(f&quot;回答: {result.get('response', result.get('error'))}&quot;)</span></div><div><span>    print(&quot;-&quot; * 50)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span>python batch_process.py</span></div></div></pre></span><h4 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:18px\\\"><span><span>2. 知识库 RAG 功能</span></span></h4><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建知识库增强生成脚本</span></div><div><span>cat &gt; rag_example.py &lt;&lt; 'EOF'</span></div><div><span>import os</span></div><div><span>import requests</span></div><div><span>from pathlib import Path</span></div><div><span><br/></span></div><div><span>class CherryStudioRAG:</span></div><div><span>    def __init__(self, base_url=&quot;http://localhost:11434&quot;):</span></div><div><span>        self.base_url = base_url</span></div><div><span>        self.knowledge_base = []</span></div><div><span><br/></span></div><div><span>    def add_document(self, file_path):</span></div><div><span>        &quot;&quot;&quot;添加文档到知识库&quot;&quot;&quot;</span></div><div><span>        if os.path.exists(file_path):</span></div><div><span>            with open(file_path, 'r', encoding='utf-8') as f:</span></div><div><span>                content = f.read()</span></div><div><span>                self.knowledge_base.append({</span></div><div><span>                    &quot;file&quot;: file_path,</span></div><div><span>                    &quot;content&quot;: content</span></div><div><span>                })</span></div><div><span>            print(f&quot;已添加文档: {file_path}&quot;)</span></div><div><span><br/></span></div><div><span>    def search_knowledge(self, query, max_results=3):</span></div><div><span>        &quot;&quot;&quot;在知识库中搜索相关内容&quot;&quot;&quot;</span></div><div><span>        # 简单的关键词匹配（实际应用中可使用更高级的向量搜索）</span></div><div><span>        results = []</span></div><div><span>        for doc in self.knowledge_base:</span></div><div><span>            if query.lower() in doc[&quot;content&quot;].lower():</span></div><div><span>                results.append(doc)</span></div><div><span>        return results[:max_results]</span></div><div><span><br/></span></div><div><span>    def rag_query(self, question, model=&quot;qwen2.5:7b&quot;):</span></div><div><span>        &quot;&quot;&quot;使用 RAG 回答问题&quot;&quot;&quot;</span></div><div><span>        # 搜索相关知识</span></div><div><span>        relevant_docs = self.search_knowledge(question)</span></div><div><span><br/></span></div><div><span>        # 构建增强提示</span></div><div><span>        context = &quot;&quot;</span></div><div><span>        if relevant_docs:</span></div><div><span>            context = &quot;参考资料:\\\\\n&quot;</span></div><div><span>            for doc in relevant_docs:</span></div><div><span>                context += f&quot;- {doc['file']}: {doc['content'][:200]}...\\\\\n&quot;</span></div><div><span><br/></span></div><div><span>        prompt = f&quot;&quot;&quot;</span></div><div><span>基于以下参考资料回答问题：</span></div><div><span><br/></span></div><div><span>{context}</span></div><div><span><br/></span></div><div><span>问题：{question}</span></div><div><span><br/></span></div><div><span>请基于参考资料提供准确的回答，如果参考资料中没有相关信息，请说明。</span></div><div><span>&quot;&quot;&quot;</span></div><div><span><br/></span></div><div><span>        response = requests.post(f&quot;{self.base_url}/api/generate&quot;, json={</span></div><div><span>            &quot;model&quot;: model,</span></div><div><span>            &quot;prompt&quot;: prompt,</span></div><div><span>            &quot;stream&quot;: False</span></div><div><span>        })</span></div><div><span><br/></span></div><div><span>        if response.status_code == 200:</span></div><div><span>            return response.json()[&quot;response&quot;]</span></div><div><span>        else:</span></div><div><span>            return f&quot;请求失败: {response.status_code}&quot;</span></div><div><span><br/></span></div><div><span># 使用示例</span></div><div><span>rag = CherryStudioRAG()</span></div><div><span><br/></span></div><div><span># 添加一些示例文档</span></div><div><span>rag.add_document(&quot;README.md&quot;)  # 如果存在的话</span></div><div><span>rag.add_document(&quot;docs/api.md&quot;)  # 如果存在的话</span></div><div><span><br/></span></div><div><span># 进行 RAG 查询</span></div><div><span>answer = rag.rag_query(&quot;如何安装这个项目？&quot;)</span></div><div><span>print(f&quot;回答: {answer}&quot;)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span>python rag_example.py</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>Cherry Studio 优缺点</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>优点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>现代化的用户界面，操作直观</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持多种模型服务（本地和云端）</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>内置知识库和 RAG 功能</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>开源免费，社区活跃</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>支持批量处理和自动化</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>多平台支持（Windows、macOS、Linux）</span></span></li></ul><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>缺点：</span></strong></p><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>相对较新，功能还在完善中</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>需要额外学习界面操作</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>依赖外部模型服务（如 Ollama）</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>知识库功能相对简单</span></span></li></ul><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>方法七：从源码编译部署（高级用户）</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>对于需要最大自定义能力的高级用户，可以从源码编译部署。</span></p><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>编译 llama.cpp</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 安装编译依赖</span></div><div><span>brew install cmake pkg-config</span></div><div><span><br/></span></div><div><span># 克隆源码</span></div><div><span>git clone https://github.com/ggerganov/llama.cpp.git</span></div><div><span>cd llama.cpp</span></div><div><span><br/></span></div><div><span># 编译（启用 Metal 支持）</span></div><div><span>make clean</span></div><div><span>make -j8 LLAMA_METAL=1</span></div><div><span><br/></span></div><div><span># 或使用 CMake</span></div><div><span>mkdir build &amp;&amp; cd build</span></div><div><span>cmake .. -DLLAMA_METAL=ON</span></div><div><span>make -j8</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>模型转换和量化</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 安装 Python 依赖</span></div><div><span>pip install torch torchvision torchaudio</span></div><div><span>pip install transformers sentencepiece protobuf</span></div><div><span><br/></span></div><div><span># 下载原始模型（需要申请访问权限）</span></div><div><span># 这里以 Llama 2 为例</span></div><div><span>git clone https://huggingface.co/meta-llama/Llama-2-7b-chat-hf</span></div><div><span><br/></span></div><div><span># 转换为 GGUF 格式</span></div><div><span>python convert.py ./Llama-2-7b-chat-hf --outdir ./models --outtype f16</span></div><div><span><br/></span></div><div><span># 量化模型</span></div><div><span>./quantize ./models/ggml-model-f16.gguf ./models/ggml-model-q4_0.gguf q4_0</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>运行自定义服务</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 运行模型</span></div><div><span>./server \\\\</span></div><div><span>  -m ./models/ggml-model-q4_0.gguf \\\\</span></div><div><span>  -c 4096 \\\\</span></div><div><span>  -b 1024 \\\\</span></div><div><span>  -t 8 \\\\</span></div><div><span>  --port 8080 \\\\</span></div><div><span>  --host 0.0.0.0</span></div><div><span><br/></span></div><div><span># 使用 Metal GPU 加速</span></div><div><span>./server \\\\</span></div><div><span>  -m ./models/ggml-model-q4_0.gguf \\\\</span></div><div><span>  -ngl 32 \\\\</span></div><div><span>  -c 4096 \\\\</span></div><div><span>  -b 1024 \\\\</span></div><div><span>  -t 8 \\\\</span></div><div><span>  --port 8080 \\\\</span></div><div><span>  --host 0.0.0.0</span></div></div></pre></span><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>性能优化和监控</span></span><span></span></h2><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>系统性能监控</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建性能监控脚本</span></div><div><span>cat &gt; monitor_system.sh &lt;&lt; 'EOF'</span></div><div><span>#!/bin/bash</span></div><div><span><br/></span></div><div><span>echo &quot;Mac mini 大模型性能监控&quot;</span></div><div><span>echo &quot;========================&quot;</span></div><div><span><br/></span></div><div><span>while true; do</span></div><div><span>    echo &quot;时间: $(date)&quot;</span></div><div><span>    echo &quot;CPU 使用率:&quot;</span></div><div><span>    top -l 1 | grep &quot;CPU usage&quot;</span></div><div><span><br/></span></div><div><span>    echo &quot;内存使用情况:&quot;</span></div><div><span>    vm_stat | head -5</span></div><div><span><br/></span></div><div><span>    echo &quot;GPU 使用情况:&quot;</span></div><div><span>    sudo powermetrics -n 1 -i 1000 --samplers gpu_power | grep &quot;GPU&quot;</span></div><div><span><br/></span></div><div><span>    echo &quot;温度监控:&quot;</span></div><div><span>    sudo powermetrics -n 1 -i 1000 --samplers smc | grep -i temp | head -3</span></div><div><span><br/></span></div><div><span>    echo &quot;========================&quot;</span></div><div><span>    sleep 10</span></div><div><span>done</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span>chmod +x monitor_system.sh</span></div><div><span>./monitor_system.sh</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>内存优化建议</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 清理系统缓存</span></div><div><span>sudo purge</span></div><div><span><br/></span></div><div><span># 关闭不必要的应用</span></div><div><span>killall &quot;Google Chrome&quot;</span></div><div><span>killall &quot;Slack&quot;</span></div><div><span>killall &quot;Zoom&quot;</span></div><div><span><br/></span></div><div><span># 设置内存压缩</span></div><div><span>sudo sysctl vm.compressor_mode=4</span></div><div><span><br/></span></div><div><span># 查看内存压力</span></div><div><span>memory_pressure</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>模型选择建议</span></span></h3><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>根据不同内存配置的推荐模型：</span></p><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 8GB 内存配置</span></div><div><span>cat &gt; models_8gb.txt &lt;&lt; 'EOF'</span></div><div><span>推荐模型（8GB 内存）：</span></div><div><span>- Llama 3.2 3B Instruct (Q4_K_M) - 约 2.3GB</span></div><div><span>- Phi-3 Mini 4K (Q4_K_M) - 约 2.4GB</span></div><div><span>- Gemma 2 2B (Q4_K_M) - 约 1.6GB</span></div><div><span>- TinyLlama 1.1B (Q5_K_M) - 约 800MB</span></div><div><span>- Qwen2.5 3B (Q4_K_M) - 约 2.0GB</span></div><div><span><br/></span></div><div><span>注意：保留至少 4GB 内存给系统使用</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span># 16GB 内存配置</span></div><div><span>cat &gt; models_16gb.txt &lt;&lt; 'EOF'</span></div><div><span>推荐模型（16GB 内存）：</span></div><div><span>- Llama 3.1 8B Instruct (Q4_K_M) - 约 4.9GB</span></div><div><span>- Mistral 7B Instruct (Q4_K_M) - 约 4.1GB</span></div><div><span>- CodeLlama 7B (Q4_K_M) - 约 4.1GB</span></div><div><span>- Qwen2.5 7B (Q4_K_M) - 约 4.2GB</span></div><div><span>- Yi 6B Chat (Q5_K_M) - 约 4.8GB</span></div><div><span><br/></span></div><div><span>可以同时运行多个小模型或一个大模型</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span># 24GB+ 内存配置</span></div><div><span>cat &gt; models_24gb.txt &lt;&lt; 'EOF'</span></div><div><span>推荐模型（24GB+ 内存）：</span></div><div><span>- Llama 3.1 8B Instruct (Q6_K) - 约 6.6GB</span></div><div><span>- Mixtral 8x7B Instruct (Q4_K_M) - 约 26GB</span></div><div><span>- CodeLlama 13B (Q4_K_M) - 约 7.9GB</span></div><div><span>- Qwen2.5 14B (Q4_K_M) - 约 8.5GB</span></div><div><span>- DeepSeek Coder 6.7B (Q5_K_M) - 约 5.2GB</span></div><div><span><br/></span></div><div><span>可以运行更大的模型或多个模型并行</span></div><div><span>EOF</span></div></div></pre></span><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>常见问题和故障排除</span></span><span></span></h2><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>问题1：内存不足</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 症状：模型加载失败或运行缓慢</span></div><div><span># 解决方案：</span></div><div><span><br/></span></div><div><span># 1. 选择更小的模型</span></div><div><span>ollama pull llama3.2:1b  # 而不是 llama3.2:8b</span></div><div><span><br/></span></div><div><span># 2. 使用更激进的量化</span></div><div><span># Q2_K &lt; Q3_K_S &lt; Q4_K_S &lt; Q4_K_M &lt; Q5_K_S &lt; Q5_K_M &lt; Q6_K &lt; Q8_0 &lt; F16</span></div><div><span><br/></span></div><div><span># 3. 减少上下文长度</span></div><div><span>./server -m model.gguf -c 2048  # 而不是 4096</span></div><div><span><br/></span></div><div><span># 4. 清理内存</span></div><div><span>sudo purge</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>问题2：推理速度慢</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 症状：生成文本速度很慢</span></div><div><span># 解决方案：</span></div><div><span><br/></span></div><div><span># 1. 启用 GPU 加速</span></div><div><span>ollama run llama3.2:3b  # Ollama 自动启用</span></div><div><span>./server -m model.gguf -ngl 32  # llama.cpp 启用 Metal</span></div><div><span><br/></span></div><div><span># 2. 调整批处理大小</span></div><div><span>./server -m model.gguf -b 1024  # 增加批处理大小</span></div><div><span><br/></span></div><div><span># 3. 使用更多 CPU 线程</span></div><div><span>./server -m model.gguf -t 8  # 使用 8 个线程</span></div><div><span><br/></span></div><div><span># 4. 启用内存映射</span></div><div><span>./server -m model.gguf --mmap</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>问题3：模型输出质量差</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 症状：回答不准确或重复</span></div><div><span># 解决方案：</span></div><div><span><br/></span></div><div><span># 1. 调整温度参数</span></div><div><span>curl -X POST http://localhost:11434/api/generate \\\\</span></div><div><span>  -d '{&quot;model&quot;: &quot;llama3.2:3b&quot;, &quot;prompt&quot;: &quot;你好&quot;, &quot;temperature&quot;: 0.7}'</span></div><div><span><br/></span></div><div><span># 2. 调整 top-p 参数</span></div><div><span>curl -X POST http://localhost:11434/api/generate \\\\</span></div><div><span>  -d '{&quot;model&quot;: &quot;llama3.2:3b&quot;, &quot;prompt&quot;: &quot;你好&quot;, &quot;top_p&quot;: 0.9}'</span></div><div><span><br/></span></div><div><span># 3. 使用更好的提示词</span></div><div><span># 不好的提示：</span></div><div><span>&quot;写一篇文章&quot;</span></div><div><span><br/></span></div><div><span># 好的提示：</span></div><div><span>&quot;请写一篇关于人工智能在医疗领域应用的 800 字文章，包括现状、挑战和未来发展方向。&quot;</span></div><div><span><br/></span></div><div><span># 4. 尝试不同的模型</span></div><div><span>ollama pull qwen2.5:7b  # 中文效果更好</span></div><div><span>ollama pull codellama:7b  # 代码生成更好</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>问题4：网络连接问题</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 症状：无法下载模型</span></div><div><span># 解决方案：</span></div><div><span><br/></span></div><div><span># 1. 使用代理</span></div><div><span>export https_proxy=http://127.0.0.1:7890</span></div><div><span>export http_proxy=http://127.0.0.1:7890</span></div><div><span>ollama pull llama3.2:3b</span></div><div><span><br/></span></div><div><span># 2. 使用镜像源</span></div><div><span># 修改 Ollama 配置</span></div><div><span>export OLLAMA_HOST=0.0.0.0:11434</span></div><div><span><br/></span></div><div><span># 3. 手动下载模型文件</span></div><div><span>wget https://huggingface.co/microsoft/DialoGPT-medium/resolve/main/pytorch_model.bin</span></div><div><span><br/></span></div><div><span># 4. 使用离线模型</span></div><div><span># 从其他机器复制模型文件到 ~/.ollama/models/</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>问题5：服务无法启动</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 症状：端口被占用或权限问题</span></div><div><span># 解决方案：</span></div><div><span><br/></span></div><div><span># 1. 检查端口占用</span></div><div><span>lsof -i :11434</span></div><div><span>kill -9 &lt;PID&gt;</span></div><div><span><br/></span></div><div><span># 2. 使用不同端口</span></div><div><span>ollama serve --port 11435</span></div><div><span><br/></span></div><div><span># 3. 检查权限</span></div><div><span>sudo chown -R $(whoami) ~/.ollama</span></div><div><span><br/></span></div><div><span># 4. 重置 Ollama</span></div><div><span>rm -rf ~/.ollama</span></div><div><span>ollama serve</span></div></div></pre></span><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>实用应用场景</span></span><span></span></h2><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>场景1：个人知识助手</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建知识库助手</span></div><div><span>cat &gt; knowledge_assistant.py &lt;&lt; 'EOF'</span></div><div><span>import requests</span></div><div><span>import json</span></div><div><span>import os</span></div><div><span>from datetime import datetime</span></div><div><span><br/></span></div><div><span>class KnowledgeAssistant:</span></div><div><span>    def __init__(self, base_url=&quot;http://localhost:11434&quot;):</span></div><div><span>        self.base_url = base_url</span></div><div><span>        self.conversation_history = []</span></div><div><span><br/></span></div><div><span>    def ask(self, question, model=&quot;llama3.2:3b&quot;):</span></div><div><span>        &quot;&quot;&quot;向模型提问&quot;&quot;&quot;</span></div><div><span>        prompt = f&quot;&quot;&quot;</span></div><div><span>你是一个专业的知识助手。请基于以下对话历史回答问题：</span></div><div><span><br/></span></div><div><span>对话历史：</span></div><div><span>{self._format_history()}</span></div><div><span><br/></span></div><div><span>当前问题：{question}</span></div><div><span><br/></span></div><div><span>请提供准确、有用的回答：</span></div><div><span>&quot;&quot;&quot;</span></div><div><span><br/></span></div><div><span>        response = requests.post(f&quot;{self.base_url}/api/generate&quot;, json={</span></div><div><span>            &quot;model&quot;: model,</span></div><div><span>            &quot;prompt&quot;: prompt,</span></div><div><span>            &quot;stream&quot;: False,</span></div><div><span>            &quot;temperature&quot;: 0.7</span></div><div><span>        })</span></div><div><span><br/></span></div><div><span>        if response.status_code == 200:</span></div><div><span>            answer = response.json()[&quot;response&quot;]</span></div><div><span>            self.conversation_history.append({</span></div><div><span>                &quot;timestamp&quot;: datetime.now().isoformat(),</span></div><div><span>                &quot;question&quot;: question,</span></div><div><span>                &quot;answer&quot;: answer</span></div><div><span>            })</span></div><div><span>            return answer</span></div><div><span>        else:</span></div><div><span>            return f&quot;错误：{response.status_code}&quot;</span></div><div><span><br/></span></div><div><span>    def _format_history(self):</span></div><div><span>        &quot;&quot;&quot;格式化对话历史&quot;&quot;&quot;</span></div><div><span>        if not self.conversation_history:</span></div><div><span>            return &quot;无历史对话&quot;</span></div><div><span><br/></span></div><div><span>        history = []</span></div><div><span>        for item in self.conversation_history[-5:]:  # 只保留最近5轮对话</span></div><div><span>            history.append(f&quot;Q: {item['question']}&quot;)</span></div><div><span>            history.append(f&quot;A: {item['answer']}&quot;)</span></div><div><span><br/></span></div><div><span>        return &quot;\\\\\n&quot;.join(history)</span></div><div><span><br/></span></div><div><span>    def save_conversation(self, filename=&quot;conversation.json&quot;):</span></div><div><span>        &quot;&quot;&quot;保存对话历史&quot;&quot;&quot;</span></div><div><span>        with open(filename, 'w', encoding='utf-8') as f:</span></div><div><span>            json.dump(self.conversation_history, f, ensure_ascii=False, indent=2)</span></div><div><span><br/></span></div><div><span>    def load_conversation(self, filename=&quot;conversation.json&quot;):</span></div><div><span>        &quot;&quot;&quot;加载对话历史&quot;&quot;&quot;</span></div><div><span>        if os.path.exists(filename):</span></div><div><span>            with open(filename, 'r', encoding='utf-8') as f:</span></div><div><span>                self.conversation_history = json.load(f)</span></div><div><span><br/></span></div><div><span># 使用示例</span></div><div><span>if __name__ == &quot;__main__&quot;:</span></div><div><span>    assistant = KnowledgeAssistant()</span></div><div><span>    assistant.load_conversation()</span></div><div><span><br/></span></div><div><span>    print(&quot;知识助手已启动！输入 'quit' 退出。&quot;)</span></div><div><span><br/></span></div><div><span>    while True:</span></div><div><span>        question = input(&quot;\\\\\n你的问题: &quot;)</span></div><div><span>        if question.lower() in ['quit', 'exit', '退出']:</span></div><div><span>            assistant.save_conversation()</span></div><div><span>            print(&quot;对话已保存，再见！&quot;)</span></div><div><span>            break</span></div><div><span><br/></span></div><div><span>        answer = assistant.ask(question)</span></div><div><span>        print(f&quot;\\\\\n助手: {answer}&quot;)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span>python knowledge_assistant.py</span></div></div></pre></span><h3 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:20px\\\"><span><span>场景2：代码审查助手</span></span></h3><span style=\\\"\\\"><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line</span><div><span># 创建代码审查助手</span></div><div><span>cat &gt; code_reviewer.py &lt;&lt; 'EOF'</span></div><div><span>import requests</span></div><div><span>import os</span></div><div><span>import sys</span></div><div><span><br/></span></div><div><span>class CodeReviewer:</span></div><div><span>    def __init__(self, base_url=&quot;http://localhost:11434&quot;):</span></div><div><span>        self.base_url = base_url</span></div><div><span>        self.model = &quot;codellama:7b&quot;</span></div><div><span><br/></span></div><div><span>    def review_file(self, file_path):</span></div><div><span>        &quot;&quot;&quot;审查单个文件&quot;&quot;&quot;</span></div><div><span>        if not os.path.exists(file_path):</span></div><div><span>            return f&quot;文件不存在: {file_path}&quot;</span></div><div><span><br/></span></div><div><span>        with open(file_path, 'r', encoding='utf-8') as f:</span></div><div><span>            code = f.read()</span></div><div><span><br/></span></div><div><span>        prompt = f&quot;&quot;&quot;</span></div><div><span>请作为一个资深的代码审查员，审查以下代码：</span></div><div><span><br/></span></div><div><span>文件路径：{file_path}</span></div><div><span>代码内容：</span></div><div><span>```python</span></div><div><span>{code}</span></div><div><span>\\\\```</span></div><div><span><br/></span></div><div><span>请从以下方面进行审查：</span></div><div><span><br/></span></div><div><span>1. 代码质量和可读性</span></div><div><span>2. 潜在的 bug 和安全问题</span></div><div><span>3. 性能优化建议</span></div><div><span>4. 最佳实践建议</span></div><div><span>5. 代码风格问题</span></div><div><span><br/></span></div><div><span>请提供具体的改进建议：</span></div><div><span>&quot;&quot;&quot;</span></div><div><span>response = requests.post(f&quot;{self.base_url}/api/generate&quot;, json={</span></div><div><span>    &quot;model&quot;: self.model,</span></div><div><span>    &quot;prompt&quot;: prompt,</span></div><div><span>    &quot;stream&quot;: False,</span></div><div><span>    &quot;temperature&quot;: 0.3</span></div><div><span>})</span></div><div><span><br/></span></div><div><span>if response.status_code == 200:</span></div><div><span>    return response.json()[&quot;response&quot;]</span></div><div><span>else:</span></div><div><span>    return f&quot;请求失败: {response.status_code}&quot;</span></div><div><span><br/></span></div><div><span># 使用示例</span></div><div><span>if __name__ == &quot;__main__&quot;:</span></div><div><span>    reviewer = CodeReviewer()</span></div><div><span><br/></span></div><div><span>    if len(sys.argv) &lt; 2:</span></div><div><span>        print(&quot;使用方法: python code_reviewer.py &lt;文件路径&gt;&quot;)</span></div><div><span>        sys.exit(1)</span></div><div><span><br/></span></div><div><span>    file_path = sys.argv[1]</span></div><div><span>    result = reviewer.review_file(file_path)</span></div><div><span>    print(f&quot;\\\\\n审查结果:\\\\\n{result}&quot;)</span></div><div><span>EOF</span></div><div><span><br/></span></div><div><span># 使用示例</span></div><div><span>python code_reviewer.py ./my_script.py</span></div></div></pre></span><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>总结</span></span><span></span></h2><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>本文介绍了在 Mac mini 上部署大模型的 7 种方法：</span></p><ol style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:decimal\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>Ollama</span></strong><span>：最简单易用，适合初学者</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>LM Studio</span></strong><span>：图形化界面，适合不熟悉命令行的用户</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>llamafile</span></strong><span>：单文件部署，适合快速测试</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>MLX</span></strong><span>：Apple Silicon 专用优化，适合追求性能的用户</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>Docker</span></strong><span>：容器化部署，适合生产环境</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>Cherry Studio</span></strong><span>：开源 AI 客户端，支持知识库和 RAG 功能</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><strong style=\\\"font-weight: bold;color: black;\\\"><span>源码编译</span></strong><span>：最大自定义能力，适合高级用户</span></span></li></ol><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>每种方法都有其优缺点，你可以根据自己的需求和技术水平选择合适的方案。对于大多数用户，我推荐从 Ollama 开始，它提供了最好的易用性和功能平衡。</span></p><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;line-height:26px;color:black\\\"><span>随着大模型技术的不断发展，本地部署将变得越来越重要。Mac mini 凭借其出色的性能和能效比，是个人和小团队部署大模型的理想选择。希望这篇文章能帮助你成功在 Mac mini 上部署属于自己的大模型！</span></p><h2 style=\\\"margin:0;margin-top:30px;margin-bottom:15px;font-weight:bold;color:black;font-size:22px\\\"><span><span>参考资源</span></span><span></span></h2><ul style=\\\"margin:0;margin-top:8px;margin-bottom:8px;padding-left:25px;color:black;list-style-type:disc\\\"><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>Ollama 官网</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>LM Studio 官网</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>llamafile 项目</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>MLX 框架</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>llama.cpp 项目</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>Hugging Face 模型库</span></span></li><li><span style=\\\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;text-align: left;color: rgb(1,1,1);font-weight: 500;\\\"><span>Cherry Studio 官网</span></span></li></ul><hr style=\\\"height: 1px;margin: 0;margin-top: 10px;margin-bottom: 10px;border: none;border-top: 1px solid black;\\\"/><blockquote style=\\\"display: block;font-size: 0.9em;overflow: auto;overflow-scrolling: touch;border-left: 3px solid rgba(0, 0, 0, 0.4);background: rgba(0, 0, 0, 0.05);color: #6a737d;padding-top: 10px;padding-bottom: 10px;padding-left: 20px;padding-right: 10px;margin-bottom: 20px;margin-top: 20px;\\\"><p style=\\\"font-size:16px;padding-top:8px;padding-bottom:8px;margin:0;color:black;line-height:26px\\\"><span>💡 </span><strong style=\\\"font-weight: bold;color: black;\\\"><span>提示</span></strong><span>：如果你在部署过程中遇到问题，可以参考文章中的故障排除部分，或者在评论区留言讨论。</span></p></blockquote></span></div></div><div><div><div><div style=\\\"display:flex;\\\"><a>阅读原文</a></div></div></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":112114}]"
metadata_diff: {"new":{"id":"1453b5b3e2f748e1b56e431db2116508","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345739415,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:12:49.029Z
created_time: 2025-11-28T16:12:49.029Z
type_: 13