当前位置: 首页 > news >正文

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

然后我们需要为Visual Studio Code安装Github Copilot插件

安装完成后,左侧工具栏会出现Copilot Chat的图标。

使用Chat模式

在Chat模式中,Copilot会自动把当前正在编辑的代码文件代入Chat上下文,我们也可以右键点击某个项目中的文件,在Copilot菜单中把它加入Chat上下文。同时Copilot还支持上传图片,选中代码片段甚至某个GIt Change作为上下文。

之后我们和Copilot的对话中Copilot会自动关联这些上下文的内容做出回应。

这里是一个通过文字描述生成一个QML窗口的例子:

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帮忙修改

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窗口中输入/查看

使用Edit模式

如果希望Copilot直接帮我们修改项目中的文件,可以使用Copilot的编辑模式。

在编写代码时,按下Ctrl+Shift+I,右侧会弹出Edit窗口,使用方式和Chat基本一样,不同的地方是Edit模式会直接把结果更改到你的代码文件中,在保存修改之前会弹出Diff窗口让我们确认Accept或者Discard。

神旗视讯 -- 开源高性能的音视频系统

开源地址: https://gitee.com/sqmeeting

相关文章:

  • unity TextMeshPro动态字体使用
  • 流式抽样唯一元素方案设计
  • iconfont和TTF
  • 在VSCode 中使用通义灵码最新版详细教程
  • 【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.2.2倒排索引原理与分词器(Analyzer)
  • 供应链管理:ETO按订单设计 / MTO按订单生产 / ATO按订单装配 / MTS按库存生产
  • leetcode28.找出字符串中第一个匹配项的下标,KMP算法保姆级教程(带动图)
  • BUG日志:使用热点或免费加速器时git链接github出现端口22拒绝访问的解决方法
  • 一款在手机上制作电子表格
  • DeepSeek-R1:GPU编程自动化加速的新纪元
  • 操作系统:文件系统
  • Spring源码分析の构造方法推断
  • Android SystemUI深度定制实战:下拉状态栏集成响铃功能开关全解析
  • 设备健康管理系统在制造业的深度应用探索
  • 无人机 CAAC 执照考取全攻略
  • 第8天:面向对象编程入门 - 类与对象
  • 面试问题——如何解决移动端1px 边框问题?
  • 同步锁:同步实现的几种方式
  • NFC拉起微信小程序申请URL scheme 汇总
  • 一文掌握ADSL拨号代理的搭建方法,及详细使用
  • 人民时评:莫让“假俗乱”讲解侵蚀“文博热”
  • 西藏日喀则市拉孜县发生5.5级地震,震源深度10千米
  • 中方发布会:中美经贸高层会谈取得了实质性进展,达成了重要共识
  • 中美经贸高层会谈11日在日内瓦将继续进行
  • 深圳市政协原副主席王幼鹏被“双开”
  • 上海发布首份直播电商行业自律公约,禁止虚假宣传、商业诋毁