DEV Community

Samarth Funde
Samarth Funde

Posted on

AI_ASSISTED_DAY_2 (Prompt Engineering)

✅ What is Prompt Engineering?

Prompt engineering is the process of designing and optimizing prompts (instructions given to AI models like ChatGPT) so that the model gives accurate, useful, and predictable outputs.

It focuses on:
How to ask
What context to include
How to structure the input

Reducing token usage (cost optimization)

✅ Cost Optimization in Prompt Engineering

Prompt engineering helps reduce token cost (usage cost) by:

1. Reducing Prompt Length
Use short and clear instructions instead of long paragraphs.

2. Using Structured Prompts
Tables, bullet points, or templates reduce repetition.

3. Reusing Context Instead of Rewriting
Give only the required information—avoid sending full documents repeatedly.

4. Caching Responses
Save earlier outputs instead of regenerating.

5. Using the Smallest Model Needed
Use cheaper/smaller models for simpler tasks.

6. Avoid Over-specifying
Don’t add unnecessary details (“write like Shakespeare”).
More tokens = more cost.

Types Of Prompting
**
**✅ Zero-Shot Prompting

Definition:
The model is asked to perform a task without giving any example.

Example:
“Classify this message as spam or not spam:
‘You won a free iPhone, click here.’”

✅ Few-Shot Prompting

Definition:
You give the model a few examples (2–5) before asking it to answer.

Example:

Example 1: Positive

Example 2: Negative

Example 3: Positive

Now classify this: "The movie was terrible."

✅ Multi-Shot Prompting

Definition:
You give the model many examples (more than a few) to teach the pattern.

Used in:

Large instructions
Training-like scenarios
Complex reasoning tasks

✅ CoT Prompting (Chain-of-Thought)

Definition:
You ask the model to show step-by-step reasoning before giving the final answer.

Example:
“Explain your steps and then answer:
If a train leaves at 3 PM and travels 2 hours, when will it arrive?”

Why it is useful:
Improves reasoning accuracy
Helps with math, logic, multi-step problems

Top comments (1)

Collapse
 
samarth_c53536f98b6123775 profile image
Developer

Very Helpful!