Is AI writing code reliable?

ChatGPT has been out for more than half a year, how many programmers use GPT to code? Although there is no data to support it, I feel that there are not many programmers coding AI. I asked a few friends, and their reply was that AI can't accomplish the tasks it wants to accomplish, and they have to write it by themselves in the end.

 

Is there really no way for GPT to help the program complete the task? I don't feel like it. But why does this happen? I conclude there are 2 reasons

 

  1. Prompt problems, such as not describing the requirements in detail enough, AI can only guess without knowing the details. If you can't describe the requirements clearly, AI will definitely not be able to help you complete the task. How to make demands on AI is likely to become a profession in the future. And I believe this time will not be too long.

  2. The expectations for AI are too high, and many codes replied by AI cannot be run immediately, and errors are likely to be reported during the process. In this way, you need to communicate with the AI ​​back and forth to get it done.

 

In fact, I have not done front-line coding work for many years, but in the attempt to use AI coding, I think the above two problems are not big.

 

First of all, we must learn to break down the requirements. Don't start by asking a big, comprehensive question. Just like writing a program yourself, one method solves one problem. Secondly, it is to learn to feed back the problems that arise to AI so that it can be corrected.

 

For example, I used GPT to complete such a task today: I have a folder with many pictures, and I want to use the method of OCR picture recognition to sort all the pictures by name, and then output the text content in order. If it was before, I may need to write it myself. But with GPT, the first version of the program was written in less than a minute. Although there is a small bug in the result returned for the first time, in one sentence, it can run normally after the modification.

 

 

The complete code is as follows:

import os
import requests
import json
import base64

# 定义接口地址和参数
url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
client_id = "your_client_id"
client_secret = "your_client_secret"

# 定义图片文件夹路径
img_dir = "your_image_folder_path"

# 获取图片文件夹中所有图片文件名并按读取顺序排序
img_files = os.listdir(img_dir)
img_files.sort()

# 定义最终文本变量
final_text = ""

# 循环遍历每个图片文件并识别
for img_file in img_files:
    # 拼接图片文件路径
    img_path = os.path.join(img_dir, img_file)
    
    # 读取图片二进制数据并进行base64编码
    with open(img_path, "rb") as f:
        img_data = base64.b64encode(f.read())

    # 定义请求参数
    params = {
        "image": img_data,
        "access_token": "",
        "detect_direction": "true",
        "language_type": "CHN_ENG"
    }

    # 获取access_token
    token_url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={}&client_secret={}".format(client_id, client_secret)
    token_res = requests.post(token_url)
    access_token = json.loads(token_res.text)["access_token"]
    params["access_token"] = access_token

    # 发送POST请求识别图片文字
    res = requests.post(url, data=params)

    # 解析响应结果并拼接文本
    res_json = json.loads(res.text)
    if "words_result" in res_json:
        words_result = res_json["words_result"]
        for words_item in words_result:
            final_text += words_item["words"]
            final_text += "\n"

# 输出最终文本
print(final_text)

 

I am using Baidu's image recognition interface here, and I need to apply to Baidu Smart Cloud to apply for an application to get the client_id and client_secret.

 

Total time is less than 5 minutes. Of course, because I have a little programming foundation, so when I see an error at runtime, I know where the problem is. If you don't have a little programming foundation, I believe you can solve it by interacting with AI. This kind of solving process can help you learn programming.

 

I will use the same prompt later to ask questions in GPT4, and the obtained code can be run directly. Now GPT4 is still very expensive, but for GPT3.5, you can use the website I built: https://ai.yunyoute.cn Pure benefits, free, no registration required, out of the box.

 

I believe that with the advancement of AI, a lot of coding work can be replaced. If you haven't started yet, I suggest you try it now.

 

ps: Some students don't know how to ask questions to GPT. You can try to use the following prompt words when asking about GPT:

 

You will play a prompt engineer expert, and you know very well which questions can guide AI to provide satisfactory professional answers.

 

You'll focus on guiding me to design the policies and prompt statement structures needed to make GPT generate specific content with minimal redundancy. For each resource, provide a concise summary and highlight specific references that were helpful in designing effective directives. Also, include example demonstrations to help me understand how the concepts and strategies in it can be applied to prompt engineering.

 

I'm new to GPT and I'm having a hard time expressing my needs clearly. And don't understand the limitations of GPT not being able to network directly. I hope to guide me step by step through the questions to complete the description of the requirements, so that it can become a prompt that is clear, concise and has sufficient background.

 

Output template:

Guidelines:

Your prompt design guidelines use concise, easy-to-understand, and precise explanations to guide me to iteratively design prompts.

 

  • For each improved result, give your assessment score on a 5-10 scale and add guidance to suggest areas for improvement. If score >= 8, ask: "Do you want to run this prompt?"

  • Comes with options "um" and "no". If I say yes, run the last tip you suggested. Otherwise, please generate a better hint for me.

  • It's important to make sure to run the prompt when I say yes. Please continue with this prompt until I say "stop" or you run the prompt.

  • While using Markdown where possible, make sure our output is readable and aesthetically pleasing, using underlined styles to highlight key points.

answer:

After the boot task is completed, you can turn back into GPT to answer my question.

 

Thanks.

It will judge whether it needs to add details based on your question, so you can write better prompt words by going back and forth a few times.

The author of this reminder is: Keyboard Teacher, he launched a "GPT Application Introductory Course with Zero Basics" during the geek time, and it has just been launched. There are a lot of dry goods in this course. If you are interested, you can also go and have a look.

 

 

おすすめ

転載: blog.csdn.net/sys025/article/details/131670941