QT6开发高性能企业视频会议-8 利用VSCode+Copilot AI开发
Github Copilot是Github和OpenAI推出的AI编程辅助工具,之前版本的Github Copilot只有简朴的代码自动补全,根据注释生成一些代码等辅助功能。近期Copilot有了一次大的升级,加入了Agent模式,可以实现自然语言对话讨论和最紧张的,根据指定的上下文直接按指令生成或者修改项目代码,做到了雷同Cursor的体验,而且基础版是免费利用的。
付费版Copilot可以指定更多的AI模子,包括最新的Claude 3.7等,而且能利用无限次的token。
本文简朴先容怎样在Visual Studio Code中集成和利用Github Copilot,以下步调都需要科学上网。
在Visual Studio Code中集成Copilot插件
首先需要登录Github账号并启用Github Copilot。
Sign in to GitHub · GitHub
https://i-blog.csdnimg.cn/direct/68f2881c113843258b69db28350051da.png
然后我们需要为Visual Studio Code安装Github Copilot插件
https://i-blog.csdnimg.cn/direct/370b6ce7a93047388b9135b0233f1ab4.png
安装完成后,左侧工具栏会出现Copilot Chat的图标。
https://i-blog.csdnimg.cn/direct/a022097e29e64dc999e7d10d9d1b6a93.png
利用Chat模式
在Chat模式中,Copilot会自动把当前正在编辑的代码文件代入Chat上下文,我们也可以右键点击某个项目中的文件,在Copilot菜单中把它加入Chat上下文。同时Copilot还支持上传图片,选中代码片断甚至某个GIt Change作为上下文。
之后我们和Copilot的对话中Copilot会自动关联这些上下文的内容做出回应。
https://i-blog.csdnimg.cn/direct/b42ccbfecc184da0a1c24f4a33292905.png
https://i-blog.csdnimg.cn/direct/8136a117de04480188af6a6476a903c4.png
https://i-blog.csdnimg.cn/direct/52fd42ce25b146cb829c68252eaf7afe.png
这里是一个通过笔墨描述生成一个QML窗口的例子:
https://i-blog.csdnimg.cn/direct/a7e54b4d60b3493892ac1f2fd337f8cb.png
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
visible: true
width: 400
height: 300
title: "User Login"
Column {
anchors.centerIn: parent
spacing: 20
Text {
text: "Login"
font.pixelSize: 24
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
}
TextField {
id: usernameField
placeholderText: "Username"
width: parent.width * 0.8
anchors.horizontalCenter: parent.horizontalCenter
}
TextField {
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
width: parent.width * 0.8
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "Login"
width: parent.width * 0.8
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
// Handle login logic here
console.log("Username: " + usernameField.text)
console.log("Password: " + passwordField.text)
}
}
}
}
生成之后可以让Copilot帮忙修改
https://i-blog.csdnimg.cn/direct/7259ce8e9c674ed8bc8562a75ad3e129.png
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
visible: true
width: 800
height: 400
title: "User Login"
Row {
anchors.centerIn: parent
spacing: 20
Image {
source: "qrc:/images/left_image.png" // Replace with the path to your image
width: 300
height: 300
fillMode: Image.PreserveAspectFit
}
Column {
spacing: 20
width: 300
Text {
text: "Login"
font.pixelSize: 24
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
}
TextField {
id: usernameField
placeholderText: "Username"
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
}
TextField {
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "Login"
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
// Handle login logic here
console.log("Username: " + usernameField.text)
console.log("Password: " + passwordField.text)
}
}
}
}
}
Chat模式除了可以用自然语言进行交换,还可以利用一些关联到Visual Studio Code的预制指令,具体可以在Chat窗口中输入/查看
https://i-blog.csdnimg.cn/direct/0fd189957e1d40ef976f723a78454632.png
利用Edit模式
假如希望Copilot直接帮我们修改项目中的文件,可以利用Copilot的编辑模式。
在编写代码时,按下Ctrl+Shift+I,右侧会弹出Edit窗口,利用方式和Chat根本一样,不同的地方是Edit模式会直接把结果更改到你的代码文件中,在保存修改之前会弹出Diff窗口让我们确认Accept或者Discard。
https://i-blog.csdnimg.cn/direct/91dc4159689b4eca93f2aac96c8717e1.png
神旗视讯 -- 开源高性能的音视频体系
开源地址: https://gitee.com/sqmeeting
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]