Cursor 配置 DeepSeek V2 辅助编程(VSCode / JetBrains 适用)

Published: 2024-09-05
Updated: 2024-09-14

Tags: Software

本文总阅读量

关于 DeepSeek,访问官网了解更多,DeepSeek-Coder 用于编程辅助,实测体验很棒!

如果你不想安装插件辅助编程,只是想通过网页版问些问题,DeepSeek 也提供了网页端 DeepSeek Chat

获取在线 DeepSeek API Key

平台地址:https://platform.deepseek.com/

创建 Key 后记得先充值后使用,最低一元

(可选)本地部署 DeepSeek

日常使用更推荐 DeepSeek 的在线 API

模型地址:https://ollama.com/library/deepseek-coder

$ ollama run deepseek-coder

参数越多,效果越好,但对机器的性能要求越高,安装后不确定模型名称可以使用 ollama list 查询

方案一:Cursor + DeepSeek API

Cursor 是基于 VS Code 改造后的编辑器(IDE),相比于 VS Code + 插件的模式来说,定制化更强,更适合 AI 辅助编程,如果是新建的小项目,我很乐意尝试 Cursor

Cursor 提供一些免费额度,但是很少,好在其可以使用其它 AI 平台的 Key,例如刚申请的 DeepSeek 平台 Key

首先添加 deepseek-coder 模型名称

然后配置 DeepSeek 获取到的 Key,需要配置 Override,地址为 https://api.deepseek.com/beta

配置完成,需要注意,使用 TAB 代码补全需要登录(配置自己的 Key 是免费的)

方案二:JetBrains / VS Code + Continue + DeepSeek API

如果你不想体验 Cursor,VS Code 是你主力代码编辑器,那么可以试试 Continue 插件,它提供了 VS Code 和 JetBrains 的支持

Continue 插件下载地址:https://www.continue.dev/

此处我使用 JetBrains Goland 记录配置 Continue 过程 ,VS Code 应该大差不差

环境信息

系统:macOS Ventura IDE:JetBrains Goland 2023.1.2 Continue: 0.0.67

Goland 安装 Continue 插件

点击设置按钮

选择从本地磁盘导入 “Install Plugin from Disk...”

下载到的 Continue 插件无需解压缩

修改 Continue 插件配置

点击 Goland 右侧的 Continue 图标

点击图标编辑配置

配置参考

使用时注意替换自己的 DeepSeek Key,因为 DeepSeek 的 API 是 OpenAI 兼容的,所以提供者是 openai

{
  "models": [
    {
      "title": "DeepSeek-V2",
      "model": "deepseek-chat",
      "apiKey": "<your-api-key>",
      "apiBase": "https://api.deepseek.com/beta",
      "provider": "openai"
    },
    {
      "title": "DeepSeek Local,
      "model": "deepseek-coder:1.3b",
      "contextLength": 4096,
      "provider": "ollama"
    }
  ],
  "customCommands": [
    {
      "name": "test",
      "prompt": "{{{ input }}}\n\nWrite a comprehensive set of unit tests foar the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.",
      "description": "Write unit tests for highlighted code"
    }
  ],
  "tabAutocompleteModel": {
    "title": "DeepSeek-V2",
    "model": "deepseek-coder",
    "apiKey": "<your-api-key>",
    "contextLength": 8192,
    "apiBase": "https://api.deepseek.com",
    "completionOptions": {
      "maxTokens": 4096,
      "temperature": 0,
      "topP": 1,
      "presencePenalty": 0,
      "frequencyPenalty": 0
    },
    "provider": "openai",
    "useLegacyCompletionsEndpoint": false
  },
  "tabAutocompleteOptions": {
    "template": "Please teach me what I should write in the `hole` tag, but without any further explanation and code backticks, i.e., as if you are directly outputting to a code editor. It can be codes or comments or strings. Don't provide existing & repetitive codes. If the provided prefix and suffix contain incomplete code and statement, your response should be able to be directly concatenated to the provided prefix and suffix. Also note that I may tell you what I'd like to write inside comments. \n{{{prefix}}}<hole></hole>{{{suffix}}}\n\nPlease be aware of the environment the hole is placed, e.g., inside strings or comments or code blocks, and please don't wrap your response in ```. You should always provide non-empty output.\n",
    "useCache": true,
    "maxPromptTokens": 2048
  },
  "allowAnonymousTelemetry": true,
  "reranker": {
    "name": "free-trial"
  }
}

总结

当前 Cursor 的付费计划应该是体验最好的编程辅助,借助 Continue 搭配 DeepSeek API 可以低成本的体验质量较高的代码补全功能

Goland(JetBrains 系列)IDE 整体体验还有较大的提升空间(Continue 待解决的 BUG),但功能是可用的,以下是我遇到的一些零散问题:

  1. 开启插件后鼠标悬浮在代码上不出现原有的函数/变量提示
  2. 程序运行后出现的 Run(command + 4) 日志面板的 Hide 按钮点击无效

内部报错,时不时弹出

UI 文字和输入框错位

Continue 插件 在 VS Code 下可能会好一些,JetBrains 家的 IDE 可以等过几个月再试试

2024-09-14 补充

Cursor 的 Tab completions 补全功能,免费账号终身只有 2000 次,用没就没有了,介意的用户慎重选择,或者重新注册一个账号?

参考