用Amazon CodeWhisperer画个爱心送你女友吧

        AI编程工具越来越流行,Amazon CodeWhisperer 是AWS亚马逊的一款AI编程工具,经过数十亿行 Amazon 和公开可用代码的训练,可以在编程的时候根据注释和代码的上下文提供代码建议。个人觉得如果你要用AWS的服务器开发程序的话,用Amazon CodeWhisperer确实是工作上的利器。

它支持15种语言:
  • Java

  • Python

  • JavaScript

  • TypeScript

  • C#

  • Go

  • PHP

  • Rust

  • Kotlin

  • SQL

  • Ruby

  • C++

  • C

  • Shell

  • Scala

它支持的浏览器:
Visual Studio Code,JetBrains,AWS Cloud9,AWS Lambda,AWS Glue Studio,JupyterLab,Amazon Sagemaker Studio

可以看到大部分的AWS的服务器编辑器它能很好的支持,毕竟是AWS训练的,所以它可以很方便的开发AWS的服务。例如Lambda就能很好的开发无服务器的代码,Amazon Sagemaker Studio能支持更好的开发AI的程序,他还支持我经常用的VSCODE。

Amazon CodeWhisperer的功能:

CodeWhisperer文档地址:

What is CodeWhisperer? – CodeWhisperer

CodeWhisperer的收费模式:

个人是免费的!个人是免费的!个人是免费的!

容我先用VSCODE作为例子。

使用教程:

1.下载插件:

2.注册并登录你的账号:

3.VSCODE左下方出现打勾的AWSbuilder和CodeWhisperer则证明你可以开始使用了

代码提示和自动生成使用的方式:

ALT+C,代码提示,生成按下TAB键

如何在CodeWhisperer中暂停和恢复自动建议

  1. 在VS Code中,从左侧边栏选择AWS图标。

  2. 在VS Code窗口的附近,展开Developer tool部分。

  3. 展开CodeWhisperer部分。

  4. 选择暂停位置所对应的符号就能暂停和恢复代码建议了

例子:

下面是我的演示例子:

我们来尝试下例子1,刚好有个项目需要将json里的时间戳修改为日期的形式,用CodeWhisperer试了下,首先有一个json,然后你想要查看时间戳真实的时间,您可以使用Python来解析JSON并转换时间戳为实际日期和时间。

你可以注释一下#将json的time改为日期的格式并且打印,然后就出来效果了。

用Amazon CodeWhisperer画个爱心送你女友吧

下面我们来尝试第二个例子:

这个例子有点复杂了。我打算用CodeWhisperer画个爱心。

第一次直接加入想要的注释

#draw red heart:明显失败了,左划了好几个都没适合的,看来提示词还是得精确一下

第二次,用ai,肯定要给更精确得promt,给注释添加更精确的代码,例如我在网上找到的爱心公式为x = 16sin^3(t) y = 13cos(t) – 5cos(2t) – 2cos(3t) – cos(4t)

#draw red heart,use x = 16sin^3(t) y = 13cos(t) – 5cos(2t) – 2cos(3t) – cos(4t)

按左右键选一个觉得符合的提示,暂时看来带相关函数的都可以试试

import turtle
import math

#draw red heart,use x = 16sin^3(t) y = 13cos(t) - 5cos(2t) - 2cos(3t) - cos(4t)
def drawHeart():
    t = turtle.Turtle()
    t.speed(0)
    t.hideturtle()
    t.pensize(2)
    t.color("red")
    t.begin_fill()
    for i in range(1000):
        x = 16*math.sin(i*0.01)**3
        y = 13*math.cos(i*0.01) - 5*math.cos(2*i*0.01) - 2*math.cos(3*i*0.01) - math.cos(4*i*0.01)
        t.goto(x,y)
    t.end_fill()
    t.penup()
    t.goto(0,0)
    t.pendown()
    t.color("black")
    t.write("I love you",font=("Arial",20,"normal"))
    t.hideturtle()
    turtle.done()
    turtle.bye()
    turtle.exitonclick()
    turtle.getscreen()._root.destroy()
    turtle.Terminator()
   

   
drawHeart()

然后,我想将爱心的尺寸加大,

直接在X的赋值函数后加入

x = x*20

y = y*20

import turtle
import math

#draw red heart,use x = 16sin^3(t) y = 13cos(t) - 5cos(2t) - 2cos(3t) - cos(4t)
def drawHeart():
    t = turtle.Turtle()
    t.speed(0)
    t.hideturtle()
    t.pensize(2)
    t.color("red")
    t.begin_fill()
    for i in range(1000):
        x = 16*math.sin(i*0.01)**3
        y = 13*math.cos(i*0.01) - 5*math.cos(2*i*0.01) - 2*math.cos(3*i*0.01) - math.cos(4*i*0.01)
        x = x*20
        y = y*20  
        t.goto(x,y)
    t.end_fill()
    t.penup()
    t.goto(0,0)
    t.pendown()
    t.color("black")
    t.write("I love you",font=("Arial",20,"normal"))
    t.hideturtle()
    turtle.done()
    turtle.bye()
    turtle.exitonclick()
    turtle.getscreen()._root.destroy()
    turtle.Terminator()
   

   
drawHeart()

这就是最后的效果了,所以,赶集试一下用Amazon CodeWhisperer画个爱心送你女友吧!让这份独特的爱意在舞台上绽放,为你们的爱情增添一抹独特的色彩。相信我,当你将这颗爱心展示给她时,她一定会被你的才华和心意所深深打动!

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年12月23日
下一篇 2023年12月23日

相关推荐