方言を話すおしゃべり猫型ロボット『ミーア』をリリースしました(こちらをクリック)

Things to keep in mind when using ChatGPT in programming.

keep-in-mind-chatgpt-programing
This article can be read in about 13 minutes.

Introduction.

GPT-4o” was announced on May 13, 2024, and the programming code output is now as fast as GPT3.5, with the same accuracy of GPT4.

Personally, when I used to use GPT4, the idle time waiting for the output results was a little too long, and I had other things to do during that time (not good because my thoughts were cut off), but with GPT-4o, such things are no longer the case, and the programming speed is about 1.5 times faster. I feel that the programming speed is about 1.5 times faster now. Thank goodness.

In this issue, as a reminder to myself, I will summarize some things to keep in mind when utilizing ChatGPT in programming. Note that this applies to everything, not just programming.

Haste makes waste: First things first

As stated in the article “What are good prompts to give to [ChatGPT]. Six Tactics to Get Good Results” article, I still feel that the first step is crucial and “writing clear and specific instructions” is of paramount importance.

With the GPT-4o, there is a further sense of omnipotence, but when you throw in abstract instructions, the results of the programming output are either the day after tomorrow or redundant. Then, the engineer’s side is swept up in the results, and the engineer may get bogged down in repeated revisions based on the results.

Therefore, although it is tempting to suddenly paste the code into GPT-4o and write a fluffy prompt saying, “I want to do this,” it is necessary to stop there and organize in your mind in detail what kind of output you expect, the functions to be created, and the necessary conditions (awareness and attention span issues). (awareness and attention).

This is the same point as writing a conventional programming specification. It does not have to be as firm as a specification; it can be as simple as a list of bullet points, but it is important to “clarify the conditions and expected output,” which is the essence. This is not limited to programming. The overall picture of how and where to make changes needs to be envisioned in your mind in advance.

It is no exaggeration to say that by giving clear and specific instructions at the beginning, the time it takes to reach the final output can be reduced by 1/2 or even 1/3.

I am not sure that the prompt below is the best example in terms of clear instructions, but it is an example of the following.

ALTER TABLE users ADD COLUMN sleep_transition_time INT DEFAULT 10 COMMENT ‘Talking setting: sleep mode transition time’;

I have previously added a column here as default10, but I want to allow null and make it default null. What migration file generation command should I run?

To create a migration file, execute the following command.

$ cd migrations
$ migrate create -ext sql -format 2006010215 <filename>

They will respond to you as follows. If you check the content and it looks OK, just do as instructed.

Screenshot

It would also be a good idea to have the prompts for clarifying instructions chewed before the actual instructions are given.

Especially if the content spans multiple files, it is important to be organized and then tell GPT as you paste the code for the relevant part. Well, it is only a matter of time before GPT4’s Cursor editor (which I do not use) will make code suggestions across multiple files, so the future may not be so far away when GPT will be able to understand your less specific prompting instructions and finish the code to your liking. But it’s not too far away.

If GPT becomes too smart, the brain may degenerate more and more as humans no longer have to think (but it may still be good if it can output results separately), but it is still likely that the time to final output will be faster if only the initial instructions are thought and clarified by humans.

The rest of us no longer need to memorize or refer to detailed grammar rules and write them, but we still need to be able to read and check the GPT-generated code carefully for errors. Even if you can’t write it, you still need to be able to read it. At this time, too, it is necessary to ask questions to gpt each time there is anything in the generated code that is unclear or incomprehensible, and build up accurate code step by step, rather than moving on with a vague understanding.

If you keep going from one thing to another in a haphazard manner and then check everything at the end, it is inefficient, you forget, and it’s not good for you.

Refer to the official documentation for API-related information.

For example, try the following prompt instructions.

In response to the text entered by the user Create a python script that calls the open ai api with the prompt “Please correct any medical terminology errors and output the results” and

The actual code output by GPT-4o is shown below.

Screenshot

The way to call OpenAi and the way to get response is still the old method (openai.Completion.create()) and does not correspond to the latest. By the way, the latest method is (OpenAI().chat.completion.create()).

https://platform.openai.com/docs/guides/text-generation

Python
from openai import OpenAI 
 client = OpenAI() 
 
 response = client.chat.completions.create( 
   model="gpt-3.5-turbo", messages=[[ gpt-3.5-turbo 
   messages=[[.
     {"role": "system", "content": "You are a helpful assistant."} 
     {"role": "user", "content": "Who won the world series in 2020?"}, } 
     {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."} 
     {"role": "user", "content": "Where was it played?"} 
   ] 
 )

By the way, I have not changed my instructions to GPT4o to support the latest open ai api.

If you blindly trust the result of the output code and run it, you will naturally get an error and be left wondering, “Why is that? and you will be confused.

So, for API-related issues, it is faster to check the official documentation and check the USAGE, as GPT may not support the latest information.

good luck charm

I would also add the following instructions at the beginning and end of the prompt, although I honestly don’t know how effective this would be, as I have never done A/B testing.

(Introduction) You are a professional engineer.
(Body) Prompt body.
(End) Think step-by-step and give a clear and correct answer.

Superb assistant depending on how you use it.

GPT is excellent in that as long as clear instructions are given, the rest of the programming code is written automatically, eliminating the need to remember the detailed syntax rules and function declarations of each language.

If it really works, just paste the output as is, and it will work fine and be done.

Also, this is a trivial thing that has nothing to do with this case, but every time gpt4 tries to output the whole code, it is better to tell them “output only the modified part” so that they know what was changed and it reduces the time to wait for the output.

Copied title and URL