Finally Replicated My Guru Hitesh Sir: (Persona Chat Bot- Gemini)

Introduction

In this article, I will be discussing on how to make your own style Persona AI Chat Bot based on my learnings from Gen AI Cohort 2.0. In which you will see the magic of efficient prompting through which the accuracy of model increases aligns to that person. In this will be using Gemini-2.0-flash model and based a prompting Technique know as Few shot prompting, I am gonna align it to my way.

Prompting and Importance

Prompting is a way of writing in easy simple, to the point instructions which the base model can understand and follow most accurately, ensuring better understanding and better results.

For example, you asked it

Eg-1: “How many r's there in strawberry“ its says 2 ❌

Eg-2: “How many r's there in strawberry? count each 'r' letter by letter in the given word”

Let's count the 'r's in "strawberry":

  1. strawberry - one 'r'

  2. strawberry - two 'r's

  3. strawberry - three 'r's

So, there are a total of three 'r's in the word "strawberry". ✅

So, yes prompt do matters Raw LLM’s can‘t directly understand the inner essence. But one may ask i asked the same question in ChatGPT and other models but it gave right answers because you might asked the commercial models which already have inner promptings to modify yours and make a good one, but when tried on a RAW ones you will see difference.

Few-Shot Prompting

In this scenario of building an Persona, I heavily used Few-Shot prompting. Now actually what is this ? you might be thinking right ? So it’s a way to align the raw llm based on your detailed examples given. For example if you tell how to count letters clearly with other words, then most probable you will get right answer.

For example

  • Hello → Bonjour

  • Thank you → Merci

  • Good night → Bonne nuit

  • How are you? → ?

The model then recognizes the pattern and finds you want to translate to French then does accordingly.

How to use Gemini

So here is the base template to get started

import os
import google.generativeai as genai
from dotenv import load_dotenv

load_dotenv()

api_key = os.getenv('API_KEY')
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-2.0-flash')

response = model.start_chat().send_message("How are you?")
print(response.text)

But if you what it to behave in certain defined manner like a strict teacher who doesn’t deviate much from topic then you can add something called as system_instruction.

    import google.generativeai as genai
    from dotenv import load_dotenv
    import json

    load_dotenv()
    api_key = os.getenv('API_KEY')

    genai.configure(api_key=api_key)
    model = genai.GenerativeModel('gemini-2.0-flash')


    system_instruction = '''
        ...
    '''
    messages = [
            { "role": "user", "parts": [system_instruction] },
    ]

    chat = model.start_chat(history=messages)

    response = chat.send_message('How to perform this operation 4*5/3+2')

This is the structure to get started using Gemini.

Explanation:

Note: Here for system_instruction you use user and any outputs of ai use model, instead of system, user and assistant (if you use OpenAI) is same, and we use parts instead of content (if you use OpenAI)

  • Go the Google Studio Labs and generate an API-key for free.

  • pip install google-generativeai (to integrate with gemini).

  • You directly use the API or for best practices use dotenv and configure the genai.

  • Select you model through: genai.GenerativeModel(‘gemini-2.0-flash‘).

  • For system_instructions write the necessary instructions to be followed before it reacts to your query like “You are a strict AI and encourage students to ask related to Math, else Roast them.“ 😅(Sorry)

  • messages is a part where we store the previous chat history as to retain your previous invoices but it doesn’t mean they run again, they are cached and used to follow up you. so better add you response and model after completion.

  • model.start_chat() starts coversation if according to any history or a fresh start.

  • To ask and get response of your query use chat.send_message().

Persona the Awaited Part

if you are clearly understanding the above ones, then you are one the right track in make a progress.

Understanding how I prompted Hitesh (Sir)

system_instruction = ''' 
Who are you:
    Immerse yourself as Hitesh Choudhary a teacher by profession. You teach coding to various level of students, right from beginners to folks who are already writing great softwares. You have been teaching on for more than 10 years now and it is your passion to teach people coding. It's a great feeling when you teach someone and they get a job or build something on their own.
    In past, You have worked with many companies and on various roles such as Cyber Security related roles, iOS developer, Tech consultant, Backend Developer, Content Creator, CTO and these days, You are at full time Founder and teacher at Chai Aur Code. You have done my fair share of startup too, your last Startup was LearnCodeOnline where we served 350,000+ user with various courses.

More about yourself:
    Hitesh Choudhary has established himself as a significant figure in online programming education through his comprehensive approach to content creation, community building, and platform development. His Chai aur Code initiative demonstrates the effectiveness of combining accessible teaching methodologies with practical, project-based learning experiences. The platform's growth from a single YouTube channel to a multi-platform educational ecosystem reflects both market demand and Choudhary's strategic vision for democratizing programming education.

    Follow the steps in sequence that is "analyse", "think", "output", "validate" and finally "result".

    Rules:
    1. Follow the strict JSON output as per schema 
    2. Always perform one step at a time and wait for the next input.
    3. Carefully analyse the user query and give full answer at last.

    Output Format:
    {{ "step": "string", "content": "string" }}


Examples:

1.Student: Hello Sir, How are you ?
Hitesh: Haanji kasa ho aap sab. Kasa ha chal raha ha aap ki coding journey ? 

2.Student: Sir, main coding seekhna chahta hoon lekin samajh nahi aa raha ki kaunsi language se shuru karun. Sab log alag-alag suggest karte hain, aap kya bolenge?
Hitesh: Dekho beta, yeh confusion sabko hota hai. C, Python, JavaScript – har kisi ki apni journey hai. Main maanta hoon ki sabse pehle ek interface banana seekho, jaise HTML/CSS. Jab tumhe apni khud ki website screen pe dikhne lagegi, tab coding ka maza aayega. Baaki languages baad mein aati hain, pehle basics pakdo!

3.Student: Sir, mujhe lagta hai main coding mein slow hoon, dusre log mujhse aage nikal rahe hain.
Hitesh: Arre, comparison se kuch nahi hota! Coding ek marathon hai, sprint nahi. Tum apni speed pe focus karo. Main bhi jab shuru kiya tha, mujhe bhi lagta tha sab mujhse tez hain. Lekin dheere-dheere jab projects banne lage, confidence aaya. Tum bhi banaoge, bas consistency chahiye.

4.Student: Sir, DSA karun ya development? Dono mein confuse ho gaya hoon.
Hitesh: Bahut badiya sawal hai! DSA aur development dono ka balance zaroori hai, jaise chai mein patti aur doodh ka balance. College placements ke liye DSA zaroori hai, lekin industry mein development skills bhi chahiye. Dono karo, lekin ek waqt pe ek pe focus karo. Balance hi life hai!
...

This is just short example (Please share your view points and improvements ✍️)
So how I get started, First of all you need most of the details of the person like what kind of

  • Background he has for that i investigated his personal website and grab some knowledge.

  • Seen many youtube videos but not in understanding lectures (for now 😅) but understanding how does he start conversations, interact in different scenarios and i say this is the where i seen most of it like i picked up some videos related to non-academic or motivational, self talk ones so i get more insights on the person’s personality rather than his abilities.

  • To speed-up the process you can even go linkedIn, twitter, instagram and see how they usually comment react to different posts. For youtueb I highly recommend to use the transcripts and seggregate the tone and language dialouges accordingly.

  • Next for more accurate answers you can force the model by giving it examples so that model easily grasps. So either a self taught ones or if possible see some comments and add those.

  • If you carefully see, I also asked model to follow some set Rules/Guidelines while providing me answers. like here in json format so that after thinking the finalized result is shown.

  • I would suggest to add more and more examples so the model gets nearer to real tone.

Then after is simple python code where i made a loop which so as the model validating according to my rules i parse it through json and see if it is still in thinking mode or result and then put result at last.

Template

import os
import json
import google.generativeai as genai
from dotenv import load_dotenv


load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')

genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-2.0-flash')

system_instruction = ''' 
Who are you:
    Immerse yourself as Hitesh Choudhary a teacher by profession. You teach coding to various level of students, right from beginners to folks who are already writing great softwares. You have been teaching on for more than 10 years now and it is your passion to teach people coding. It's a great feeling when you teach someone and they get a job or build something on their own.
    In past, You have worked with many companies and on various roles such as Cyber Security related roles, iOS developer, Tech consultant, Backend Developer, Content Creator, CTO and these days, You are at full time Founder and teacher at Chai Aur Code. You have done my fair share of startup too, your last Startup was LearnCodeOnline where we served 350,000+ user with various courses.

More about yourself:
    Hitesh Choudhary has established himself as a significant figure in online programming education through his comprehensive approach to content creation, community building, and platform development. His Chai aur Code initiative demonstrates the effectiveness of combining accessible teaching methodologies with practical, project-based learning experiences. The platform's growth from a single YouTube channel to a multi-platform educational ecosystem reflects both market demand and Choudhary's strategic vision for democratizing programming education.

    Follow the steps in sequence that is "analyse", "think", "output", "validate" and finally "result".

    Rules:
    1. Follow the strict JSON output as per schema 
    2. Always perform one step at a time and wait for the next input.
    3. Carefully analyse the user query and give full answer at last.

    Output Format:
    {{ "step": "string", "content": "string" }}


Examples:

1.Hello Sir, How are you ?
Ans: Haanji kasa ho aap sab. ...

'''

messages = [
    {'role': 'user', 'parts': [system_instruction]},
]

chat = model.start_chat(history=messages)


def get_gemini_response(prompt):
    thinking = []

    query = prompt
    messages.append({'role': 'user', 'parts': query})

    while True:

        response = chat.send_message(query)
        raw_text = response.text.strip()

        if raw_text.startswith('```json') and raw_text.endswith('```'):
            json_str = raw_text[len('```json'): -3].strip()
        else:
            json_str = raw_text

        try:
            parsed_json = json.loads(json_str)
            messages.append({'role': 'model', 'parts': parsed_json['content']})

            if parsed_json.get('step') != 'result':
                thinking.append(f"🧠 {parsed_json.get("content")}")
                # print(f"🧠 {parsed_json.get("content")}")
                continue

            result = parsed_json.get("content")
            return thinking, result
            # break

        except json.JSONDecoderError as e:
            print('Failed to pars JSON:', e)
            return 'Failed to parse JSON'

As in gemini i was not getting a direct json format so I formatted the response before parsing then i seggregated to see under which stage and appending to messages under user/model under parts (where content is given) this is important part because Raw llms don’t build a history of chats and respond to you as the pre-prompted ChatGPT, Grok or other AI models. (First time i too made mistakes. 😂)

You might wonder why i am using it under a function? it is because as i integrated with streamlit, I am simply sending the response back to it as a function output, else for basic terminal running you can remove those def.

How I Structed my code

Project Structure

    project-root/
    ├── app.py                # Streamlit app code
    ├── requirements.txt      # Python dependencies
    ├── .env                  # Your Gemini API 
    ├── images/               # Image assets
    └── backend/
        └── chat_handler.py

Where the main heart is chat_handler.py where the function exports the results and the main frontend part is simply a streamlit ui interface in app.py with other important things like requirements.txt, .env, .venv.

Requirements

# Core
streamlit==1.45.1
python-dotenv==1.1.0
requests==2.32.3

# Google Generative AI
google-generativeai==0.8.5
google-api-core==2.24.2
google-auth==2.40.2
google-auth-httplib2==0.2.0
googleapis-common-protos==1.70.0
protobuf==5.29.5
grpcio==1.71.0
grpcio-status==1.71.0
httpx==0.28.1

# Data and performance
pandas==2.2.3
numpy==1.26.4
altair==5.5.0

For more info about my project : GitHub

If you want to Play with it (Still has some minor issues): https://mtwu7vafl4s6jv4tn7bxyb.streamlit.app/

Please Share Your Views and tell me what Improvements i need more

14
Subscribe to my newsletter

Read articles from Sapparapu Abhijeet directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sapparapu Abhijeet
Sapparapu Abhijeet

I am Abhijeet from Hyderabad an enthusiastic Techy, with progress in Web Development with Tech stacks ->ReactJs, Django and a bit of ExpressJs. Also a problems solver in Java and current updation with rapid growing AI world learning Generative AI