<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>AI 工程实践 on Harry AI</title><link>https://harryai.cc/categories/ai-%E5%B7%A5%E7%A8%8B%E5%AE%9E%E8%B7%B5/</link><description>Recent content in AI 工程实践 on Harry AI</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>harryliuwx888@gmail.com (Harry)</managingEditor><webMaster>harryliuwx888@gmail.com (Harry)</webMaster><copyright>Copyright © 深圳市网旭科技有限公司。&lt;a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备14077691号&lt;/a></copyright><lastBuildDate>Sat, 03 Aug 2024 12:30:01 +0800</lastBuildDate><atom:link href="https://harryai.cc/categories/ai-%E5%B7%A5%E7%A8%8B%E5%AE%9E%E8%B7%B5/index.xml" rel="self" type="application/rss+xml"/><item><title>阿里开源 CosyVoice 语音克隆 部署和使用</title><link>https://harryai.cc/post/cosyvoice/</link><pubDate>Sat, 03 Aug 2024 12:30:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/cosyvoice/</guid><description>&lt;p>应该是 &lt;strong>开源界 音色 最稳定&lt;/strong> 的语音合成和克隆模型了，支持预训练音色合成、自然语言控制、3秒极速复刻和跨语种复刻。&lt;/p>
&lt;p>官方部署方式比较复杂，错误较多，我这里进行了整理和优化，&lt;strong>支持GPU和CPU&lt;/strong>，方便大家使用。&lt;/p>
&lt;p>CosyVoice 开源仓库: &lt;a href="https://github.com/FunAudioLLM/CosyVoice">CosyVoice&lt;/a>&lt;/p>
&lt;h2 id="效果展示">效果展示&lt;/h2>
&lt;h3 id="自然语言控制">自然语言控制&lt;/h3>
&lt;img src="https://harryai.cc/post/cosyvoice/1.jpg" alt="image" class="center" width="600">&lt;h3 id="3秒极速复刻">3秒极速复刻&lt;/h3>
&lt;img src="https://harryai.cc/post/cosyvoice/2.jpg" alt="image" class="center" width="600">&lt;h2 id="使用方法">使用方法&lt;/h2>
&lt;blockquote>
&lt;p>均支持 GPU 和 CPU&lt;/p>
&lt;p>第一次启动过程可能会有点长，需要从魔搭下载3个模型&lt;/p>&lt;/blockquote>
&lt;h3 id="windows-一键启动包">Windows 一键启动包&lt;/h3>
&lt;p>百度网盘: &lt;a href="https://pan.baidu.com/s/1UTuRKPQ9nuQk69qxQzdL4A?pwd=j2ei">https://pan.baidu.com/s/1UTuRKPQ9nuQk69qxQzdL4A?pwd=j2ei&lt;/a> 提取码: j2ei&lt;/p>
&lt;ul>
&lt;li>下载后使用 7z 解压。没有 7z 的话，可以在这里下载：&lt;a href="https://7-zip.org/download.html">https://7-zip.org/download.html&lt;/a>&lt;/li>
&lt;li>双击 &lt;code>双击启动.bat&lt;/code> 启动服务&lt;/li>
&lt;li>启动后，访问 &lt;a href="http://127.0.0.1:50000/">http://127.0.0.1:50000/&lt;/a>&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>注意：文件夹中不能有 &lt;strong>中文&lt;/strong>、&lt;strong>特殊字符&lt;/strong>和&lt;strong>空格&lt;/strong>，否则可能会启动失败&lt;/p>&lt;/blockquote>
&lt;h3 id="docker部署">Docker部署🐳&lt;/h3>
&lt;blockquote>
&lt;p>确保已经安装了Docker软件，没有的话，从官网下载安装 &lt;a href="https://www.docker.com/products/docker-desktop/">https://www.docker.com/products/docker-desktop/&lt;/a>&lt;/p>&lt;/blockquote>
&lt;p>复制以下代码到终端运行即可&lt;/p>
&lt;h4 id="cpu-版本">CPU 版本&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl -fsSL https://harryai.cc/cosyvoice/docker-compose.yml -o docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="gpu-版本">GPU 版本&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl -fsSL https://harryai.cc/cosyvoice/docker-compose-gpu.yml -o docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>docker 启动后，访问 &lt;a href="http://127.0.0.1:50000/">http://127.0.0.1:50000/&lt;/a>&lt;/strong>&lt;/p></description></item><item><title>FunASR实时语音识别部署和使用</title><link>https://harryai.cc/post/realtime-funasr/</link><pubDate>Thu, 25 Jul 2024 20:30:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/realtime-funasr/</guid><description>&lt;p>FunASR 模型的整理和集成，Docker一键启动，能够&lt;strong>实时识别语音&lt;/strong>输入，准确度非常高&lt;/p>
&lt;p>项目地址：&lt;a href="https://github.com/harry0703/AudioNotes">https://github.com/harry0703/AudioNotes&lt;/a>&lt;/p>
&lt;p>FunASR开源仓库: &lt;a href="http://localhost:15433/">https://github.com/modelscope/FunASR&lt;/a>&lt;/p>
&lt;h2 id="效果展示">效果展示&lt;/h2>
&lt;img src="https://harryai.cc/post/realtime-funasr/1.jpg" alt="image">&lt;h2 id="使用方法">使用方法&lt;/h2>
&lt;h3 id="docker部署">Docker部署🐳&lt;/h3>
&lt;blockquote>
&lt;p>确保已经安装了Docker软件，没有的话，从官网下载安装 &lt;a href="https://www.docker.com/products/docker-desktop/">https://www.docker.com/products/docker-desktop/&lt;/a>&lt;/p>&lt;/blockquote>
&lt;p>复制以下代码到终端运行即可&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl -fsSL https://harryai.cc/realtime-funasr/docker-compose.yml -o docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;blockquote>
&lt;p>注意：第一次启动过程可能会有点长，需要从魔搭下载4个模型&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://www.modelscope.cn/models/damo/speech_fsmn_vad_zh-cn-16k-common-onnx/summary">FSMN-VAD模型&lt;/a>,&lt;/li>
&lt;li>&lt;a href="https://www.modelscope.cn/models/damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online-onnx/summary">Paraformer-lagre实时模型&lt;/a>,&lt;/li>
&lt;li>&lt;a href="https://www.modelscope.cn/models/damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727-onnx/summary">CT-Transformer标点预测模型&lt;/a>,&lt;/li>
&lt;li>&lt;a href="https://www.modelscope.cn/models/thuduj12/fst_itn_zh/summary">基于FST的中文ITN&lt;/a>&lt;/li>
&lt;/ul>&lt;/blockquote>
&lt;p>&lt;strong>docker 启动后，访问 &lt;a href="http://localhost:10096/">http://localhost:10096/&lt;/a>&lt;/strong>&lt;/p>
&lt;h2 id="-如果你想了解更多可以往下看">👉👉 如果你想了解更多，可以往下看&lt;/h2>
&lt;h3 id="参数说明">参数说明&lt;/h3>
&lt;h4 id="-模型模式">① 模型模式&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>2pass&lt;/strong>: （默认）实时语音识别，并且句尾采用离线模型进行纠错（&lt;strong>准确度更高&lt;/strong>）&lt;/li>
&lt;li>online: 实时语音识别&lt;/li>
&lt;li>offline: 一句话识别&lt;/li>
&lt;/ul>
&lt;h4 id="-逆文本标准化itn">② 逆文本标准化（ITN）&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>是&lt;/strong>: （默认） 表示进行逆文本标准化&lt;/li>
&lt;li>否: 表示不进行逆文本标准化&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>逆文本标准化（Inverse Text Normalization, ITN）&lt;/strong> 是语音识别和自然语言处理领域的一种技术，用于将自动语音识别（ASR）系统生成的文本转化为更自然和可读的格式。这是对文本标准化（Text
Normalization, TN）的逆过程。&lt;/p>
&lt;p>&lt;strong>逆文本标准化的目的&lt;/strong>&lt;/p>
&lt;p>当语音被转换为文本时，ASR 系统通常会输出一种更标准化的文本形式。例如：&lt;/p>
&lt;ul>
&lt;li>数字 &amp;ldquo;123&amp;rdquo; 可能会被识别为 &amp;ldquo;一二三&amp;rdquo; 或 &amp;ldquo;123&amp;rdquo;。&lt;/li>
&lt;li>日期 &amp;ldquo;2024年7月25日&amp;rdquo; 可能会被识别为 &amp;ldquo;二零二四年七月二十五日&amp;rdquo; 或 &amp;ldquo;2024年7月25日&amp;rdquo;。&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>这些输出虽然标准化，但不一定是人们习惯书写或阅读的格式。&lt;/strong>
ITN 的作用是将这些标准化的文本转换回更自然、更符合书面习惯的形式。例如：&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;一二三&amp;rdquo; 转换为 &amp;ldquo;123&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;二零二四年七月二十五日&amp;rdquo; 转换为 &amp;ldquo;2024年7月25日&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;五千七百六十三&amp;rdquo; 转换为 &amp;ldquo;5763&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;h2 id="如果你想使用api请参考以下文档">👉👉如果你想使用API，请参考以下文档&lt;/h2>
&lt;h3 id="系统架构图">系统架构图&lt;/h3>
&lt;img src="https://harryai.cc/post/realtime-funasr/2.jpg" alt="image">&lt;blockquote>
&lt;p>注意：&lt;/p>
&lt;ol>
&lt;li>10096端口为网页界面&lt;/li>
&lt;li>10095端口为websocket通信端口
&amp;gt; &lt;img src="https://harryai.cc/post/realtime-funasr/3.jpg" alt="image">&lt;/li>
&lt;/ol>&lt;/blockquote>
&lt;h3 id="-从客户端往服务端发送数据">🅰️ 从客户端往服务端发送数据&lt;/h3>
&lt;h4 id="消息格式">消息格式&lt;/h4>
&lt;p>配置参数用&lt;code>json&lt;/code>，音频数据采用&lt;code>bytes&lt;/code>&lt;/p>
&lt;h4 id="-首次通信">① 首次通信&lt;/h4>
&lt;p>客户端发送配置参数&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-12">12&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-13">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-13">13&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-14">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-14">14&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;chunk_size&amp;#34;&lt;/span>: [
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#ae81ff">5&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#ae81ff">10&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#ae81ff">5&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ],
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;wav_name&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;h5&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;is_speaking&amp;#34;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;wav_format&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;pcm&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;chunk_interval&amp;#34;&lt;/span>: &lt;span style="color:#ae81ff">10&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;itn&amp;#34;&lt;/span>: &lt;span style="color:#66d9ef">true&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;mode&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;2pass&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;hotwords&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;{\&amp;#34;阿里巴巴\&amp;#34;:20,\&amp;#34;hello world\&amp;#34;:40}&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>参数说明：&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>wav_name&lt;/code>：表示需要推理音频文件名&lt;/li>
&lt;li>&lt;code>wav_format&lt;/code>：表示音视频文件后缀名，只支持pcm音频流&lt;/li>
&lt;li>&lt;code>is_speaking&lt;/code>：表示断句尾点，例如，vad切割点，或者一条wav结束&lt;/li>
&lt;li>&lt;code>chunk_size&lt;/code>：表示流式模型latency配置，&lt;code>[5,10,5]&lt;/code>，表示当前音频为600ms，并且回看300ms，又看300ms。&lt;/li>
&lt;li>&lt;code>hotwords&lt;/code>：如果使用热词，需要向服务端发送热词数据（字符串），格式为 &amp;ldquo;{&amp;ldquo;阿里巴巴&amp;rdquo;:20,&amp;ldquo;通义实验室&amp;rdquo;:30}&amp;rdquo;&lt;/li>
&lt;li>&lt;code>itn&lt;/code>: 设置是否使用itn，默认 &lt;code>true&lt;/code>&lt;/li>
&lt;/ul>
&lt;h4 id="-发送音频数据">② 发送音频数据&lt;/h4>
&lt;p>直接将音频数据移除头部信息后，使用 bytes 数据发送，支持音频采样率为8000&lt;/p>
&lt;h4 id="-发送结束标志">③ 发送结束标志&lt;/h4>
&lt;p>音频数据发送结束后，需要发送结束标志&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3">3&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;is_speaking&amp;#34;&lt;/span>: &lt;span style="color:#66d9ef">false&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="-从服务端往客户端发数据">🅱️ 从服务端往客户端发数据&lt;/h3>
&lt;h4 id="发送识别结果">发送识别结果&lt;/h4>
&lt;p>识别中&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6">6&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;is_final&amp;#34;&lt;/span>: &lt;span style="color:#66d9ef">false&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;mode&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;2pass-online&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;text&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;阿里&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;wav_name&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;h5&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>识别结束&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-12">12&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-13">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-13">13&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-14">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-14">14&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-15">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-15">15&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;is_final&amp;#34;&lt;/span>: &lt;span style="color:#66d9ef">false&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;mode&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;2pass-offline&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;stamp_sents&amp;#34;&lt;/span>: [
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;end&amp;#34;&lt;/span>: &lt;span style="color:#ae81ff">4385&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;punc&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;start&amp;#34;&lt;/span>: &lt;span style="color:#ae81ff">820&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;text_seg&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;阿 里 开 源 的 语 音 识 别 真 是 太 牛 了&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ],
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;text&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;阿里开源的语音识别真是太牛了&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;timestamp&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;[[820,1060],[1060,1319],[1319,1480],[1480,1760],[1760,2220],[2220,2420],[2420,2659],[2659,2820],[2820,3300],[3300,3480],[3480,3659],[3659,3820],[3820,4060],[4060,4385]]&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;wav_name&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;h5&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>参数说明：&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>mode&lt;/code>：推理模式
&lt;ul>
&lt;li>2pass-online：表示实时识别结果&lt;/li>
&lt;li>2pass-offline：表示2遍修正识别结果&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;code>wav_name&lt;/code>：需要推理音频文件名&lt;/li>
&lt;li>&lt;code>text&lt;/code>：语音识别输出文本&lt;/li>
&lt;/ul>
&lt;h2 id="踩坑">👉👉踩坑&lt;/h2>
&lt;h3 id="报错录音open失败浏览器禁止不安全页面录音">报错：录音open失败：浏览器禁止不安全页面录音&lt;/h3>
&lt;p>如果你是在&lt;strong>其他电脑或服务器上部署的服务，而不是在本地&lt;/strong>，当你打开页面后，可能会遇到这个问题。&lt;/p>
&lt;p>假设服务器IP是 &lt;code>192.168.1.170&lt;/code>，打开的页面是 http://192.168.1.170:10096/&lt;/p>
&lt;p>&lt;strong>解决方法：&lt;/strong>
&lt;img src="https://harryai.cc/post/realtime-funasr/4.jpg" alt="image">&lt;/p>
&lt;h4 id="chrome浏览器">Chrome浏览器&lt;/h4>
&lt;ul>
&lt;li>在浏览器地址栏输入 &lt;code>chrome://flags/#unsafely-treat-insecure-origin-as-secure&lt;/code>&lt;/li>
&lt;li>把 &lt;code>http://192.168.1.170:10096/&lt;/code> 添加到输入框内&lt;/li>
&lt;li>将 &lt;code>Insecure origins treated as secure&lt;/code> 设置为 &lt;code>Enabled&lt;/code>&lt;/li>
&lt;li>重启浏览器&lt;/li>
&lt;/ul>
&lt;h4 id="edge浏览器">Edge浏览器&lt;/h4>
&lt;ul>
&lt;li>在浏览器地址栏输入 &lt;code>edge://flags/#unsafely-treat-insecure-origin-as-secure&lt;/code>&lt;/li>
&lt;li>把 &lt;code>http://192.168.1.170:10096/&lt;/code> 添加到输入框内&lt;/li>
&lt;li>将 &lt;code>Insecure origins treated as secure&lt;/code> 设置为 &lt;code>Enabled&lt;/code>&lt;/li>
&lt;li>重启浏览器&lt;/li>
&lt;/ul></description></item><item><title>ChatTTS 开源语音合成服务的部署和使用</title><link>https://harryai.cc/post/chat-tts/</link><pubDate>Wed, 29 May 2024 20:16:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/chat-tts/</guid><description>&lt;p>项目地址：&lt;a href="https://github.com/2noise/ChatTTS">https://github.com/2noise/ChatTTS&lt;/a>&lt;/p>
&lt;p>&lt;strong>Windows 用户建议直接下载一键启动包，运行环境和模型都已经配置好，使用更简单。&lt;/strong>&lt;/p>
&lt;h2 id="windows-一键启动包">Windows 一键启动包&lt;/h2>
&lt;p>百度网盘下载：&lt;a href="https://pan.baidu.com/s/1wfdqQDTzDnMf01bV1wzKgQ?pwd=v2kb">https://pan.baidu.com/s/1wfdqQDTzDnMf01bV1wzKgQ?pwd=v2kb&lt;/a>
提取码：v2kb&lt;/p>
&lt;p>&lt;strong>解压密码：harryai&lt;/strong>&lt;/p>
&lt;p>&lt;strong>下载后解压&lt;/strong>，然后双击 &lt;code>启动服务.bat&lt;/code> 即可。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/windows.jpg" alt="启动服务" class="center" width="600">&lt;p>启动成功后，会自动打开 &lt;a href="http://localhost:8080/">http://localhost:8845/&lt;/a> 页面。&lt;/p>
&lt;p>输入文本内容，即可合成语音。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/webui.jpg" alt="Web效果演示" class="center" width="600">&lt;h2 id="手动部署">手动部署&lt;/h2>
&lt;h3 id="1-下载代码">1. 下载代码&lt;/h3>
&lt;p>&lt;a href="https://harryai.cc/chat-tts/code.zip">点击下载代码压缩包&lt;/a>，然后解压到本地。&lt;/p>
&lt;h3 id="2-下载模型">2. 下载模型&lt;/h3>
&lt;p>从魔搭下载 &lt;a href="https://www.modelscope.cn/models/pzc163/chatTTS/summary">https://www.modelscope.cn/models/pzc163/chatTTS/summary&lt;/a>
建议使用 git 克隆&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>git clone https://www.modelscope.cn/pzc163/chatTTS.git
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>注意：魔搭里面缺少文件 &lt;code>spk_stat.pt&lt;/code>，&lt;a href="https://harryai.cc/chat-tts/spk_stat.pt">点击这里&lt;/a> 下载，然后放到 chatTTS/asset 目录下。&lt;/p>
&lt;p>再将下载的整个文件夹，放到 &lt;code>models&lt;/code> 文件夹下，结构如下：&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/folder.jpg" alt="文件夹结构" class="center" width="600">&lt;h3 id="3-安装依赖">3. 安装依赖&lt;/h3>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>pip install -r requirements.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="4-启动服务">4. 启动服务&lt;/h3>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>python webui.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>启动成功后，会自动打开 &lt;a href="http://localhost:8080/">http://localhost:8845/&lt;/a> 页面，输入文本内容，即可合成语音。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/webui.jpg" alt="Web效果演示" class="center" width="600"></description></item><item><title>只需3分钟，基于 LLaMA3-8B 微调一个属于你自己的嬛嬛</title><link>https://harryai.cc/post/llama3-fine-tuning/</link><pubDate>Fri, 03 May 2024 17:56:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/llama3-fine-tuning/</guid><description>&lt;blockquote>
&lt;p>注意：没有GPU，也可以微调一个属于你自己的大模型，只是微调的时间长一点而已，建议晚上睡觉前运行，第二天早上就可以使用了 😄&lt;/p>&lt;/blockquote>
&lt;h2 id="效果演示">效果演示&lt;/h2>
&lt;img src="https://harryai.cc/post/llama3-fine-tuning/chatbot2.jpg" alt="ChatBot对话页">&lt;h2 id="部署环境">部署环境&lt;/h2>
&lt;ol>
&lt;li>点击下载 &lt;a href="https://harryai.cc/llama3-fine-tuning/llama3-ft.zip">LLaMA3-8B 微调代码压缩包&lt;/a>&lt;/li>
&lt;li>将下载的压缩包解压&lt;/li>
&lt;li>在 &lt;strong>终端 (macOS)&lt;/strong> 或 &lt;strong>cmd命令提示符 (Windows)&lt;/strong> 里面，进入解压后的文件夹，创建一个新的 Conda 虚拟环境
&lt;blockquote>
&lt;p>未安装 Conda 的用户，可以到 &lt;a href="https://conda.io/projects/conda/en/latest/index.html">Conda官网下载安装&lt;/a>。&lt;/p>&lt;/blockquote>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3">3&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cd llama3-ft
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>conda create -n llama3-ft python&lt;span style="color:#f92672">=&lt;/span>3.10
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>conda activate llama3-ft
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>安装依赖包
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>pip install -r requirements.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;h2 id="数据准备">数据准备&lt;/h2>
&lt;p>你可以直接使用 &lt;code>dataset/huanhuan.json&lt;/code> 数据集（该数据集来源于 &lt;a href="https://github.com/KMnO4-zx">https://github.com/KMnO4-zx&lt;/a> ），&lt;strong>也可以自己准备数据集
，比如你的客服对话（FAQ）数据集，这样就可以微调一个更适合你的智能客服的模型，客服回答更准确&lt;/strong>。&lt;/p>
&lt;p>数据集的格式也比较简单，示例如下：&lt;/p>
&lt;ul>
&lt;li>&lt;code>instruction&lt;/code> 是问题&lt;/li>
&lt;li>&lt;code>output&lt;/code> 是回答&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-12">12&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>[
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;instruction&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;你好&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;input&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;output&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;皇上好，我是甄嬛，家父是大理寺少卿甄远道。&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> },
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;instruction&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;你不愿意见我？&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;input&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;output&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;不该相见自然不愿见，还望王爷尊重我的意愿。&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="模型微调">模型微调&lt;/h2>
&lt;h3 id="模型选择">模型选择&lt;/h3>
&lt;p>我使用的是 &lt;a href="https://www.modelscope.cn/studios/LLM-Research/Chat_Llama-3-8B/summary">LLM-Research/Meta-Llama-3-8B-Instruct&lt;/a>
，你也可以选择一个其他模型，只需要修改 &lt;code>train.py&lt;/code> 文件里面的 &lt;code>model_id&lt;/code> 变量即可。&lt;/p>
&lt;p>由于国内访问 HuggingFace 比较困难，因此使用 &lt;a href="https://www.modelscope.cn">ModelScope&lt;/a> 提供的模型。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6">6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-7">7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-8">8&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 需要微调的基座模型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># https://www.modelscope.cn/studios/LLM-Research/Chat_Llama-3-8B/summary&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>model_id &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;LLM-Research/Meta-Llama-3-8B-Instruct&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 比如你也可以使用 Qwen1.5-4B-Chat 模型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># https://www.modelscope.cn/models/qwen/Qwen1.5-4B-Chat/summary&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># model_id = &amp;#39;qwen/Qwen1.5-4B-Chat&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="开始微调">开始微调&lt;/h3>
&lt;p>只需要在项目根目录下执行以下命令即可。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>python train.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>或者可以打开 &lt;code>LLaMA3-8B-Instruct Lora.ipynb&lt;/code> 文件，使用 Jupyter Notebook 进行微调。&lt;/p>
&lt;blockquote>
&lt;p>注意：&lt;/p>&lt;/blockquote>
&lt;ol>
&lt;li>微调的时间会根据你的数据集大小和模型大小而定。我由于没有 GPU，因此耗时2个小时，如果你有 GPU，大概需要 30 分钟。&lt;/li>
&lt;li>代码会自动下载模型，然后开始微调&lt;/li>
&lt;li>微调完成后，所有的文件会保存在 &lt;code>models&lt;/code> 文件夹下面，结构如下：
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-12">12&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-13">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-13">13&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-14">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-14">14&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-15">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-15">15&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-16">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-16">16&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-17">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-17">17&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-18">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-18">18&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-19">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-19">19&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-20">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-20">20&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-21">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-21">21&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-22">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-22">22&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>├── models
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── checkpoint &lt;span style="color:#75715e">#【模型微调的 checkpoint】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-100
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-200
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-xxx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Qwen1.5-4B-Chat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-100
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-200
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-xxx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── lora &lt;span style="color:#75715e">#【模型微调的 lora 文件】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Qwen1.5-4B-Chat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── model &lt;span style="color:#75715e">#【自动下载的基座模型】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── Qwen1___5-4B-Chat
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;h2 id="模型测试">模型测试&lt;/h2>
&lt;p>微调完成后，你可以执行以下命令启动一个 ChatBot 进行对话测试。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>streamlit run chat.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>该命令执行后，会自动打开浏览器对话页面&lt;/p></description></item><item><title>手把手教你把AI大模型本地知识库问答接入个人微信，实现微信内的AI智能客服</title><link>https://harryai.cc/post/chatgpt-on-wechat/</link><pubDate>Mon, 29 Apr 2024 07:56:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/chatgpt-on-wechat/</guid><description>&lt;blockquote>
&lt;p>&lt;strong>前提&lt;/strong>&lt;/p>
&lt;p>先搭建好 &lt;strong>本地化的企业级知识库问答系统&lt;/strong>
，参考 &lt;a href="https://harryai.cc/post/enterprise-knowledge-llm-qa/">《手把手教你构建一个 本地化的，免费的，企业级的，AI大模型知识库问答系统》&lt;/a>&lt;/p>&lt;/blockquote>
&lt;h2 id="下载docker启动文件">下载Docker启动文件&lt;/h2>
&lt;blockquote>
&lt;p>因为 &lt;a href="https://github.com/zhayujie/chatgpt-on-wechat">ChatGPT-On-WeChat&lt;/a>
代码有 &lt;a href="https://github.com/zhayujie/chatgpt-on-wechat/issues/1880">Bug&lt;/a>，作者一直未修复，因此我修改后，重新打了一个Docker镜像，避免大家踩坑。&lt;/p>&lt;/blockquote>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3">3&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>mkdir chatgpt-on-wechat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd chatgpt-on-wechat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl -O https://harryai.cc/chatgpt-on-wechat/docker-compose.yml
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="修改配置文件">修改配置文件&lt;/h2>
&lt;p>打开 &lt;code>docker-compose.yml&lt;/code> 文件，修改 &lt;code>OPEN_AI_API_KEY&lt;/code> 和 &lt;code>OPEN_AI_API_BASE&lt;/code> 为你的 FastGPT 的 API Key 和 API 地址。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-12">12&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-13">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-13">13&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-14">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-14">14&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-15">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-15">15&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-16">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-16">16&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-17">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-17">17&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-18">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-18">18&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-19">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-19">19&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-20">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-20">20&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-21">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-21">21&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-22">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-22">22&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-23">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-23">23&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-24">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-24">24&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-25">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-25">25&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-26">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-26">26&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-27">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-27">27&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-28">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-28">28&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-29">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-29">29&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-30">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-30">30&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-31">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-31">31&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-yaml" data-lang="yaml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">version&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;2.0&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">services&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">chatgpt-on-wechat&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">image&lt;/span>: &lt;span style="color:#ae81ff">harryliu888/chatgpt-on-wechat:latest&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">container_name&lt;/span>: &lt;span style="color:#ae81ff">chatgpt-on-wechat&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">security_opt&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - &lt;span style="color:#ae81ff">seccomp:unconfined&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">environment&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># OPEN_AI_API_KEY 在 FastGPT 的 应用发布页面生成（API访问）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">OPEN_AI_API_KEY&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;fastgpt-iAt0KIDwpZqFvxfpmWstAkars36s0ASBENYKYLGSwJcf7NuCn2NzT&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># OPEN_AI_API_BASE 填写 FastGPT 的 API 地址&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e"># 特别注意，如果 chatgpt-on-wechat 是docker部署的，因此要访问外部的 FastGPT，这里需要使用 host.docker.internal&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">OPEN_AI_API_BASE&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;http://host.docker.internal:3000/api/v1&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">MODEL&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;gpt-3.5-turbo&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">PROXY&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">SINGLE_CHAT_PREFIX&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;[&amp;#34;bot&amp;#34;, &amp;#34;@bot&amp;#34;]&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">SINGLE_CHAT_REPLY_PREFIX&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;&amp;#34;[bot] &amp;#34;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">GROUP_CHAT_PREFIX&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;[&amp;#34;@bot&amp;#34;]&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">GROUP_NAME_WHITE_LIST&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;[&amp;#34;ChatGPT测试群&amp;#34;, &amp;#34;ChatGPT测试群2&amp;#34;]&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">IMAGE_CREATE_PREFIX&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;[&amp;#34;画&amp;#34;, &amp;#34;看&amp;#34;, &amp;#34;找&amp;#34;]&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">CONVERSATION_MAX_TOKENS&lt;/span>: &lt;span style="color:#ae81ff">1000&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">SPEECH_RECOGNITION&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;False&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">CHARACTER_DESC&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题，并且可以使用多种语言与人交流。&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">EXPIRES_IN_SECONDS&lt;/span>: &lt;span style="color:#ae81ff">3600&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">USE_GLOBAL_PLUGIN_CONFIG&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;True&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">USE_LINKAI&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;False&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">LINKAI_API_KEY&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">LINKAI_APP_CODE&lt;/span>: &lt;span style="color:#e6db74">&amp;#39;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">extra_hosts&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - &lt;span style="color:#e6db74">&amp;#39;host.docker.internal:host-gateway&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="启动docker">启动Docker&lt;/h2>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cd chatgpt-on-wechat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div></description></item><item><title>手把手教你构建一个 本地化的，免费的，企业级的，AI大模型知识库问答系统</title><link>https://harryai.cc/post/enterprise-knowledge-llm-qa/</link><pubDate>Sat, 20 Apr 2024 13:56:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/enterprise-knowledge-llm-qa/</guid><description>&lt;p>我将通过一个系列分享，手把手的教大家打造一个完全本地化的，免费的，企业级知识库问答系统&lt;/p>
&lt;h2 id="本地大模型回答演示图">本地大模型回答演示图&lt;/h2>
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/gitmin1.jpg" alt="gitmin1.jpg">&lt;h2 id="知识库导入演示图">知识库导入演示图&lt;/h2>
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/gitmind2.jpg" alt="gitmind2.jpg">&lt;h2 id="我认为本地化主要有2方面的意义">我认为本地化主要有2方面的意义：&lt;/h2>
&lt;h3 id="1-安全性">1. 安全性&lt;/h3>
&lt;p>当使用外部模型或服务时，我们的私有数据，用户问题，都会被发送给第三方
那我们就要面临私有数据暴露给别人的风险，甚至会导致数据泄露
本地化会让我们的数据就更安全&lt;/p>
&lt;h3 id="2-灵活性">2. 灵活性&lt;/h3>
&lt;p>另外随着我们的业务发展，如果模型不能很好的满足我们需求的时候
我们可以很方便的对本地模型其进行微调
以达到更好的适配&lt;/p>
&lt;blockquote>
&lt;p>这样就既兼顾了安全，又兼顾了灵活性&lt;/p>&lt;/blockquote>
&lt;h2 id="应用场景">应用场景&lt;/h2>
&lt;p>知识库问答的使用场景其实非常多，我随便举2个商业系统的例子&lt;/p>
&lt;p>比如对个人，可以用来&lt;code>整理笔记&lt;/code>、&lt;code>论文解读&lt;/code>、&lt;code>文献检索&lt;/code>、&lt;code>文档问答&lt;/code>等等。
这里我用 &lt;a href="https://lightpdf.cn/chatdoc">轻闪PDF的文档对话 https://lightpdf.cn/chatdoc&lt;/a> 来演示一下效果。&lt;/p>
&lt;p>我们随便上传一个PDF文档，等文档解析完成后，我们就可以通过提问的方式，对文档里面的内容进行解读，可以很快的从文档中找到我们想要的内容，
&lt;strong>大大提高我们查看文档的效率&lt;/strong>。&lt;/p>
&lt;p>对企业，可以用来做&lt;code>智能客服&lt;/code>，&lt;code>数据沉淀&lt;/code>或者&lt;code>数字员工&lt;/code>等等，同样我用&lt;a href="https://gitmind.cn">思乎的在线客服 https://gitmind.cn&lt;/a>
来演示一下。&lt;/p>
&lt;p>我们可以向客服提问，AI就会准确的回复我们的问题，而这些问题的答案，大模型本身是没有的。
因为大模型既不了解我们的业务，也不知道我们的数据，这些AI回复的答案，都是从企业的知识库里面获取的。这样我们就实现了一个7x24小时的智能客服，
&lt;strong>不仅为企业降本增效，还提高了客户的满意度&lt;/strong>。&lt;/p>
&lt;h2 id="服务器配置要求">服务器配置要求&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>环境&lt;/th>
&lt;th>最低配置&lt;/th>
&lt;th>推荐配置&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>测试&lt;/td>
&lt;td>2核 2GB&lt;/td>
&lt;td>2核 4GB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>100w 组向量&lt;/td>
&lt;td>4核 8GB 50GB&lt;/td>
&lt;td>4核 16GB 50GB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>500w 组向量&lt;/td>
&lt;td>8核 32GB 200GB&lt;/td>
&lt;td>16核 48GB 200GB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1000w 组向量&lt;/td>
&lt;td>16核 48GB 200GB&lt;/td>
&lt;td>32核 64GB 500GB&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="架构图">架构图&lt;/h2>
&lt;p>整个的系统搭建，都是基于这个架构图来进行的&lt;/p>
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/architecture.jpg" alt="架构图">&lt;h2 id="rag原理">RAG原理&lt;/h2>
&lt;h3 id="是什么">是什么&lt;/h3>
&lt;ul>
&lt;li>检索：Retrieval，通过向量模型，或者多种混合检索方式，从知识库中检索出相关的文档&lt;/li>
&lt;li>增强：Augmentation，通过将检索到的文档，附加到提示词中，进行增强。也即 ICL（In Context Learning）&lt;/li>
&lt;li>生成：Generation，通过大语言模型，生成答案&lt;/li>
&lt;/ul>
&lt;h3 id="有什么优势">有什么优势&lt;/h3>
&lt;ol>
&lt;li>有助于减轻大模型的幻觉，提高大模型回复的准确性&lt;/li>
&lt;li>与微调不同，RAG提供了一定的可观察性和可检查性&lt;/li>
&lt;li>成本低，好实施&lt;/li>
&lt;/ol>
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/rag.png" alt="rag.png">&lt;h2 id="安装-docker">安装 Docker&lt;/h2>
&lt;p>下载 Docker 并安装 &lt;a href="https://www.docker.com/products/docker-desktop/">https://www.docker.com/products/docker-desktop/&lt;/a>&lt;/p>
&lt;h2 id="安装-ollama">安装 Ollama&lt;/h2>
&lt;p>下载 Ollama 并安装 &lt;a href="https://ollama.com/">https://ollama.com/&lt;/a>&lt;/p>
&lt;h3 id="下载-chat-模型">下载 Chat 模型&lt;/h3>
&lt;p>我使用阿里的通义千问作为演示，根据自己的电脑配置情况，选择合适的模型。&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>总体来说，模型是越大，效果越好&lt;/strong>，但是对电脑的配置要求也越高&lt;/p>&lt;/blockquote>
&lt;ul>
&lt;li>4b 模型要 3GB内存&lt;/li>
&lt;li>7b 模型要 8GB 内存&lt;/li>
&lt;li>13b 模型要 16GB 内存&lt;/li>
&lt;li>70b 模型要 64GB 内存&lt;/li>
&lt;/ul>
&lt;p>特别注意：你如果要&lt;strong>用于商业用途，需要申请授权&lt;/strong>，否则只能用于个人学习&lt;/p>
&lt;ul>
&lt;li>千问许可说明: &lt;a href="https://ollama.com/library/qwen:latest/blobs/41c2cf8c272f">https://ollama.com/library/qwen:latest/blobs/41c2cf8c272f&lt;/a>&lt;/li>
&lt;li>&lt;/li>
&lt;/ul>
&lt;p>申请商用授权: &lt;a href="https://dashscope.console.aliyun.com/openModelApply/qianwen">https://dashscope.console.aliyun.com/openModelApply/qianwen&lt;/a>&lt;/p>
&lt;h4 id="下载模型">下载模型&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>ollama pull qwen:7b
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="测试api请求">测试API请求&lt;/h4>
&lt;p>等模型下载和安装好后，执行下面的命令，测试API请求是否成功&lt;/p>
&lt;h5 id="maclinux下执行">Mac/Linux下执行：&lt;/h5>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-12">12&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl &lt;span style="color:#e6db74">&amp;#39;http://localhost:11434/api/chat&amp;#39;&lt;/span> &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span>--data &lt;span style="color:#e6db74">&amp;#39;{
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;model&amp;#34;: &amp;#34;qwen:7b&amp;#34;,
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;messages&amp;#34;: [
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> {
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;role&amp;#34;: &amp;#34;user&amp;#34;,
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;content&amp;#34;: &amp;#34;你是谁&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> ],
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;temperature&amp;#34;: 0.1,
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;stream&amp;#34;: false
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h5 id="windows下执行">Windows下执行：&lt;/h5>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl &lt;span style="color:#e6db74">&amp;#34;http://localhost:11434/api/chat&amp;#34;&lt;/span> ^
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>--data &lt;span style="color:#e6db74">&amp;#34;{&amp;#34;&amp;#34;model&amp;#34;&amp;#34;: &amp;#34;&amp;#34;qwen:7b&amp;#34;&amp;#34;, &amp;#34;&amp;#34;messages&amp;#34;&amp;#34;: [{&amp;#34;&amp;#34;role&amp;#34;&amp;#34;: &amp;#34;&amp;#34;user&amp;#34;&amp;#34;, &amp;#34;&amp;#34;content&amp;#34;&amp;#34;: &amp;#34;&amp;#34;你是谁&amp;#34;&amp;#34;}], &amp;#34;&amp;#34;temperature&amp;#34;&amp;#34;: 0.1, &amp;#34;&amp;#34;stream&amp;#34;&amp;#34;: false}&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="下载-embedding-模型">下载 Embedding 模型&lt;/h3>
&lt;p>我使用了 DmetaSoul 的中文Embedding模型，该模型&lt;code>号称&lt;/code>在 MTEB
中文榜单取得开源第一的成绩: &lt;a href="https://huggingface.co/DMetaSoul/Dmeta-embedding-zh/blob/main/README_zh.md">https://huggingface.co/DMetaSoul/Dmeta-embedding-zh/blob/main/README_zh.md&lt;/a>&lt;/p>
&lt;h4 id="下载模型-1">下载模型&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>ollama pull shaw/dmeta-embedding-zh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="测试api请求-1">测试API请求&lt;/h4>
&lt;p>等模型下载和安装好后，执行下面的命令，测试API请求是否成功&lt;/p>
&lt;h5 id="maclinux下执行-1">Mac/Linux下执行：&lt;/h5>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3">3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4">4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5">5&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl &lt;span style="color:#e6db74">&amp;#39;http://localhost:11434/api/embeddings&amp;#39;&lt;/span> &lt;span style="color:#ae81ff">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">&lt;/span>--data &lt;span style="color:#e6db74">&amp;#39;{
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;model&amp;#34;: &amp;#34;shaw/dmeta-embedding-zh&amp;#34;,
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> &amp;#34;prompt&amp;#34;: &amp;#34;天空是灰色的&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h5 id="windows下执行-1">Windows下执行：&lt;/h5>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl &lt;span style="color:#e6db74">&amp;#34;http://localhost:11434/api/embeddings&amp;#34;&lt;/span> ^
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>--data &lt;span style="color:#e6db74">&amp;#34;{&amp;#34;&amp;#34;model&amp;#34;&amp;#34;: &amp;#34;&amp;#34;shaw/dmeta-embedding-zh&amp;#34;&amp;#34;, &amp;#34;&amp;#34;prompt&amp;#34;&amp;#34;: &amp;#34;&amp;#34;天空是灰色的&amp;#34;&amp;#34;}&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="安装fastgpt及其依赖">安装FastGPT及其依赖&lt;/h2>
&lt;h3 id="1-下载-docker-文件-和-config-文件">1. 下载 docker 文件 和 config 文件&lt;/h3>
&lt;p>&lt;strong>你可以手动下载，放到一个文件夹里面&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>docker-compose.yml: &lt;a href="https://harryai.cc/kbqa/docker-compose.yml">https://harryai.cc/kbqa/docker-compose.yml&lt;/a>&lt;/li>
&lt;li>config.json: &lt;a href="https://harryai.cc/kbqa/config.json">https://harryai.cc/kbqa/config.json&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>也可以直接执行下面的命令，自动下载&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-3">3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-4">4&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir kbqa
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd kbqa
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl -O https://harryai.cc/kbqa/docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl -O https://harryai.cc/kbqa/config.json
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="2-启动-docker">2. 启动 docker&lt;/h3>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>注意&lt;/p>
&lt;ul>
&lt;li>第一次启动会有点慢，因为要拉取镜像，后面启动就会很快了&lt;/li>
&lt;li>如果第一次启动失败，可以多次执行 &lt;code>docker-compose up&lt;/code>&lt;/li>
&lt;/ul>
&lt;h3 id="3-访问-fastgpt-和-oneapi">3. 访问 FastGPT 和 OneAPI&lt;/h3>
&lt;blockquote>
&lt;p>你第一次访问，系统里面是没有数据的，截图里面的数据，是我测试的时候已经创建好了的。&lt;/p>&lt;/blockquote>
&lt;h4 id="fastgpt">FastGPT&lt;/h4>
&lt;p>点击访问：&lt;a href="http://localhost:3000">http://localhost:3000&lt;/a>&lt;/p>
&lt;p>用户名 &lt;code>root&lt;/code>，密码 &lt;code>1234&lt;/code>（密码可以在 &lt;code>docker-compose.yml&lt;/code>
环境变量里设置 &lt;code>DEFAULT_ROOT_PSW&lt;/code> 进行修改）
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/fastgpt.jpg" alt="fastgpt.jpg">&lt;/p>
&lt;h4 id="oneapi">OneAPI&lt;/h4>
&lt;p>点击访问：&lt;a href="http://localhost:3001">http://localhost:3001&lt;/a>&lt;/p>
&lt;p>用户名 &lt;code>root&lt;/code>，密码 &lt;code>123456&lt;/code>
&lt;img src="https://harryai.cc/post/enterprise-knowledge-llm-qa/oneapi.jpg" alt="oneapi.jpg">&lt;/p>
&lt;h2 id="配置oneapi">配置OneAPI&lt;/h2>
&lt;p>添加模型：&lt;a href="http://localhost:3001/channel">http://localhost:3001/channel&lt;/a>&lt;/p>
&lt;h3 id="1-配置大语言模型">1. 配置大语言模型&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>类型&lt;/strong>：Ollama&lt;/li>
&lt;li>&lt;strong>名称&lt;/strong>：ollama-qwen:7b&lt;/li>
&lt;li>&lt;strong>模型&lt;/strong>：输入自定义模型名称，&lt;code>qwen:7b&lt;/code>&lt;/li>
&lt;li>&lt;strong>密钥&lt;/strong>：随便填，比如 123&lt;/li>
&lt;li>&lt;strong>代理&lt;/strong>：http://host.docker.internal:11434&lt;/li>
&lt;/ol>
&lt;h3 id="2-配置embedding向量模型">2. 配置Embedding向量模型&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>类型&lt;/strong>：Ollama&lt;/li>
&lt;li>&lt;strong>名称&lt;/strong>：ollama-dmeta-embedding-zh&lt;/li>
&lt;li>&lt;strong>模型&lt;/strong>：输入自定义模型名称，&lt;code>shaw/dmeta-embedding-zh&lt;/code>**，比如&lt;/li>
&lt;li>&lt;strong>密钥&lt;/strong>：随便填，比如 123&lt;/li>
&lt;li>&lt;strong>代理&lt;/strong>：http://host.docker.internal:11434&lt;/li>
&lt;/ol>
&lt;p>&lt;strong>特别注意：&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>模型 &lt;strong>必须和 ollama 安装的模型名称保持一致&lt;/strong>，可以使用 &lt;code>ollama list&lt;/code> 命令查看&lt;/li>
&lt;li>代理地址 &lt;strong>必须是 &lt;a href="http://host.docker.internal:11434">http://host.docker.internal:11434&lt;/a>&lt;/strong>，这样 OneAPI 才能访问到 ollama&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>默认情况下，&lt;strong>Docker 使用的是 桥接模式 启动服务&lt;/strong>，即容器使用 Docker 自己创建的虚拟网络，容器之间可以相互通信，但是它们无法直接访问宿主机（即你的电脑）上的网络服务。&lt;/p>
&lt;p>但是 Ollama 是运行在你的电脑上的， 而 OneAPI 是运行在 Docker 容器里面的，所以 OneAPI 无法直接访问 Ollama。&lt;/p>
&lt;p>docker 官方提供了一种支持方案，可通过指向 host.docker.internal 来指向宿主机的 IP。&lt;/p>&lt;/blockquote>
&lt;p>参见官方文档：&lt;a href="https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host">从容器连接到主机上的服务&lt;/a>&lt;/p>
&lt;h2 id="配置fastgpt">配置FastGPT&lt;/h2>
&lt;p>我们先创建一个简单的应用，实现一个基本的AI对话，目的是测试OneAPI的接口以及Ollama的接口是否正常。&lt;/p>
&lt;blockquote>
&lt;p>未完待续&lt;/p>&lt;/blockquote></description></item></channel></rss>