OpenAI ChatGPT usage example (programmer)

As a programmer, when I know that ChatGPT comes out or GPT3 comes out, I have joys and sorrows. The joy is that it can help me write code, refactor code, write comments, write tests,,. Wow, it sounds so exciting. I can no longer write test classes, don't have to worry about chasing 80% test coverage every day, don't have to write some POC code crazy Google, don't have to write code comments Thinking hard. The worry is that it does so many things for me, am I useless? Are programmers like me really useless? Let's see what ChatGPT can do for me.

1. Programming application

1.1. Generate example code (Coding Generation)

ChatGPT helps us produce the example code we need. And the accuracy rate is very high. It doesn't matter even if you don't understand a certain language, it lowers the threshold for programmers to a certain extent.

I have three sets of data, the first set is from Monday to Friday, the second set is the specific time of the day, and the third set is the number of users. Please use python to generate an algorithm for predicting the number of future users

 

1.2. Debugging code (Debugging)

ChatGPT's bug-fixing capabilities are also a valuable tool for programmers. It can assist in debugging code by suggesting possible causes of errors and suggesting workarounds.

After one step of debugging the following code, chatgpt added a check of 0 to the count variable for me to prevent the error of dividing by 0.

查一下下面代码错误
def calculate_average(numbers):
   total=0
   count=0
   for num in numbers
     total +=num
     count +=1
   average = total/count
   return average

1.3. Code refactoring (Clean code)

 source 

help me refactor below python code 

def calculate_price(quantity, price):

     total = quantity * price
     if total > = 100:
        discount = 0.1
     else:
       discount =0 
    final_price = total * (1- discount)
    return final_price

1.4. Code Completion

ChatGPT can help complete the code, based on the context and the current code, predict the next few lines or paragraphs of code. This is especially beneficial for programmers who may not remember all the syntax and features of the programming language they are using, saving time and effort

 1.5. Commenting the code (Documentation)

When programmers input their code into ChatGPT, it can suggest suitable document templates according to the programming language and the kind of code being recorded. For example, if the code is a function, ChatGPT can propose a function documentation template, including parameters, return value, and a description of the function's goal

 

Comment the code for me

Can you debug below code 
def calculate_average(numbers):
   total = 0
   count = 0
   for num in numbers:
     total += num
     count += 1
   average = total / count
   return average

1.6 Writing Test cases

It feels like I can stop worrying about annoying code coverage.

generate python test case for below calculate_average method

def calculate_average(numbers):
    total = 0
    count = 0
    for num in numbers:
        total += num
        count += 1
    if count == 0:
        return 0  # To avoid division by zero if the list is empty
    average = total / count
    return average
 

1.7 Explain coding techniques and concepts

ChatGPT can provide explanations and examples about programming concepts, software products, syntax and functions, which is very helpful for learning and understanding programming languages. This is especially useful for beginning programmers who may not be familiar with programming concepts, or experienced programmers who are using a new programming language.

2. Translation

ChatGPT can be used in translation services, which can automatically translate text from one language to another.

3. Example of ChatGPT + Knowledge Base answering questions

With the help of the powerful comprehension of the chatgpt model and the company's internal knowledge base, it can automatically answer users' questions about the company's internal affairs. If only chatgpt is used, chatgpt cannot answer the unique business knowledge and questions within the company. The second is that only the knowledge base can neither understand the customer's questions well nor organize the language to answer the questions.

As an advanced chatbot named Skippy, your primary goal is to assist users to the best of your ability.
 
START CONTEXT
Login to VideoGram from Website
1. Open your web browser and go to the VideoGram website.
2. Click on the “Login” button located in the top right corner of the page.
3. On the login page, enter your VideoGram username and password.
4. Once you have entered your credentials, click on the “Login” button.
5. You should now be logged in to your VideoGram account.
 
Login to VideoGram from Mobile App
1. Open the VideoGram app on your mobile device.
2. On the main page, tap the “Login” button located in the bottom right corner.
3. On the login page, enter your VideoGram username and password.
4. Once you have entered your credentials, tap the “Login” button.
5. You should now be logged in to your VideoGram account.
END CONTEXT
 
SKIPPY: Hello, I’m Skippy! How can I help you?
USER: I can’t find the login button.

SKIPPY:

Guess you like

Origin blog.csdn.net/keeppractice/article/details/131257488