Source-linked AI summary
GPTutor: a ChatGPT-powered programming tool for code explanation
Eason Chen, Ray Huang, Han-Shin Chen, Yuen-Hsien Tseng, Liang-Yi Li
TL;DR
Learners and new employees need tailored help understanding unfamiliar code, while existing NLG explainers may miss domain logic by considering only the current file. GPTutor is a Visual Studio Code extension that uses relevant source code and ChatGPT prompts to explain selected code. The paper reports more concise and accurate explanations than vanilla ChatGPT and GitHub Copilot, alongside positive preliminary user feedback.
Problem
Learners and new employees may need tailored help understanding unfamiliar code, while existing NLG explainers may miss domain logic by considering only the current file.
Source: §1 · p. 1, §2.2 · p. 3Method
GPTutor is a Visual Studio Code extension that collects relevant source code and uses ChatGPT prompts to explain selected code.
Source: §1 · p. 2, §3.2 · p. 5Results
Takeaways & Limitations
The authors see GPTutor as a potential way to offer students convenient, personalized computer-science learning experiences.
Source: §6 · p. 6
Abstract
from arXiv · showhide
Learning new programming skills requires tailored guidance. With the emergence of advanced Natural Language Generation models like the ChatGPT API, there is now a possibility of creating a convenient and personalized tutoring system with AI for computer science education. This paper presents GPTutor, a ChatGPT-powered programming tool, which is a Visual Studio Code extension using the ChatGPT API to provide programming code explanations. By integrating Visual Studio Code API, GPTutor can comprehensively analyze the provided code by referencing the relevant source codes. As a result, GPTutor can use designed prompts to explain the selected code with a pop-up message. GPTutor is now published at the Visual Studio Code Extension Marketplace, and its source code is openly accessible on GitHub. Preliminary evaluation indicates that GPTutor delivers the most concise and accurate explanations compared to vanilla ChatGPT and GitHub Copilot. Moreover, the feedback from students and teachers indicated that GPTutor is user-friendly and can explain given codes satisfactorily. Finally, we discuss possible future research directions for GPTutor. This includes enhancing its performance and personalization via further prompt programming, as well as evaluating the effectiveness of GPTutor with real users.
1 Introduction
The paper introduces GPTutor, a Visual Studio Code extension that uses ChatGPT to explain source code. It targets difficulties with personalized programming support and understanding unfamiliar code, and claims an advantage over other code explainers through prompt design.
- High demand for coding education and teacher shortages make personalized classroom support difficult, while unfamiliar or poorly maintained code can challenge learners.Source: §1 · pp. 1–2
- Students, language learners, and new employees can use GPTutor for explanations of coding problems, example code, and codebase business logic.Source: §1 · p. 2
- GPTutor is a Visual Studio Code extension that uses the OpenAI ChatGPT API to explain source code.Source: §1 · p. 2
- The paper claims GPTutor surpasses vanilla ChatGPT and GitHub Copilot through advanced prompt designs.Source: §1 · p. 2
- The paper discusses applications, limitations, and future research directions for code explanation applications such as GPTutor.Source: §1 · p. 2
2 Background
NLG generates human-like language by predicting continuations, and added prompt context can make desired outputs more likely. Code explainers apply NLG to programming, but may miss cross-file logic or produce irrelevant explanations; GPTutor analyzes function source code and is described as more concise and accurate.
2.1 Natural Language Generation
- NLG uses algorithms to produce human-like language, generating likely continuations that can be fictitious as well as plausible.Additional context in a prompt increases the likelihood of the desired text; Figure 1 illustrates output probabilities.Source: §2.1 · p. 2, Figure 1 · p. 3
- Prompt programming adds context to increase the likelihood of a desired output, a technique proposed for using language models as context-based programming tutors.For code explanation, the model can draw on programming code and its comments or explanations.Source: §2.1 · p. 2, §2.2 · p. 3
2.2 Using NLG for Programming Code Explanation
- Existing code explainers may overlook or speculate about domain logic when relevant objects are imported from other files, especially in object-oriented code.They may also provide excessive, irrelevant, or fictitious information, or explanations that are not satisfactory for new, unpopular, or private libraries.Source: §2.2 · pp. 3–4
- GPTutor analyzes a function's source code and is described as providing the most concise and accurate explanations among the compared code explainers.Figure 3 compares explanations from ChatGPT, GitHub Copilot, and GPTutor.Source: §2.2 · p. 4, Figure 3 · p. 4
3 Implementation of GPTutor
GPTutor is a Visual Studio Code extension that gathers file and function context, then sends a designed prompt to ChatGPT for a code explanation.
3.1 Building GPTutor as a Visual Studio Code Extension
- GPTutor was built as a TypeScript Visual Studio Code extension, with the user's OpenAI API key stored in the extension's global state.The extension is implemented using the Visual Studio Code extension development environment.Source: §3.1 · p. 5
- On an explanation request, GPTutor identifies the file language, reads the current file, and retrieves a function's source when the cursor is on that function.The extension uses Visual Studio Code APIs for these steps.Source: §3.1 · p. 5
3.2 Getting answer by ChatGPT API with prompt programming
- GPTutor uses the collected data to form a prompt for gpt-3.5-turbo through the OpenAI API, with the tested Figure 4 format producing the most favorable results.Figure 4 shows the prompts used to feed the model.Source: §3.2 · p. 5, Figure 4 · p. 5
4 Current Results
GPTutor is publicly available, and preliminary interviews with students, teachers, and coding boot-camp tutors were positive about its usability and explanations.
4 Current Results
- GPTutor is published in the Visual Studio Code Extension Marketplace, and its source code is openly accessible on GitHub.The paper reports both the marketplace publication and public source code.Source: §4 · p. 5
- Preliminary interviews with students, programming teachers, and coding boot-camp tutors indicated that GPTutor is user-friendly and explains given code satisfactorily.The reported feedback comes from user interviews.Source: §4 · p. 5
- Interviewees especially valued GPTutor's ability to include relevant source code behind functions in prompts for thorough explanations.The paper highlights this capability in its account of user feedback.Source: §4 · p. 5
5 Discussion and Future Works
The discussion proposes prompt improvements for performance and personalization, and plans real-world evaluation of GPTutor's effect on students' programming comprehension.
5.1 Enhance performance and personalization by prompt programming
- Heuristic search for relevant code and varied prompts are proposed to improve GPTutor's performance and tailor explanations to user preferences.The authors propose transforming retrieved code into possible prompts to offer varied explanations and a more personalized experience.Source: §5.1 · p. 6
5.2 Evaluate the effectiveness of using GPTutor in the real world
- The planned evaluation will observe students using GPTutor on programming assignments and assess relationships between grades and usage frequency.The authors propose collaborating with course lecturers and using Between-Subjects Design and Interrupted Time Series Analysis.Source: §5.2 · p. 6
6 Conclusion
GPTutor collects relevant code in a Visual Studio Code extension and uses ChatGPT to explain selected code. Comparisons favor its explanations over Vanilla ChatGPT and GitHub Copilot, and the authors see potential for convenient, personalized learning.
6 Conclusion
- GPTutor delivers the most concise and accurate explanations compared with Vanilla ChatGPT and GitHub Copilot.Source: §6 · p. 6
- GPTutor collects relevant code and uses the OpenAI ChatGPT API to explain the chosen code.Source: §6 · p. 6
- The authors believe GPTutor can enhance computer science education and offer each student convenient, personalized learning in the future.Source: §6 · p. 6