Introduction to Programming Assistant

Session Overview

  • Code Completion
  • ChatGPT3
  • Best Practices for Communicating:
    • Generation
    • Correction
    • Documentation
    • Language Translation

Code Completion

ChatGPT

ChatGPT

  • Large Language Model

  • IT CAN BE WRONG!

It Can Be Wrong

It Can Be Wrong

ChatGPT Guidelines

  • NO PERSONAL INFORMATION! EVER!!!
  • Double check the work!
  • Use it interactively
  • Iteratively refine your prompts
  • Prompt engineering matters (a lot). If you aren’t obtaining helpful results with one prompt, consider re-engineering your prompt (more on this tomorrow).

ChatGPT Guidelines

Documentation


def calculate_sum(number_one, number_two):
  result = number_one + number_two
  
  return result

“Please generate the docstring and comments for this python function:”

ChatGPT Guidelines

Generation

“Please develop a python function to calculate euclidean distance between two points.”

ChatGPT Guidelines

Correction

def some_function(input):
    for i in range(len(input)):
        if input[i] == 2:
            del input[i]
    return True

list_01 = [1,2,4,5,6]
some_function(list_01)

“This code does not work. Would you please fix it and explain what was wrong and how you fixed it. Thank you!”

ChatGPT Guidelines

Language Translation


“Please convert this code from R to Python:”

table4b %>% 
  pivot_longer(c(`1999`, `2000`), names_to = "year", values_to = "population")