Beyond Coding: Learn to interact with AI
Tags: ai, chatgpt, promptengineering, developer
Published: 2024-06-20 12:49:51

What is the latest buzzword in the market? If you guessed AI, ChatGPT or prompt engineering then you are on the right track. I am sure everyone of us has recently seen a few (maybe more than a few!) articles with the title “20 prompts that you need for …”

But do we really need someone else to write these prompts for us? Being developers should we not be curious enough to explore this new area and write our own prompts? 

These were some of the questions that came to my mind when I saw such posts and so I decided to dive deep into this new and exciting world of prompt engineering and explore it myself.

Before we begin this discussion, let me ask you a very simple question, what are prompts? In simple terms, a prompt is the act of verbalizing or expressing a desire to communicate something. This is precisely what we aim to achieve when writing prompts, i.e. to ask (inquire) about any subject matter we wish to explore. Subsequently, the next step is to understand how to enhance our prompting approach so that we can get meaningful and crisp responses.

## What you need to know?

Below are some of the key concepts that one should know to write good prompts.

####Keep it simple
Start by writing simple prompts and study the responses. Tweak a few words in the prompt and analyse how the response changes. Understand what works and what does not. Iterate over the prompts and refine.

####Use conversational tone
Communicate with the AI in a conversational tone where one participant is asking questions and the other, being highly knowledgeable, is answering the questions. Keeping this tone makes the whole interaction more human and makes it easier to understand.

####Understand the basic concepts
Follow some of the best practices of prompt writing like context setting, providing clear instructions, adjusting prompt length. It is also helpful when we provide background information relevant to the task as it reduces ambiguity. 

####Try different approaches
Experiment with different prompt structures, like using instructions, examples, conditionals, etc. and see what gives the best results.
If the task is complex then break it down into multiple sub-tasks and use structured prompts with steps.

####Refining Prompt Iteration
Iteratively refining prompts as per your requirements is one of the most important steps that needs to be followed. It enhances clarity and specificity of prompts. Also, it improves overall performance and usability of prompt-based systems

Finally, be curious, explore, experiment, and learn!

## Some common examples

Here are some examples of how you can write a simple prompt and iterate the same once you receive an output

- 
Here I first wrote a prompt asking the model to write a function and take an input of time in seconds and convert it to hh:mm:ss format.

![code-image 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9vnimhsatdlf4wi6v33.png)

After analysing the output, I felt the need to include edge cases in the function and so wrote a prompt asking it to consider all cases and refactor the code

![code-image 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cs0fk8b5rmzs50b14f0l.png)

- 
Creating JSON to mock any API

![code-image 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yyc702cirhynu0l7j6uv.png)

(PS: This has been generated in claude.ai)

- 
Refactor any code. But do not entirely depend on the output generated by the model, verify the generated code, and use your knowledge to judge if the output shown is better than the one you had written.

- 
You can use it to write test cases for any testing library. (Trust me this is a life saver!)

## Conclusion

Will AI replace the work that we do? I do not think at this point of time AI has reached that position where it can do the work of a developer. It is still learning and is very young to do so. I think what we need to understand and practice is how we can use this amazing new technology to make our work better and deliver faster results.