Amazon CodeWhisperer 开箱初体验

人工智能
Amazon CodeWhisperer
云上探索实验室
0
0
> 文章作者:Coder9527 科技的进步日新月异,正当人工智能发展如火如荼的时候,各大厂商在“解放”码农的道路上不断创造出各种 Coding 利器,今天在下就带大家开箱体验一个 Coding 利器: **[Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail)。** 话不多说,开撸! 准备环境和开发工具:Win11 系统,VSCode,python3.9(环境变量已添加) Amazon Toolkit 插件安装需要一个邮箱以及设定一个密码以便设置 Amazon Builder ID 并激活 [Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail) 这对于没有亚马逊云科技账号的开发者来说可以很方便的使用亚马逊云科技系的服务了。 激活 [Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail) 后我们的 VSCode 是这样的。如下图: ![image.png](https://dev-media.amazoncloud.cn/da185f2523424c07a5479a2ae79bda0a_image.png "image.png") 代码自动建议默认是打开的,另外还可以提供安全扫描服务等。 ### 1.代码生成的自动建议 于是让 [Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail) 先来一个简单的,生成打印 hello world 函数: 在 py 文件中输入: ``` # a function named print_hello_world that prints "Hello World" to the screen. ``` ![image.png](https://dev-media.amazoncloud.cn/b3f0366d2e30453fb4bd9c55f54c6cbf_image.png "image.png") 稍等片刻,它会自动提示函数名定义,按 Tab 键确认生成函数定义。 ![image.png](https://dev-media.amazoncloud.cn/12ee2b7795a9423bb2f220af198e7b4f_image.png "image.png") 然后是函数体以及调用: ![image.png](https://dev-media.amazoncloud.cn/19b1c7d56eb04cd28a35f73a7de8e338_image.png "image.png") 我们运行一下试试: ![image.png](https://dev-media.amazoncloud.cn/09197d0f03a246da82427519d1558e95_image.png "image.png") 运行完成。 接下来再撸一个求斐波那契数列第 n 位数的函数: ![image.png](https://dev-media.amazoncloud.cn/33e4731304674b17b4d87b1ea86a5ac5_image.png "image.png") 生成运行成功,这个很考验英文描述能力,希望以后能增加解读汉语的功能!! ### 2.代码风险检测 我们看看 [Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail) 对于除数为零的代码风险能不能检测到: ![image.png](https://dev-media.amazoncloud.cn/522ee784fd324266bb2b479c67cb09d0_image.png "image.png") 竟然是:未在工作区检测到问题。 我和我的小伙伴们都惊呆了,说实话心理很忐忑。。。。。。 非得运行一下才能报出来问题。当然我写的这个除数为零的比较明显,如果能在比较隐藏的深的代码中检测到除数为零问题,那简直是很有帮助的。 ![image.png](https://dev-media.amazoncloud.cn/7ce74f889e294ca08053879df869e5f9_image.png "image.png") 对于内存溢出我们来测试一下看看能不能检测出来: ``` def max_recursion(n): if n == 1: return 1 else: return n * max_recursion(n-1) print(max_recursion(1000000)) ``` ![image.png](https://dev-media.amazoncloud.cn/1c15c131a0c94b628d7ce0a486276f19_image.png "image.png") 来运行一下, ![image.png](https://dev-media.amazoncloud.cn/28a1346c74dd4156ba2b5e9d268f41c9_image.png "image.png") 啊,这。。。抱歉,是在下肤浅了。。。 总体体验下来,[Amazon CodeWhisperer](https://aws.amazon.com/cn/codewhisperer/?trk=cndc-detail) 表现还是不错的生成的代码比较规范,我这里只用 python 测评了一下,有空在用其他语言试试。 好了,达摩克里斯之剑入鞘! 感觉没过瘾的小伙伴们请移步☞ ☞ ☞ ☞ ☞️ ***[亚马逊云科技中国峰会](https://link.zhihu.com/?target=https%3A//summit.awsevents.cn/2023/form.html%3Fsource%3DaHMZ6Q20We4igheElTULyinBa1qRTISgfZcMsoZCBuqdqMRgsBt0cSfDnLS2uBkb?trk=cndc-detail)***
0
目录
关闭