How to start building your own chatbot

Hello Community! :smiley:

I’ve completed three of DeepLearning.AI’s short courses and would like to build my own chatbot based on LLM as a study project. I’m product manager of a tech (but not ML) product, I have entry-level knowledge of Python, yet I’m ready to learn more in case if it’s needed.

I have several quite simple use cases im mind, which imply simple inputs (text or emodgi, and also links or pdf files without a need to understand the contents) and chatbot’s outputs in text. I wonder which platforms could be used to build an interface for such a bot? Telegram comes first to my mind, as I use it quite a lot as the most of my social circle. Yet maybe there are other platforms you’ve used?

Also, I’d be very grateful for any tips on how to build LLM-based chatbot (any videos, text instructions) from scratch. Sorry for the broadness of my inquiry, right now I have only the CJM for my use cases, so all the technical part is something really new for me and the courses’ material seemed missing those initial steps for newbies.

Thank you :pray:

Hi @nina.p,

I believe building your own chatbot is taught in one (or more) of our LLMs short courses. Kindly check those out.

Cheers,
Mubsi

Hi @Mubsi,

Thank you so much for your kind answer.

I’ve completed “Prompt Engineering for Developers”, “Building Systems with the ChatGPT API” and “LangChain for LLM Applications”, but I’m still struggling with the very first steps, lacking understanding of several technical moments.

What is to be done to have not just a code written in my Jupyter Notebook, but a deployed application? Any suggestions of certain courses where I could understand this transition are welcomed.

Best wishes,
Nina

Hi @nina.p,

I’m not much familiar with these topics, I’m afraid I can’t give you a good suggestion regarding the courses you can take.

However, if you are struggling with the technicalities, I’d suggest to first make sure you understand the foundations before diving into the advance topics.

Additionally, developing something and then deploying it (as an application) are two very different things and require for you to know the both. It is not like, you have the understanding and the skillset to develop something that deploying it would be easy. More often than not, this is not the case. Again, I’d suggest to start from these basic topics, or at least have an understanding of it, so that in case something isn’t working, you’d know or could figure out why. Then dive into the advance topics.

Best,
Mubsi

Hi @Mubsi,

Thank you very much for clarifying this :pray: Now I have something to start with.

Best wishes,
Nina

Hi, you can start by creating a bot on telegram, search for @botfather first. Create your bot and copy the key.
Then open a python file in vscode and start implementing. You can install dependencies like
“pip install pytelegrambotapi” , “pip install openai” and get started.

import telebot
import openai
import re
from os import getenv
import dotenv

Configuring credentials and API key

dotenv.load_dotenv()
API_KEY = getenv(‘API_KEY’)
OPENAI_API_KEY = getenv(‘API_OPENAI’)

Telegram bot initialization

bot = telebot.TeleBot(API_KEY)

OpenAI API initialization

openai.api_key = OPENAI_API_KEY

Storage of message state for each user

user_messages = {}
appointment_date = {}

OpenAI response function

def get_openai_response(messages):
response = openai.ChatCompletion.create(
model=“gpt-3.5-turbo”,
messages=messages
)
return response.choices[0].message[‘content’]

/start command handler

@bot.message_handler(commands=[‘start’])
def send_welcome(message):
chat_id = message.chat.id
user_first_name = message.from_user.first_name
bot.send_message(chat_id, f"Hello! {user_first_name}, how are you?
Welcome to office X")

Start the conversation with system messages

user_messages[chat_id] = [{‘role’: ‘system’, ‘content’: “”"
First, greet the user and inform them that you are doctor Marcus Júnior’s secretary, and that you are available to schedule your appointment.
You are Jana, a virtual assistant and secretary to Doctor Marcus Junior. You are here to help schedule doctor appointments.
You are not available to answer general questions, but only help schedule appointments at Doctor Marcus Junior’s medical office.
Ask for the client’s full name and reason for the consultation.
Ask the client for a preferred date and time to see if it is available on the doctor’s schedule.
Check the doctor’s availability and suggest three possible times if the requested time is not available.
After confirming the date and time of the appointment, ask if the appointment will be private or through a health plan.
After the customer provides plan details or confirms they will pay out of pocket,
assure the client that the appointment was successfully scheduled and provide a summary of the appointment details.
Consultation details must be sent to the patient at the end of the appointment.
Be polite, professional and attentive throughout the interaction.
Emphasize that you are available to help with any questions or rescheduling needs.
Expect new interactions, always ready to serve the customer in an efficient and friendly manner.
“”"}]
appointment_data[chat_id] = {}

Text message handler

@bot.message_handler(func=lambda message: True)
def handle_message(message):
chat_id = message.chat.id
user_message = message.text

Retrieve user’s message history

if chat_id not in user_messages:
    user_messages[chat_id] = []

user_messages[chat_id].append({‘role’: ‘user’, ‘content’: user_message})

Call the OpenAI API to get the response

assistant_message = get_openai_response(user_messages[chat_id])
user_messages[chat_id].append({‘role’: ‘assistant’, ‘content’: assistant_message})

bot.send_message(chat_id, assistant_message)

Start the bot

bot.polling()

Hi @nina.p,

Great to hear you’re diving into building your own LLM-based chatbot! Since you have some product management experience and basic Python knowledge, you’re already on a good path. Here are some tips to get started:

  1. Choosing a platform for your chatbot interface:
    Telegram is an excellent choice—it’s widely used, supports rich media, and has a well-documented Bot API that makes integration straightforward. Other popular platforms you might consider are Discord, Slack, or even simple web-based chat UIs using frameworks like Streamlit or React. The choice depends on where your target users are and how complex you want the interface to be.

  2. Building the chatbot backend:
    For an LLM-based chatbot, you can leverage APIs from providers like OpenAI, Cohere, or Hugging Face. These services handle the heavy lifting of natural language processing, so you don’t need to build the model from scratch. You can write Python scripts that send user inputs to these APIs and return generated responses.

  3. Handling inputs like text, emojis, links, and PDFs:

  • Text and emojis are typically handled naturally by LLMs.

  • For links and PDFs, since you don’t need the bot to understand their content deeply, you can preprocess or store them as references and design your chatbot to acknowledge or fetch simple metadata if needed.

  1. Learning resources:
    Start with beginner-friendly tutorials on building chatbots with Python and OpenAI’s GPT models. Many video tutorials and blog posts cover step-by-step how to connect APIs and create chat interfaces. DeepLearning.AI’s own courses on NLP and Transformers will also deepen your understanding as you progress.

  2. Next steps:

  • Experiment with simple Python scripts calling LLM APIs.

  • Build a minimal interface (Telegram bot or web app).

  • Gradually add features as you learn more.

Feel free to ask here anytime if you want help with code examples or advice on specific tools. Best of luck on your chatbot journey! :blush:

@williamsj043, just FYI, your reply to nina.p is on a topic that has been cold for 2 years and 9 months.

The easiest way to start isto use an existing LLM API and focus on how the conversation flows instead of training models yourself. You can vuild a simple backend (FastAPI is actually a good choice) and plug it into a UI like Telegram or a web chat widget.

If you’re aiming for something more production-ready, solutions like MirrorFly’s AI agent (a plug and play JS widget) can let you build completely custom chat or voice agnets straight into your app without much manual efforts.