<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
  <language>zh-cn</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://blog-ccino-cc.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://blog.ccino.cc</link>
  <itunes:author>奇诺分享</itunes:author>
  <itunes:image href="https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png"/>
  <image>
    <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
    <url>https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png</url>
    <link>https://blog.ccino.cc</link>
  </image>
  <copyright>©2024</copyright>
  <item>
    <title>使用 Continue 部署免费的 AI 代码助手</title>
    <guid>mR7PNdXxt5F</guid>
    <pubDate>Sun, 13 Oct 2024 08:37:38 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<p>过去的一年, 我一直在使用 GitHub Copilot 作为代码助手, 它提供了补全、问答等功能, 付费订阅 10 美元 / 月.</p><p>说实话这个价格并不算贵, 但最近 Copilot 对问答范围进行了限制, 导致很多与开发相关的问题无法得到解答.</p><p>后续我也尝试了 Codium AI, 响应速度不尽人意.</p><p>最近发现了一个开源的代码助手&nbsp;<a href="https://www.continue.dev/" rel="noopener noreferrer" target="_blank">Continue</a>, 支持调用本地和云端的模型, 包括 Cloudflare 的 worker AI.</p><h2>介绍</h2><p><br></p><p>Continue 本质是个帮你向大模型发起请求的客户端.</p><p>当你编写代码的时候, 它会获取代码的上下文, 向模型发起请求, 获取结果后处理等待你的命令 (tab), 再拼接到代码中去.</p><h2>本地部署</h2><p><br></p><p>本地部署可以使用&nbsp;<a href="https://ollama.com/" rel="noopener noreferrer" target="_blank">Ollama</a>&nbsp;或&nbsp;<a href="https://docs.continue.dev/reference/Model%20Providers/lmstudio" rel="noopener noreferrer" target="_blank">lmstudio</a>.</p><p>这是两个非常方便的大模型集成工具, 同时支持 Mac、windows 以及 Linux, 帮助你快速在本地运行大模型.</p><p>这里我选择在 Mac 上运行 Ollama, 在官网 Ollama 可以下载到安装包, 安装过程中记得勾选命令行工具.</p><p><a href="https://ollama.com/" rel="noopener noreferrer" target="_blank">Ollama</a>&nbsp;ollama. Com</p><p>Get up and running with large language models.</p><p><img src="https://ollama.com/public/og.png"></p><h3>配置要求</h3><p><br></p><p>配置要求取决于你要使用的模型, 这里推荐 llama 3.</p><p>Llama 3 是 meta 开源的模型, 也是目前最强的开源模型, 可以获得比较好的补全效果.</p><p>模型有两个变体, 8 B 需要至少 16 g 的内存和 8 g 的显存, 70 B 则需要 64 g 以上的内存.</p><p>默认运行的 8 B 版本即可满足正常需要.</p><h3>运行模型</h3><p><br></p><p>安装完成后进入 terminal, 输入以下命令获取 llama 3 模型:</p><pre class="ql-syntax" spellcheck="false">1ollama run llama3
</pre><p><br></p><p><br></p><p>模型拉取完成后就会自动运行.</p><p>测试用中文让他编写一个 python 版的 hello-world.</p><p><img src="https://r2.ray-d-song.com/2024/09/6d3a74f153d36136f7ae81586e8315fb.png"></p><p>输入&nbsp;/bye&nbsp;可以退出运行.</p><h3>配置 Continue 插件</h3><p><br></p><p>安装&nbsp;<a href="https://marketplace.visualstudio.com/items?itemName=Continue.continue" rel="noopener noreferrer" target="_blank">vscode plugin</a></p><p>安装完成左侧边栏会展示 Continue 的对话框:</p><p><img src="https://r2.ray-d-song.com/2024/09/ea18b185908bda96720414fcad005f10.png"></p><p>这个时候是无法对话的, 因为还没有选择模型, 点击&nbsp;Select model&nbsp;-&gt;&nbsp;Add Model, 向下拉, 找到:</p><p><img src="https://r2.ray-d-song.com/2024/09/58d456bc4ba21cacbb2f2c2b076722de.png"></p><p>然后再选择第一个&nbsp;Autodetect&nbsp;选项:</p><p><img src="https://r2.ray-d-song.com/2024/09/05191d0410e4f23c30285563b15c54dc.png"></p><p>返回对话, 选择 Ollama 选项:</p><p><img src="https://r2.ray-d-song.com/2024/09/f82f1758e1ea1f85cf5cd9db3913e11d.png"></p><p>确保你的模型正在后台运行, 接下来就可以开始对话了.</p><p><img src="https://r2.ray-d-song.com/2024/09/2880fe2110c014bc1b6e736d41bb0e71.png"></p><h3>自动补全设置</h3><p><br></p><p>虽然现在已经可以完成对话, 但还是无法补全.</p><p><img src="https://r2.ray-d-song.com/2024/09/c072cad8863c2a50f9202e05e3442d44.png"></p><p>因为补全默认使用的是&nbsp;Starcoder2 3b&nbsp;模型, Starcoder 是一个针对代码场景针对性强化的模型.</p><p>你可以使用以下命令启动该模型.</p><pre class="ql-syntax" spellcheck="false">1 1ollama run starcoder2
</pre><p><br></p><p><br></p><p>模型启动后就可以触发补全.</p><p>如果你的机器性能不足以同时运行两个模型, 你也可以设置补全也使用&nbsp;llama3:</p><p>在插件侧边栏的角落, 找到这个小齿轮图标</p><p><img src="https://r2.ray-d-song.com/2024/09/d3b06fcec439af8e2cec4d360f2663c2.png"></p><p>点击就会进入配置文件 (也可以打开~/. Continue/config. Json), 将&nbsp;tabAutocompleteModel&nbsp;字段的两个高亮行的值修改为&nbsp;llama3&nbsp;即可.</p><pre class="ql-syntax" spellcheck="false">1"tabAutocompleteModel": {
2  "title": "Starcoder2 3b",
3  "provider": "ollama",
4  "model": "starcoder2:3b"
5},
</pre><p><br></p><p>如果你希望补全 markdown 之类的的文本文件, 那我建议使用 llama 3 进行补全</p><h2>Cloudflare worker AI</h2><p><br></p><p>有一些轻薄本机型不能在本地运行大模型, 也可以使用 Cloudflare worker 的 AI 模型.</p><p>Cloudflare 提供了免费额度, 不过是以&nbsp;神经元&nbsp;作为单位, 可以在<a href="https://ai.cloudflare.com/#pricing-calculator" rel="noopener noreferrer" target="_blank">这个页面查看估算</a>.</p><p>每日的免费额度大体相当于 500 次调用, 每次 100 个入参字符和 500 个返回字符, 足以应对正常的开发场景.</p><p>首先根据&nbsp;<a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/" rel="noopener noreferrer" target="_blank">Cloudflare 的指引, 创建 key</a></p><p>然后打开配置文件, 增加一个&nbsp;models&nbsp;字段值, 并修改&nbsp;tabAutocompleteModel&nbsp;字段.</p><pre class="ql-syntax" spellcheck="false">1{
2  "models": [
3    {
4      "accountId": "YOUR CLOUDFLARE ACCOUNT ID",
5      "apiKey": "YOUR CLOUDFLARE API KEY",
6      "contextLength": 2400,
7      "completionOptions": {
8        "maxTokens": 500
9      },
10      "model": "@cf/meta/llama-3-8b-instruct",
11      "provider": "cloudflare",
12      "title": "Llama 3 8B"
13    }
14  ],
15  "tabAutocompleteModel": {
16    "accountId": "YOUR CLOUDFLARE ACCOUNT ID",
17    "apiKey": "YOUR CLOUDFLARE API KEY",
18    "model": "@hf/thebloke/deepseek-coder-6.7b-base-awq",
19    "provider": "cloudflare",
20    "title": "DeepSeek 7b"
21  },
22}
</pre><p><br></p><p>修改 accountId 为你自己的账户 id, apiKey 是你刚刚保存的 key 值.</p><p>账户 id 获取比较麻烦. 你必须要有一个 Cloudflare 下的域名或者一个 Worker, 具体可以参照官方文档和这两个页面:</p><ul><li><a href="https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/" rel="noopener noreferrer" target="_blank">官方文档</a></li><li><a href="https://docs.thorn.red/articles/6d89ow4vgfghgnn8" rel="noopener noreferrer" target="_blank">参考 1</a></li><li><a href="https://community.cloudflare.com/t/where-can-i-find-my-account-id/164431" rel="noopener noreferrer" target="_blank">参考 2</a></li></ul><p>model&nbsp;字段的值可以自行修改, 不同的模型需要的算力不同, 对&nbsp;神经元&nbsp;的计费方式也会有影响.</p><p>如果你发现免费额度不足以覆盖, 可以修改为低一级的模型.</p><p>点击链接可以看到完整的模型列表:</p><p><a href="https://developers.cloudflare.com/workers-ai/models" rel="noopener noreferrer" target="_blank">Models | Cloudflare Workers AI docs</a>&nbsp;developers. Cloudflare. Com</p><p>Browse our entire catalog of models:</p><h2>总结</h2><p><br></p><p>Llama 3 有不错的对话效果, 但是速度比较慢, 代码补全也比较笨.</p><p>Starcoder 2 速度要快得多, 补全效果也更好, 但对文本的处理能力偏弱.</p><p>个人推荐使用 Cloudflare 的 llama 3 模型进行对话, 本地运行 starcoder 2 进行补全, 是比较完美的解决方案.</p><p>本文出自：<a href="https://ray-d-song.com/zh-cn/blog/continue-free-ai-code-assistant/" rel="noopener noreferrer" target="_blank">使用 Continue 部署免费的 AI 代码助手</a></p>]]>
    </description>
    <link>https://blog.ccino.cc/i/deploy-a-free-ai-code-assistant-with-continue/</link>
    <itunes:episodeType>full</itunes:episodeType>
    <enclosure url="https://ray-d-song.com/zh-cn/blog/continue-free-ai-code-assistant/" type="text/html"/>
  </item>
</channel>
</rss>