阿里 “通义灵码” 真的 “灵吗”,全保姆级实操

 最近很多朋友,都在关注阿里公测的“通义灵码”,我索性也安装了,准备看看它真的有说的那么“灵吗”?

图片

一、安装

官网:https://tongyi.aliyun.com/lingma/

安装方式:https://tongyi.aliyun.com/lingma/download

帮助手册:https://help.aliyun.com/document_detail/2590613.html

补充几个安装步骤:

1、我用的是IDEA,各位IDEA的小伙伴要注意从插件商店去安装,搜索“TONGYI Lingma”。

图片

2、安装完成后要重启,重启后可能会有一定的加载过程,比较慢。

图片

3、重启后,IDEA会提示你灵码要登录。

图片

图片

4、点击登录后会进入阿里云登录界面,登录自己的阿里账号。

图片

图片

图片

5、登录成功后,可以看看右边的栏目中找到“通义灵码”的插件,点击后即可对话。

图片

6、快捷键。

图片

二、初探

一)看看聊闲话的能力

安装这个的目的就是为了让它帮咱们写代码,现在一起来看看他写代码的能力,首先我尝试的问了一些题外话:

1、开发团队的问题

图片

回答很官方,哈哈。

2、看看它会多少种语言

图片

由于截图有限我把他的内容整理出来,能明确的是102种:

作为一款智能编码助手,通义灵码(TONGYI Lingma)具备处理多种编程语言的能力,能够理解并为用户提供以下主要编程语言的相关支持:

通用编程语言:

Java、Python、C、C++、C#、JavaScript、TypeScript、Rust、Swift、Go、Kotlin、Scala、Ruby、PHP、Perl、Objective-C、Dart、Erlang、Haskell、Lua、Julia、Groovy、R、Matlab

Web开发相关:

HTML/CSS、React、Vue.js、Angular、Svelte、jQuery、Bootstrap、Tailwind CSS、Webpack、Gatsby、Next.js、Nuxt.js、Jekyll、WordPress、Drupal、Laravel、Django、Flask、Express.js、Fastify、Node.js

移动开发:

Android (Java/Kotlin)、iOS (Swift/Objective-C)、Flutter、React Native

数据库与数据处理:

SQL (MySQL, PostgreSQL, SQLite, Oracle, SQL Server, etc.)、

NoSQL (MongoDB, Cassandra, Redis, Elasticsearch, etc.)、

GraphQL、Pandas、NumPy、SciPy、pandas-SQLAlchemy、dplyr (R)

脚本与自动化:

Bash、PowerShell、Ansible、Terraform、Chef、Puppet

数据分析与科学计算:

NumPy、Pandas、SciPy、Matplotlib、Seaborn、scikit-learn、TensorFlow、PyTorch、Keras、Theano、Spark MLlib、R Shiny

云计算与容器化:

Docker、Kubernetes、AWS SDKs、Azure SDKs、Google Cloud SDKs、OpenStack、Terraform、CloudFormation

其他工具与框架:

Git、Jenkins、Travis CI、CircleCI、GitHub Actions、Docker Compose、Makefiles、JUnit、pytest、Mocha、Chai、Jest、Enzyme、ESLint、Prettier、Black、Flake8、SonarQube、Jupyter Notebook

以上列举了通义灵码能够提供支持的部分编程语言、框架、库和服务。

3、是否能判断我当前的代码环境和开发环境

图片

嗯~意料之中吧。

三、看看发力点

一)代码补全

直接上干货,我在service中增加了一个方法,只给它把注释写好,让他来补写代码:

图片

组合键ALT + P:

图片

Tab键将代码做实,回车后会自动提示下面的代码:

图片

但是显然还没完成,我们在方法中间再让它补充一下:

图片

这次就完美了,哈哈总体来说,简单的代码还是可以写的。

图片

二)再看看查问题的能力

1、直白问题查找

图片

回答挺全面的,因为问题就很模糊,回答自不用说了。

三)选中代码进行bug查找

选中左边的文件认为有问题的代码,在右边的对话框中填入“/查找问题”,回车。

图片

图片

图片

从这些原因中进行分析和查找,多半能解决。

四)对问题进行搜索

解答大多数来自“stackoverflow”

图片

图片

四、尝试让他写个增删改查

下面我以Java为例,用rouyi框架做演示,让它来写一个增删改查试试:

一)先写Controller

图片

package com.example.app.controller.system;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.example.app.common.annotation.Log;
import com.example.app.common.core.controller.BaseController;
import com.example.app.common.core.domain.AjaxResult;
import com.example.app.common.core.domain.entity.CustomUser;
import com.example.app.common.enums.BusinessType;
import com.example.app.common.utils.SecurityUtils;
import com.example.app.common.utils.StringUtils;
import com.example.app.common.utils.poi.ExcelUtil;
import com.example.app.system.service.ICustomUserService;

/**
 * 自定义用户信息
 * 
 * @author Your Name
 */
@RestController
@RequestMapping("/system/customuser")
public class CustomUserController extends BaseController
{
    @Autowired
    private ICustomUserService customUserService;

    /**
     * 获取自定义用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomUser customUser)
    {
        startPage();
        List<CustomUser> list = customUserService.selectCustomUserList(customUser);
        return getDataTable(list);
    }

    @Log(title = "自定义用户管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:customuser:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomUser customUser)
    {
        List<CustomUser> list = customUserService.selectCustomUserList(customUser);
        ExcelUtil<CustomUser> util = new ExcelUtil<CustomUser>(CustomUser.class);
        util.exportExcel(response, list, "自定义用户数据");
    }

    // ... (省略导入功能相关方法,若需要请自行添加)

    /**
     * 根据自定义用户ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:query')")
    @GetMapping(value = { "/", "/{customUserId}" })
    public AjaxResult getCustomUserInfo(@PathVariable(value = "customUserId", required = false) Long customUserId)
    {
        if (StringUtils.isNotNull(customUserId))
        {
            CustomUser customUser = customUserService.selectCustomUserById(customUserId);
            return AjaxResult.success(customUser);
        }
        return AjaxResult.error("Invalid custom user ID");
    }

    /**
     * 新增自定义用户
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:add')")
    @Log(title = "自定义用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CustomUser customUser)
    {
        if (!customUserService.checkCustomUserNameUnique(customUser))
        {
            return error("新增自定义用户'" + customUser.getUserName() + "'失败,登录账号已存在");
        }
        // ... (根据实际需求添加其他唯一性校验,如手机号、邮箱等)

        customUser.setCreateBy(getUsername());
        // ... (如有需要,进行密码加密或其他初始化操作)
        return toAjax(customUserService.insertCustomUser(customUser));
    }

    /**
     * 修改自定义用户
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:edit')")
    @Log(title = "自定义用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CustomUser customUser)
    {
        customUserService.checkCustomUserAllowed(customUser);
        if (!customUserService.checkCustomUserNameUnique(customUser))
        {
            return error("修改自定义用户'" + customUser.getUserName() + "'失败,登录账号已存在");
        }
        // ... (根据实际需求添加其他唯一性校验,如手机号、邮箱等)

        customUser.setUpdateBy(getUsername());
        return toAjax(customUserService.updateCustomUser(customUser));
    }

    /**
     * 删除自定义用户
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:remove')")
    @Log(title = "自定义用户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customUserIds}")
    public AjaxResult remove(@PathVariable Long[] customUserIds)
    {
        if (ArrayUtils.contains(customUserIds, getUserId()))
        {
            return error("当前用户不能删除");
        }
        return toAjax(customUserService.deleteCustomUserByIds(customUserIds));
    }

    // ... (省略其他自定义用户管理相关功能,如重置密码、状态修改、授权等,若需要请自行添加)

    /**
     * 获取自定义用户所属部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:customuser:list')")
    @GetMapping("/deptTree")
    public AjaxResult customUserDeptTree(CustomUser customUser)
    {
        // ... (实现或调用相应服务方法获取自定义用户的部门树列表)
        return success(customUserDeptTreeList);
    }
}

代码还不错,基本满足要求,接下来我给它数据表的sql,告诉它用ORM用的MyBatis,让他生成domain文件、service层文件、mapper文件和xml文件,结果就差强人意了:

二)domain

图片

三)service

有点拉跨,想使用就得不停的连续问

图片

四)Mapper

直接给了个空接口

图片

五)XML

应该是回答字数限制,突然停止了,然后我让它“继续”。。。。

图片

图片

嗯~~~~它开始别的操作了,应该是上下文衔接不好。

综合看,不如代码生成器来的方便,能节约开发量吗,能节约,但不是很大,没那么玄乎。

五、它适合来干啥?

1、简单的代码补全,前提是你能够有逻辑能力,有清晰的判断,并且告诉它,你会引入其他类或方法来辅助它。

2、查找明显错误(逻辑性强的难点儿)

3、生成固定写法和算法

例如这样的:

图片

4、生成注释和解释代码

六、总结

总的来说,灵码还是挺灵的,但是如果想从众多 AI编码工具中脱颖而出,还得做几点加强:

1、超时问题,我用了2小时,大概出现了10次左右。

图片

2、应加强上下文联动,尤其回答不够,需要“继续”时。

3、给出相应的提示词Demo,让程序员更快的了解专用的提示词。

4、增加文件上传对文件进行分析,然后根据要求修复代码或者,生成改写代码。

5、能够分析当前打开代码的语言和环境,能够快速识别,能够给使用者更好的体验。


怎么样今天的内容还满意吗?再次感谢观众老爷的观看。

最后,祝您早日实现财务自由,还请给个赞,谢谢!

  • 36
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值