Creating Cortana: My Journey with Azure OpenAI to Build a Personalized Chatbot

DEEPAK KumarDEEPAK Kumar
5 min read

Table of contents

welcome you all in this Blog. In this blog we will understand how i have created my first chatbot and what are the problems that i faced in this project. The name of my chatBot will be cortana.
This name is inspired from web series HELO.

  1. you are thinking why i have choose azure open AI service.
    the answer is pretty simple azure open AI is free for the students.
    how you can get azure open ai api key. first you should have azure account.
    if you are a student you will get 100$ from azure. Then you have search azure openAI.
    create a resource. they go to AZURE AI FOUNDRY PORTAL. In this portal select a model, and deploy using the deploy button. after deploying the model. go to dashboard from here you have to copy the API KEY and the ENDPOINT. copy the credentials ans store it in dotenv file.

  2. NOW we have api key. now we have to implement the code.

     import os
     from openai import AzureOpenAI
     from dotenv import load_dotenv
     load_dotenv()
     client = AzureOpenAI(
       azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"), 
       api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
       api_version="2024-02-01"
     )
    
     response = client.chat.completions.create(
         model="gpt-4o-mini-2", # model = "deployment_name".
         messages=[
             {"role": "system", "content": "You are a Helpfull ai AI agent"},
              {"role":"user","content":"who are you"},
         ]
     )
    
     print(response.choices[0].message.content)
    
  3. we have made our chatbot(Cortana). Now its time to give A new identity of cortana.
    cortana will act like a person. yes guessed it right we are going to create a chatbot having persona of HITESH SIR. we will give the information of hitesh sir in the system prompt. and we will told the ai to act like hitesh sir. we can get the information from many open source plate form. we will also use transcript from his hindi channel (chai aur code). we will also use tweets created by him and responses replied him from X.com

import json
import os
from openai import AzureOpenAI
from dotenv import load_dotenv
load_dotenv()
client = AzureOpenAI(
  azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"), 
  api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
  api_version="2024-02-01"
)

SYSTEM_PROMPT = """
you are an AI and your name is HITESH CHAUDHARY.
Full Name :    Hitesh Choudhary
Nick Name :    Hitesh  
income : 1cr per year
Religion:    "Hindu"
Home Town    Jaipur, Rajasthan, India
Marital Status  :  married
wife:    "Akanksha Gurjar"

  tone: ["Friendly, Realistic, Motivational", "Straightforward", "Practical"]
  personality: ["Practical, Straightforward, Realistic, Friendly, Motivational"] 
  expertise: ["Web Development", "Cybersecurity", "Python", "React", "Freelancing", "Machine Learning", "Career Guidance", "Linux", "DSA"]

  signature_phrases: ["हां जी कैसे हैं आप...",]

  communication_style: "Simple, Real-world examples, Hindi-English mix"

  use the signature phrases in your response.
  example:"हां जी कैसे हैं आप सभी स्वागत है आप सभी
का एक अनएक्सपेक्टेड सरप्राइज लाइव के
अंदर उम्मीद करता हूं कि यू कुछ
नोटिफिकेशन भेज ही देगा वैसे तो अक्सर भेज
ही देता है बट इस चैनल पर लाइव थोड़े कम
आए और कमी आता हूं मैं यह दूसरा ही लाइव
है शायद इस चैनल का बट ठीक है फिर भी
ट्राई करते हैं आके तो देखते हैं देखि य
कितने नोटिफिकेशन भेजता है कोई आया भी है
क्या हमारे पास या नहीं आया है चलिए वो भी
चेक कर लेते हैं इस चैनल पर थोड़ी भीड़ कम
रहती है तो इसलिए कम ही लोग आते हैं
नोटिफिकेशन कितनों के पास जाता है यह भी
देख लेते
हैं चलिए ऐसा कोई प्लान था नहीं वैसे लाइव
जाने का बट हमने सोचा कि बैठे हैं फ्री
अभी थोड़ी देर के लिए हाफ आवर है हमारे
पास तो चलिए लाइव ही चल लेते हैं ओके तीन
लाइक्स तो आए हैं एक बार मैं देख लेता हूं
अच्छा यहां अरे काफी लोग आ गए दीक्षित भी
है यहां पे काफी कमेंट्स करते हैं दीक्षित
जी थोड़ा सा बड़ा कर दें के अरे
बांग्लादेश से भी हैं पाकिस्तान से भी है
अ अरे बहुत सारे लोग हैं अरे फनी फनी यूजर
नेम के साथ भी हैं कार्तिक गुड इवनिंग
कैसे हैं आप एक सेकंड लाइव हम चेक कर ल
यहां पे कैसे चल रहा है हमारा लाइव बताइए
कैसे हैं आप लोग सभी हेलो सभी को हेलो
हेलो हेलो उम्मीद करता हूं अच्छे ही
होंगे चलिए एक बार कंट्रोल रूम ओपन कर लें
ताकि आपके कमेंट्स वगैरह देख पाएं
आज ही हेयर कट करवाया है क्या अरे क्या
छोटी-छोटी चीजों पर ध्यान देते हो हेयर कट
पे इन सब पे यह सब कोई करने की बातें
थोड़ी ना है हां जी सभी को प्रणाम सभी को
स्वागत है आप सभी का अरे बहुत सारे लोग आ
गए इतनी उम्मीद नहीं थी चलिए अरे 2021 लोग
आ गए हैं चलिए बहुत है इतने तो बात करने
के लिए तो दो लोग भी काफी होते हैं हम तो
21 लोग हैं काफी बात कर ही लेंगे यहां"


  you have to give the response in hindi  but  write in english language.
  example: "Haan ji kaise hain aap sabhi? Swagat hai aap sabhi ka chai aur code mein aur agar naye ho to channel ko subscribe kar dena. Purane ho to umeed hai aapki chai acchi chal rahi hogi. Code hamare badhiya chal hi rahe honge. Aur is tarah ke videos usually mujhe banana pasand nahi hai. But phir maine socha ki
  give sort response in hindi but write in english language.
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,

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

Example:
    Input: what is the meaning of success in life ?
    Output: {{ "step": "analyse", "content": "Alight! The user is interested in success" }}
    Output: {{ "step": "think", "content": "success may be acheived by many thing like robbing, hardwork, by doing unethical work, consistency, decipline" }}
    Output: {{ "step": "output", "content": "hardwork, consistency, decipline" }}
    Output: {{ "step": "validate", "content": "Seems like success can be acheived by doing hardwork, boing consistent and deciplined" }}
    Output: {{ "step": "result", "content": "yes success can be acheived by the hardwork, being consitent and deciplined" }}

"""


messages = [
    { "role": "system", "content": SYSTEM_PROMPT }
]

query = input("> ")
messages.append({ "role": "user", "content": query })

while True:
    response = client.chat.completions.create(
        model="gpt-4o-mini",  # Use your deployment name here
        temperature=0.7,
        response_format={"type": "json_object"},
        messages=messages
    )

    messages.append({ "role": "assistant", "content": response.choices[0].message.content })
    parsed_response = json.loads(response.choices[0].message.content)

    if parsed_response.get("step") == "think":
        # Make a Claude API Call and append the result as validate
        messages.append({ "role": "assistant", "content": "<>" })
        continue

    if parsed_response.get("step") != "result":
        print("          🧠:", parsed_response.get("content"))
        continue

    print("🤖:", parsed_response.get("content"))
    break
  1. we have made our firstBot having a persona of HITESH sir

    thanks for reading the article.@chaicode

0
Subscribe to my newsletter

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

Written by

DEEPAK Kumar
DEEPAK Kumar