Thursday, November 23, 2023

Exploring GitHub Copilot

GitHub Copilot is a game-changer in the coding world. It’s like having a coding “genius” sitting right next to you, ready to help you at any time. Yeah, you read that right. It’s like having a very senior developer available for all your questions whenever you need them. And here's why I'm especially thrilled: As I get ready for an internal workshop on December 7th at our London office, I'm preparing a session about this very exciting topic. In the run-up to this event, I've been diving deep into GitHub Copilot's capabilities, and I’m happy to share my findings with you over this blog post.

If you want to learn more about GitHub Copilot, I recommend that you take the Microsoft learning path: “GitHub Copilot Fundamentals - Understand the AI pair programmer” that served as the primary source of content for this blog post.

What is GitHub Copilot?


In a nutshell, GitHub Copilot (going forward, Copilot) is a virtual, AI pair programmer that can help you write code faster and with less work. It works tirelessly by your side offering autocomplete-style suggestions on your code and comments. 

Research reveals that developers with access to Copilot finished their programming tasks 55.8% quicker than a control group without the AI pair programmer by their side. This demonstrates that Copilot increases developer productivity significantly and is an added value for those using it. For the full research, see The Impact of AI on Developer Productivity: Evidence from GitHub Copilot.

Copilot vs. ChatGPT


During my research, I considered whether ChatGPT can serve as an alternative to an AI pair programmer such as Copilot. At the end of the day, ChatGPT is free and user friendly, plus my colleagues might already be using it. Now, although ChatGPT is free and appealing, Copilot has more to offer for people who write code. To illustrate, I created the following comparison.

Feature

ChatGPT

GitHub Copilot Individual

Subscription cost

Free

$10/month

Primary function

Conversational AI

AI pair programmer

Availability

Web-based application, mobile app

IDEs (Integrated Development Environments)

Audience

General public, various industries

People who write code

Model

GPT-3.5, focused on natural language or code

Codex, a modified version of GPT-3, focused on code

Personal use

Yes, general usage

Yes, primarily for coding

Ease of use

User-friendly interface

Requires familiarity with IDEs

Learning and improvements

Pre-trained, continuous learning from interactions

Pre-trained, learns from code repositories and interactions


Copilot is based on the OpenAI Codex model, a programming model, that is focused on any type of programming tasks such as creating functions and fixing bugs. If you use the Copilot Chat to ask for support with preparing a dinner party, you will get the following answer: Sorry, but I can only assist with programming related questions. The focus of Copilot on programming tasks and the additional features it brings around that, makes it a strong peer to any person who writes code.

Now, if you don’t have access to Copilot, ChatGPT serves as an alternative, but it isn’t as specialized in programming tasks as Copilot.

Licenses


Copilot offers three licensing plans: Individual, Business, and Enterprise (release planned for February 2024). For more details on the different licenses and benefits, see GitHub Copilot pricing. This blog post focuses on the capabilities of the GitHub Copilot Individual plan.

How Copilot works


Copilot runs as a plugin within popular IDEs such as Visual Studio Code, Visual Studio, JetBrains, or Neovim. You can also use Copilot via GitHub Codespaces, a hosted developer environment that runs in the cloud.

When you type in your IDE, Copilot considers the context of the code already written, including comments, the filename, the file extension, and other open files in the IDE. This context goes through a proxy that filters out hate speech and personal data before it’s sent to Open AI. The AI model analyzes the context and generates code suggestions. These suggestions are displayed in the IDE in real-time, offering one or more alternatives for you to choose from. You can then modify, accept, or reject these suggestions. 

Your interaction helps Copilot provide more accurate suggestions over time as it adapts to your coding style. Copilot also uses your feedback on the suggestions to further improve the model. I’m not sure however whether this feedback loop also applies to Copilot for Business that has a major focus on data privacy.

Some practical tips 😉


During my hands-on trial with Copilot, I didn’t see the code block suggestions. A quick Ctrl + Enter (Windows) brings up the Copilot completions panel with many code suggestions. Also, you can accept a code suggestion using the Tab key (Windows). 

One special aspect that applies to Copilot, as described by Microsoft, is “Surround”. This means that Copilot uses the code you've already written—including comments, the filename, the file extension, and other open files in the IDE—to provide more tailored code suggestions. Consider opening more files in your IDE to provide extra context to Copilot.

Prompt engineering


You can't talk about successful generative AI interaction without talking about prompt engineering. The art of prompt engineering is crucial in reaching Copilot's full potential. A prompt is your instruction to the AI, and the more accurate and clear your prompts are, the better code suggestions Copilot generates. For example, using a comment like “// Create an API endpoint” isn't specific enough and can result in an output that doesn't meet your intentions. However, if you are more specific and define a clear scope, such as “// Create an API endpoint using the React framework that accepts a JSON payload in a POST request”, the output will more likely meet your expectations. Like anything in life, repeatedly practicing helps you get better, in this case, with prompt engineering. To learn more about prompt engineering, see Prompt Engineering Guide.

Summary


GitHub Copilot is more than a tool; it's the next level in programming and I wish Copilot had been there when I was an active developer. Its seamless integration into IDEs transforms it into the perfect programming “buddy” directly where you need it.

There might be many other features that I haven't explored, but I definitely loved these:
  • Code suggestion: Suggestion of one or more code alternatives that you can accept, reject, or modify. The suggestions appear when you start to write code or by writing natural-language comments that describe your intent.
  • GitHub Copilot Chat: A feature that makes difference, offering a conversational programming experience and responding to your questions with insights from your code's context and cursor position in the IDE. This helps you avoid context switching and navigating interruptions to look for support on the internet.
  • Surround: Copilot’s ability to use additional information (the code already written, including comments, the filename, the file extension, and other open files in the IDE) around a comment or code as context for the response.

I look forward to finishing my slides for the upcoming workshop and soon having a great time with my colleagues as we discuss and apply Copilot.

See more


Thanks for reading,
Jarbas

Wednesday, November 8, 2023

Integrate with Announcements in Viva Connections using the Microsoft Graph API

In the constantly evolving Microsoft 365 world, there's always something new to explore. One of the latest additions to catch our attention is the Announcements feature in Viva Connections. This feature introduces publishing capabilities to Viva Connections, enhancing communication within organizations by allowing communicators to share targeted, time-sensitive updates and information with their team members. In this post, I share with you my findings about how to extend Viva Connections Announcements using the Microsoft Graph API.

Anatomy of Announcements 

First things first, behind the scenes Announcements is not a common list in SharePoint, but a document library that can be accessed directly via Viva Connections or in SharePoint via the following URL: {SiteUrl}/_layouts/15/announcements.aspx. Communicators can use this area to create, manage, and share announcements to keep their team informed. Technically, an announcement is stored in XML format as an .aspx page.

Key properties for announcements:

  • Audience Targeting: When creating an announcement, audience targeting is essential and mandatory. You can target up to 10 audiences, which can be Microsoft Entra ID security groups or Microsoft 365 groups. This ensures that your message reaches the right people.
  • End date and time: Setting an end date and time for your announcement is mandatory. You can schedule it to remain visible for up to two weeks from the original publishing date.
  • Message: The message is where you convey the details. Maximum of 250 characters.
  • Title: Each announcement must have a title but keep it concise as you're limited to 60 characters.
  • Schedule to send later: If timing is crucial, you can schedule your announcement to send later. Scheduling is available only in half-hour increments, so plan accordingly.

Accessing Announcements


The most recent announcement takes the spotlight in Viva Connections. The next four announcements are accessible through a carousel format. If you want to view all announcements, a "See all" button opens a modal dialog listing all announcements in descending order.

Announcements in Viva Connections


Extending Announcements 


Microsoft Viva Connections has had so far limited extensibility options, primarily related to Dashboard cards (aka. adaptive card extensions). However, the landscape is changing with the introduction of new Viva Connections features such as Announcements and Company Links. These features leverage the SharePoint infrastructure, opening the door to a wider range of integration scenarios. Now, you can integrate with SharePoint to enhance the Viva Connections experience.

Extending via the Microsoft Graph API


At the time of this written, Microsoft hasn’t introduced a dedicated API set to integrate with Announcements in Viva Connections. However, you can use the driveItem API to seamlessly integrate with the Announcements library in SharePoint. The following examples show the requests I used to create a new announcement in Viva Connections.

Downloading an announcement


I first ran a GET request to download an existing announcement from the Announcements library.


This is what the response object looks like:


Uploading an announcement


You can upload announcements in the form of .aspx pages to the Announcements library. For this example, I updated the XML content of the previous response before uploading the new announcement to the Announcements library.


The previous request creates a new announcement in the Announcements library; however, the announcement isn’t yet visible in Viva Connections. To ensure your announcement appears in Viva Connections, remember to publish the page. Note that you'll need to check out the .aspx page before you can proceed with checking it in and publishing it.

Checking out the .aspx page (announcement)



Checking in and publishing the .aspx page (announcement)



Exploring deeper with internal APIs


For those who enjoy taking a deeper look at internal APIs, I found an endpoint that returns announcements the signed-in user has dismissed.

https://example.sharepoint.com/sites/homesite/_api/EmployeeExperience/GetAnnouncementsState. 

The EmployeeExperience path in this endpoint already exists in Microsoft Graph. I’m curious whether Microsoft plans to extend the employeeExperience resource in the future to expose other Viva APIs publicly 🤔

API integration considerations


While Announcements in Viva Connections offer powerful communication capabilities, it's worth noting that Microsoft doesn't provide dedicated Viva Connections APIs for seamless integration. To work with Announcements, you have to rely on SharePoint operations. However, this approach can be risky, as Microsoft can change the structure of the Announcements library without prior notice. Announcements are saved in XML format on .aspx pages and relying on this XML structure can be challenging because Microsoft can alter it at any time. This represents a challenge for building production-ready integrations, especially considering the ever-changing landscape of Microsoft 365.

In conclusion, Announcements in Viva Connections are a valuable tool for enhancing communication within your organization. Communicators have an additional instrument with support for audience targeting that they can use to increase their reach. As a developer or ISV, understanding the extensibility options and the potential challenges can help you make the most of this feature and potentially extend Microsoft’s services.

See also



Thanks for reading,
Jarbas