推荐一个免费的AI编程助手-Codeium

Codeium-免费的AI编程助手,支持几乎所有主流语言和IDE

Codeium官网地址 codeium.com

老实说现在没有AI编程助手,已经快不会写代码了。虽然IDE也支持一部分的代码补全,但相比于如今的AI编程工具,还是显得太简单了。

我个人用过的AI编程插件也有不少了,从最初的Tabnine,到收费的Copilot,再到Amazon Whisper,最后还是选择了Codeium。

原因也很简单,首先他是免费的,在免费插件中他效果最好,无论是补全、理解中文、对话式AI、甚至还有重构和解释代码功能。个人体验他起码有Copilot的60%-70%水准,而Copilot一个月10美刀的价格还是劝退了我。

安装插件

安装Codeium很简单,基本上主流的IDE插件市场上都有。我个人使用的Vscode和Goland,只要在市场搜索codeium,安装后注册登录即可使用。 在Vscode市场可以看到评分人数和评价都很高。

alt text 安装后也无需配置,开箱即用。在Vscode右下角有Codeium扩展的图标,在转动时就是在AI生成中。点击可以启用/禁用当前文件类型是否启用AI。

使用插件

  • 注意codeium对网络环境有一定要求,裸连有时候会连不上,建议使用魔法

接下来我们看一下codeium都能做什么

代码补全

代码补全是AI编程助手最重要的一环,这部分codeium只能算是及格,相比copilot会一次生成一大段代码,codeium有时候会需要你按几次tab键才能补全。

用注释告诉他实现一个递归计算文件夹大小的函数,下面是他生成的预览代码。 alt text

解释代码

在代码函数上方,会显示一些快捷操作,比如Refactor、Explain、Docstring等等。我们点击Explain让他解释这段代码

1
2
3
4
5
6
7
8
const copyResult = () => {
    const textarea = document.createElement('textarea')
    textarea.value = data.result
    document.body.appendChild(textarea)
    textarea.select()
    document.execCommand('copy')
    document.body.removeChild(textarea)
}

Codeium Explain:

This code snippet creates a textarea element, sets its value to the result, appends it to the document body, selects the content, copies it to the clipboard, and then removes the textarea from the document.

编写注释

同样是在代码函数上方,点击Docstring,帮你偷懒编写注释: alt text 生成注释后,点击Apply Diff直接帮你插入到代码中,属实是懒人福音了。

聊天对话

这年头AI工具不能聊天对话感觉已经落后时代了,让他写一个go语言泛型教程,好像有点实力。 alt text

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import "fmt"

func main() {
    // 泛型函数
    fmt.Println(contains([]int{1, 2, 3}, 2)) // true
    fmt.Println(contains([]string{"apple", "banana", "cherry"}, "durian")) // false

    // 泛型类型
    stack := NewStack()
    stack.Push(1)
    stack.Push(2)
    fmt.Println(stack.Pop()) // 2
    fmt.Println(stack.Pop()) // 1
}

// 泛型函数
func contains[T comparable](slice []T, item T) bool {
    for _, s := range slice {
        if s == item {
            return true
        }
    }
    return false
}

// 泛型类型
type Stack[T any] []T

func NewStack[T any]() *Stack[T] {
    return &Stack[T]{}
}

func (s *Stack[T]) Push(value T) {
    *s = append(*s, value)
}

func (s *Stack[T]) Pop() T {
    length := len(*s)
    if length == 0 {
        panic("stack is empty")
    }
    value := (*s)[length-1]
    *s = (*s)[:length-1]
    return value
}

总结时间

这是我2023年使用Codeium的总结,用了510小时,补全了5620次。而其实2023年我只用了不到半年的时间,用数据说话,可见codeium确实已经成为了我的工作好帮手。对目前阶段来说,AI是辅助工作和学习的好帮手和工具,至于未来会怎么样,我也不清楚。

Keep Learning
使用 Hugo 构建
主题 StackJimmy 设计