IDEA 接入 DeepSeek

最近DeepSeek非常的火爆,而我们开发中常用的是IDEA,如果将DeepSeek集成到IDEA中,将会提高开发效率。

一、安装CodeGPT

具体步骤:

  1. 打开Intelli IDEA -> File -> settings -> plugins 选项卡。

  2. 在Plugins页面点击右侧的 Marketplace按钮,在搜索框内输入"CodeGPT" 进行查找。

  3. 如果找到了对应的插件,则点击 Install 来下载并安装该插件,如果没有发现官方渠道提供的 CodeGPT插件。


    CodeGPT.png
  4. 安装完成后重启IDEA使更改生效。

二、配置

settings-> Tools -> CodeGPT->Providers->Custom OpenAI 修改配置

  1. Chat completions(对话模型)
    1.1 API key: xxx
    1.2 URL:https://api.openai.com/v1/chat/completions
    1.3 Body,修改对话模型model:deepseek-chat
    配置01.png
  1. Code completions(推理模型)
    1.1 API key: xxx
    1.2 FIM template: Deepseek Coder
    1.2 URL:https://api.openai.com/v1/chat/completions
    1.3 Body,修改对话模型model:deepseek-reasoner

deepseek-chat:对话模型为DeepSeek-V3
deepseek-reasoner:推理模型为 DeepSeek-R1

配置02.png

API key需要到Deekseep官网注册后创建生成,可以参考上一篇文章关于DeepSeek

三、使用DeepSeek进行提问,获取参考代码

1.配置
2.输入问题
3.输出的结果


Codegpt使用01.png
import java.util.List;
import java.util.stream.Collectors;

public class ListIntersection {
    public static List<String> getIntersection(List<String> list1, List<String> list2) {
        return list1.stream()
                    .filter(list2::contains)
                    .collect(Collectors.toList());
    }

    public static void main(String[] args) {
        List<String> list1 = List.of("A", "B", "C", "D");
        List<String> list2 = List.of("C", "D", "E", "F");

        List<String> result = getIntersection(list1, list2);
        System.out.println(result); // 输出: [C, D]
    }
}

4.输入问题2


codegpt问题2.png
<template>
  <div class="login-page">
    <h1>登录</h1>
    <form @submit.prevent="login">
      <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" id="username" v-model="username" required />
      </div>
      <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" v-model="password" required />
      </div>
      <button type="submit">登录</button>
    </form>
    <p v-if="error" class="error">{{ error }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      error: ''
    };
  },
  methods: {
    login() {
      if (this.username === 'admin' && this.password === 'password') {
        this.error = '';
        alert('登录成功!');
        // 这里可以添加跳转到主页的逻辑
      } else {
        this.error = '用户名或密码错误';
      }
    }
  }
};
</script>

<style scoped>
.login-page {
  max-width: 300px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
}
.form-group {
  margin-bottom: 15px;
}
label {
  display: block;
  margin-bottom: 5px;
}
input {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
}
button {
  width: 100%;
  padding: 10px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
.error {
  color: red;
  margin-top: 10px;
}
</style>

四、CodeGPT 工具使用
  1. New Chat(新建对话)
    操作步骤:右键选中代码 → 选择 New Chat → 在对话框中输入问题。
    使用场景:快速理解陌生代码逻辑,讨论代码优化可能性生成代码注释或文档。


    newchat01.jpg
newchat02.jpg
newchat03.jpg
newchat04.jpg
  1. Edit Code(编辑代码)
    操作步骤:选中代码 → 右键选择 Edit Code → 输入修改指令(如 "将循环改为递归")。
    使用场景:代码重构(如简化冗余逻辑),修复已知错误(如 "修复数组越界问题")等。


    edit-code01.jpg
edit-code02.jpg
  1. Ask Question(提问)
    操作步骤:选中代码 → 右键选择 Ask Question → 输入具体问题。
    使用场景:调试错误(如 "这段代码是否存在bug?","为什么这段代码抛出空指针异常?")。


    ask-question-01.jpg
ask-question-02.jpg
ask-question-03.jpg
  1. Find Bugs (找bug)
    操作步骤:选中代码 → 右键选择 Find Bugs;


    find-bugs01.jpg
  2. Include Selection in Prompt(将选中代码包含到提示)
    核心作用,将当前选中的代码作为上下文自动注入到后续提问中,避免重复粘贴代码片段。
    5.1 操作步骤:选中代码 → 右键选择 Include Selection in Prompt;
    5.2 输入问题(如 "解释这段代码");

  3. Explain(代码解释)

  4. Refactor(代码重构)

  5. Optimize(代码优化)

总结

我们将 DeepSeek 集成到了 IDEA 中,在今后的编程工作中,可以尽情享受 DeepSeek 带来的便利和高效,领略AI编程世界的无限魅力。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

相关阅读更多精彩内容

友情链接更多精彩内容