How to Build an AI Friend: My First Experience

Tech Stack Used in the Project :
Next.js
Typescript
OpenAI Api key
GitHub Repo For Code :
Main Things Required to make this project:
1: Prompt Engineering and its types:
What is Prompt Engineering?
Prompt Engineering is the art and science of crafting effective inputs (prompts) for AI language models like GPT to produce desired outputs. Since these models are trained on massive text datasets, how you ask matters just as much as what you ask.
Prompt engineering is crucial when:
You want consistent answers from the model.
You’re trying to guide its reasoning or style.
You need to solve tasks like summarization, translation, or question answering.
Types:
- **Zero-Shot Prompting :**You give the model a task without any examples. Best for straightforward tasks like definitions, translations, or facts.
Translate the following English sentence to French: "I love learning."
- One-Shot Prompting : You give one example along with the task. Best for slightly complex tasks where format clarity matters.
Translate the following English sentences to French.
English: "Good morning." → French: "Bonjour."
English: "I love learning." → French:
- Few-Shot Prompting : You provide 2-5 example prompts to the system as a working example . It can be used in COT (chain of thought) implementation For eg : Deep think in Deepseek and chat GPT.
You are rude to everyone except Aarush . If the user is not Aarush you will
act rude and roast them . You kinda like Aarush . You will flirt with him.
Example :
User: Hi , I am Aarush . How r you my.
Assistant : Just waiting for you
- . Chain-of-Thought (CoT) Prompting: This is the type in which the ai provides detailed analysis for every query given by the user. The user can modify the system prompt as follows to get a desired detailed flow .
"""
You are an helpful AI assistant who is useful in resolving queries .
You work on START , PLAN , ACTION , OBSERVE mode .
For the given user input , analyse the input and break down the problem step by step.
Steps are you get a user input . You think , you analyse , you thing again , you think for several times before coming up with an output
Follow the steps in sequence ->
1) Analyze
2) Think
3) Output
4) Validate
5) Result
Rules:
1) Follow the strict JSON output as per schema
2) Always perform one step at a time before moving on to the next step
3) Carefully analyse the user query
Output Format :
{{ "step" : 'string' , "content" : "string"}}
Example :
Input : What is 2+2 ?
Output : {{"step" : Analyze , "content": Alright , the user is interesting in getting his maths query solved . He is asking a basic arithmetic problem}}
Output : {{"step" : Think , "content": To perform this addition i must go from left to right and add all the operands}}
Output : {{"step" : Output , "content": 4}}
Output : {{"step" : Validate , "content": seems like 4 is correct answer for 2+2 = 4 and that is calculated by adding all numbers }}
Output : {{"step" : Result , "content": give the final answer to the user as per your understanding }}
"""
Code Structure for AI Dost :

Route.ts File : File used for sending api request and getting the api response
import { NextResponse } from 'next/server'
import systemPrompt from '@/lib/systemPrompt'
export async function POST(req: Request) {
try {
// Step 1: Get the user's message from the request body
const body = await req.json()
const userMessage = body.userMessage
// Step 2: Send the message to OpenAI
const openaiRes = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.OPENAI_API_KEY!}`
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'system', content: systemPrompt }, // This is your custom AI behavior
{ role: 'user', content: userMessage } // This is the user's message
]
})
})
// Step 3: Read the response from OpenAI
const data = await openaiRes.json()
const reply = data.choices[0].message.content
// Step 4: Send the reply back to the frontend
return NextResponse.json({ reply })
} catch (error) {
console.error('Chat API error:', error)
return NextResponse.json({ error: 'Something went wrong' }, { status: 500 })
}
}
For building UI You can take the help of AI models . It is not very complicated and saves Time for making more projects .
Remember to keep enough tokens available for making AI related projects.