TubeSum

Build a Gen AI Chatbot with Python — Step-by-Step Guide & Transcript

Gen AI Application Development Tutorial 2026 | Gen AI App Development For Beginners

0h 25m video Published Aug 7, 2026 Transcribed Aug 9, 2026 S Simplilearn
Beginner 12 min read For: Absolute beginners with no prior experience in generative AI or Python who want to build their first chatbot.
AI Trust Score 75/100
⚠️ Average / Some Fluff

"Delivers exactly what the title promises — a beginner-friendly tutorial for building a Gen AI app with Python."

AI Summary

This tutorial provides a step-by-step guide for beginners to build a generative AI chatbot using Python and Google's Gemini model. It covers the fundamental concepts of generative AI applications, setting up the development environment, and implementing both manual and built-in conversation history features.

[03:42]
What is a Generative AI Application?

A generative AI application uses an AI model to create new content such as text, images, audio, or code. Examples include AI writing assistants, coding assistants, and customer support chatbots.

[04:09]
Basic Workflow of Gen AI Apps

The basic workflow involves: user provides a prompt, the app sends it to an AI model, the model processes it and generates output, and the app displays the output to the user.

[04:39]
Required Tools and Setup

The project requires Python and Visual Studio Code. Python installation can be verified by running 'python --version' in the command prompt.

[08:09]
Installing Google Gen AI Library

The Google Gen AI library is installed using 'pip install google-genai'. The code imports the library and creates a client using a Gemini API key.

[10:17]
Building the Basic Chatbot

A basic chatbot is created using a while loop that takes user input, sends it to the Gemini model via 'client.models.generate_content()', and prints the response. The model and system instructions are configured in the request.

[16:40]
Implementing Manual Conversation History

The initial chatbot lacks conversation history, treating each query independently. To fix this, a list is created to store the chat history, and the entire list is passed as the 'contents' parameter to the model.

[20:01]
Using Built-in Chat Session for History

The Gemini SDK provides a built-in chat session feature using 'client.chats.create()' and 'chat.send_message()', which automatically handles conversation history without manual list management.

Mentioned in this Video

Tutorial Checklist

1 04:39 Install Python and Visual Studio Code on your system.
2 05:38 Verify Python installation by running 'python --version' in the command prompt.
3 07:01 Create a project folder named 'GenAI' and open it in VS Code.
4 07:42 Create a new Python file named 'chat_demo.py'.
5 08:09 Install the Google Gen AI library by running 'pip install google-genai' in the terminal.
6 08:36 Import the library: 'from google import genai'.
7 08:52 Create a client with your Gemini API key: 'client = genai.Client(api_key="YOUR_API_KEY")'.
8 09:21 Print a start message and take user input using 'input()'.
9 10:17 Create a while loop that continues until the user types 'end chat'.
10 10:34 Inside the loop, call 'client.models.generate_content()' with the model name, user input, and configuration.
11 12:53 Print the model's response using 'system_output.text'.
12 16:40 To add conversation history, create an empty list and append each user input and system output to it.
13 17:35 Pass the entire list as the 'contents' parameter instead of just the latest user input.
14 20:01 Alternatively, use the built-in chat session: 'chat = client.chats.create(model=...)' and 'response = chat.send_message(user_input)'.

Study Flashcards (7)

What is a generative AI application?

easy Click to reveal answer

A software application that uses an AI model to create new content like text, images, audio, or code.

03:42

What is the basic workflow of a generative AI application?

easy Click to reveal answer

The user provides an input (prompt), the app sends it to an AI model, the model processes it and generates output, and the app displays the output.

04:09

What two main tools are required for this project?

easy Click to reveal answer

Python and Visual Studio Code.

04:39

What command is used to install the Google Gen AI Python library?

medium Click to reveal answer

pip install google-genai

08:09

What type of API key is needed to use the Gemini 2.5 Flash model?

medium Click to reveal answer

A Gemini API key.

14:07

How is conversation history manually implemented in the tutorial?

hard Click to reveal answer

By creating an empty list and appending each user input and system output to it, then passing the entire list as the 'contents' parameter.

16:40

What is the simpler, built-in method for conversation history provided by the Gemini SDK?

hard Click to reveal answer

Using the built-in chat session feature: `chat = client.chats.create(model=...)` and `response = chat.send_message(user_input)`.

20:01

💡 Key Takeaways

🔧

Manual Conversation History via List

Shows a fundamental programming pattern for maintaining state across interactions.

16:40
🔧

Built-in Chat Session for History

Demonstrates a more efficient, SDK-provided method for the same functionality.

20:01
💡

Iterative Learning Approach

Encourages building small projects and gradually adding features, a core principle of effective learning.

24:00

[00:08] write emails, summarize documents, answer questions, generate code, or create new ideas. But, have you ever wondered how developers build these applications? The good news is that you do not need to train a large artificial

[00:22] intelligence model from scratch. With Python and an AI model and a simple application framework, you can create your own generative AI application in just few steps. In this tutorial, we will build a complete generative AI

[00:37] chatbot using Python. The chatbot will accept questions from a user, send those questions to an AI model, receive an intelligent response, and display the response on the screen. Plus, we will also see the chat conversation history

[00:52] feature. We will use Python for the application logic and an AI model for generating responses. Even if you are new to generative AI development, do not worry. We will build the application one step at a time and understand why every

[01:07] part of the code is required. So, by the end of this video, you will have a complete working generative AI application with you. So, now let's look at the agenda of our today's video. So, first we will understand what a

[01:20] generative AI application is. Second, we will understand the architecture of our application. Then, we will install the required dependencies like Python and Node.js in our system. Next, we will install Python libraries and create the

[01:35] project structure. Then, we will connect our Python application to the AI model, and we will also add conversation history, error handling, and clear chat option. Finally, we will run the application, test it with different

[01:49] prompts. So, stay till the very end because this session is going to be very interesting, trust me. Also, just a quick information, if you are interested in building job-ready skills in artificial intelligence and machine

[02:02] learning, then explore the professional certificate course in generative AI and machine learning by IIT Kanpur and Simplilearn. This 11-month live online program takes you from Python and data science fundamentals to machine

[02:15] learning, deep learning, generative AI, and agentic AI. Learn through interactive sessions led by experienced industry professionals, attend exclusive academic masterclasses delivered by IIT Kanpur faculty. Gain hands-on experience

[02:29] with 30-plus tools including Python, TensorFlow, PyTorch, LangGraph, OpenAI, and GitHub Copilot. Work on 18-plus industry projects including three capstone projects across technology, finance, healthcare, and other domains.

[02:45] Strengthen your professional profile with program certificates and membership in the EICTA alumni network. You will also receive job support for resume interview preparation, and job opportunities. So, why wait? Check the

[03:02] program link given in the description box below and start your AI/ML journey today with Simplilearn. So, before we begin, let us start with a quick quiz question. And the question is, which component generates the intelligent

[03:14] response in a generative AI application? And your options are, option A, the keyboard, option B, the web browser, option C, the large language model, or the option D, the folder containing the Python file. Take your time to think

[03:28] about it, and instead of guessing, let us know your answers in the comment section below. So, let us begin with the basics and first try to understand what is generative AI application. So, what is generative AI? So, let's understand

[03:42] what is generative AI application. A generative application is a software application that uses an artificial intelligence model to create new content. This content can include text, images, audio, video, code, summaries,

[03:56] recommendation, or structured data. For example, an AI writing assistant generates written content. An AI coding assistant generate or explains programming code. A document assistant read documents and answers questions

[04:09] about them. A customer support chatbot responds to customer queries. And a study assistant can explain difficult topic, even create quizzes and summarize lessons. Although these applications perform different tasks, the basic

[04:24] workflow is usually similar. The user provides an input called as prompt. The application sends that prompt to an AI model. The model processes the prompt and generates the output. The application then displays the output to

[04:39] the user. So, this was the basic workflow. Now, let's look at the tools required for our project. So, first of all, we need Python, where we will write all our codes. And then we need an IDE. So, in this project, we will use Visual

[04:54] Studio Code as our IDE. So, make sure Python and Visual Studio Code are both installed in your device successfully. If not, then you can go to the official websites of Python and Visual Studio Code to get it downloaded. So, here type

[05:10] Python, and here's the official website of Python. From here, you can download the latest version of Python. And similarly in the case of Visual Studio Code, if it is not installed, then go to its official website, and from here, you

[05:25] can download uh the Visual Studio Code as the steps given on the screen. So, you can download it for Windows as well as for Mac, depending upon your system. So, once the Python is successfully installed, you

[05:38] can even check its installation, whether it was installed or not. For that, you need to go to command prompt, and here you can type as you can type as Python hyphen hyphen version. So, the

[05:51] screen. It means it is successfully installed in my device. Similarly, if you will follow all the steps given on the screen, then you will also be able to download Python very easily in your device. And this is how you can check

[06:05] its installation whether it was installed or not. So, both the dependencies, which is Visual Studio Code and Python, is installed in our device, so we can go ahead with our project. So, here we will be going to

[06:17] develop a chatbot using Gemini and Python. Bot that would be responsive, our own chatbot. So, in this video, we are going to cover the concept of chat conversation history, and we are going to create a simple chatbot using Gemini

[06:33] and Python. We are going to have a user who will be us, most probably, and who will send a message, then the system or the bot will going to respond. Then again, we can send the message as a user, and then again the system or the

[06:48] bot is going to respond. So, this will go on a loop. So, for this, we need to go to our Visual Studio Code because this is where we will write all our codes. And first of all, we will create the project.

[07:01] Go to your folders. Here in C drive, I usually create my folders in C drive, so here in C drive, create a folder and type it as GenAI. Press enter. Then we can open this folder in our Visual Studio Code. So,

[07:17] here go to open file. Here click on open folder, open file. Here click on open folder, and here in C drive, you can see we have and here in C drive, you can see we have created the project name as GenAI.

[07:29] We can select this folder, and we can open this. So, yeah. Yes, I do trust the authors. And now we can begin typing our code. Now we will create a file inside GenAI folder, which is chat_demo.py.

[07:42] Where we will be writing all our code to execute a chatbot. chat demo.py because it is a Python file. extension for Python file. Here we will be writing all our codes. So let's go to the

[07:56] terminal. From here you can go to the terminal. Now first of all, let's install gen AI from Google. And for this the command is as follows. PIP install Google hyphen gen AI

[08:09] and press enter. So you have installed the Python packages into your global environment. So it was already installed that is why it is saying that upgrade the version but I'm okay with this.

[08:22] With this command you'll be able to download and install the gen AI from Google in your system. So this was our first step. Then we will start writing our code. So first of all, we are going to import gen AI from Google. And for

[08:36] this we will write the following command on our Visual Studio Code. From Google import gen AI and press enter. Now we are going to create a gen AI client and let me show you how we can create that.

[08:52] The command for the same is client is equals to gen AI equals to gen AI dot client. And here you need to paste your open AI key. So here login to your open AI account and from here you can

[09:07] Create a secret key. Here you need to copy this key. And here you need to So now we will going to give a message that will pop up on the screen which will say that chat start here and

[09:21] you can type end chat to close your chat. So we will give the command for the same. So we'll write print chat start here to make it more interactive. The main purpose of giving the

[09:33] particular and the line to line command is is to make it more understandable, more clear, and more indirect. So, chat start here, type end chat to close. So, this will print a simple message like this on the screen. The exact message

[09:47] quotes. Now, the next step is to take the user input. So, for this, we'll type this following command. User input is equals to input user. So, this particular

[10:02] user and store it in the variable called user input. Now, we will write a while loop, which will say the condition like this. While the user input is not is equals to end chat, please continue chatting. So, for this, we'll give this

[10:17] command. So, while user input is not is equals to end chat, then we will continue chatting. Now, we are making the request, and for that, we have written system output is equals to client.models.generate_content.

[10:34] generate the content for us, and it will be stored in the variable called system output. It means whatever the output will be generated by the system will be stored in system output. And the input from the user is being stored in user

[10:47] input. For this, inside this, we'll give content is equals to user in then we will specify the model. So, we have written model is equals to Gemini 2.5 flashlight model. You can use any of the models, but for

[11:01] my reference, I am using this. I have chosen this particular model. Then, the next step is to give the configuration. And for configuration, we need to import the types library. So, here, we have written config is equals to dict content

[11:15] config, and then we need to import the types. And for that, we will go here. And here, we will write from import types. And inside the configuration, now we will give the system instruction, which

[11:29] would be as follows. System instruction is equals to answer should be in one line within 50 characters. This is for the reference of our chatbot. So, till now what we have done? We have just imported genai from

[11:43] Google and then we have created a client which will use our genai API key. Then we have printed the simple message which states that uh the chat will start here and you have to type end chat to close. Then we have taken the user input which

[11:57] is stored in the variable called as user input. Then we have started a while loop that will work until the input is in end chat. Then we have used dot generate content the information and the contents and the inputs and the outputs of the

[12:12] following code. So, here we have given contents as user input then model then specified configuration and then inside configuration we have given the system instruction that the chatbot has to follow. I think till now everything is

[12:26] clear. I've been explaining the whole line of code so everything is being clear to you. Till now I think everything is clear. So, let's save whatever we have coded till now.

[12:38] And it is a good habit to save your code regularly even though auto save is on. Now, whatever the system will generate we have to print that message. So, for this we will be printing the message and for this the

[12:53] command would be as follows. Print Now, let's give the name to our chatbot, let's give the name to our chatbot, right? So, I'm giving as as simply good gesture, I guess. And here we will write system output.text. So, this simply bot

[13:06] will generate and respond as system output. dot text. Whatever system will generate, it will give it in the response and will be printed on the screen. And here user input is equals to input user.

[13:21] It will continue chatting like it will continue taking input from the user until the input is end chat. Now, it is a very simple chatbot which has just taken the input and will, let's see, this much. So, now here we have done a

[13:35] small mistake. I have missed writing API key here. So, just give API key is equals to your API key. That is why we were not able to generate the output. So, this is how we can solve this error. Now, here save. And now here

[13:51] we can again run. So, here our chat is being started. Chat starts here. Type end chat to close. So, I'm writing Hi. So, here you make sure that you make and create the API key of Google, Google Gemini API key. Because here we are

[14:07] Gemini API key. Because here we are using the model Gemini 2.5 light model. So, it will not take any other API key, but the Gemini API key. Now, once we have corrected our code, we

[14:20] will run this file. And let's see if it works. So, now we have encountered another error. So, basically coding is all about writing code and then solving

[14:32] the errors. And it is not about writing the perfect code at once. So, let's see what is the next error. So, it is saying that the particular model of Gemini is not supported. And you need to use the newer or the latest version.

[14:47] newer or the latest version. Okay. So, instead of Gemini 2.5, let's use another model, the latest one. So, you can use Gemini 3.1 flash light model. Now, let's try to run this lesson. Our output is on the screen. We

[15:01] have just wrote Hi. And our simply bot replied, "Hello, how can I help you today?" So, let's start with this. Who are you? So, it replied, "I am a large language model trained by Google."

[15:15] large language model trained by Google." Awesome. Now, we can ask like, "Okay." And I am simply Oh, nice to meet you Simply Bot. Good. Now, I'm going to show you the flaw in our code. You must be thinking that it is working fine. We are

[15:30] asking question. It is replying back. Perfect. But, no. Let me show you the flaw. I have shared my information with this chatbot that my name is Simply Bot. Okay, so I had given

[15:43] my name as Simply Bot. In fact, our chatbot was also a Simply Bot. So, it's chatbot was also a Simply Bot. So, it's okay. We can give this as my name is anything. I just need to show you the flaw in our system.

[15:56] So, it will say, "Nice to meet you, Stuti." Working fine. Now, if I will ask you Now, if I will ask it, "What is my you Now, if I will ask it, "What is my name?" So, let's see what does it reply.

[16:10] And here, we have seen what is the mistake with our chatbot that it is not storing any conversation history. And every query is being treated as an independent query, and it doesn't remember anything we have previously

[16:24] contacted or previously shared. And it is not a good chatbot, right? Because it has replied, "I do not know your name." So, we need to fix this, right? So, there are many ways to implement chat conversation history, but we are going

[16:40] to run a very simple one. So, let's end the particular chat and clear our console. So, here we will be creating a list of the chat that is empty for now. list of the chat that is empty for now. So, here we will write chat list is

[16:53] equals to that is empty. Now, we are going to append the user input in this particular chat. And let's see how we can do that. So, while user input is not is equals to end chat, and here we will append our chat. Chat.append

[17:09] user input. Whatever chat is being made, we are appending the chat. So, that the entire history is visible to us. And now, we can print the output after the end of the while loop. And here we

[17:21] will also append the output. Here we have written chat.append system output.text. Now here we don't have to send the user input as the content. Here you can see we have replaced the user input as a

[17:35] chat because our input will be stored in the chat variable, right? So here at the place of user input, we can pass chat because the content is being now stored in this list as a complete chat history.

[17:49] Now the system is going to remember our entire conversation. And if we will ask any question related to our previous conversation, it will be now able to give it. Now let's make this entire system and entire coding a little

[18:04] robust. Like a little understandable, readable, like to make it more explanatory and it is a perfect way of writing a code it is a perfect way of writing a code that any beginner level student or a

[18:16] understand the code. So here we will say user plus user input. Which means this input is being by the user. And similarly in the place of output. So it shows that

[18:30] the input is coming from the user. And here the output is coming from Simply Bot. So this is nothing just making it more readable, understandable, and robust. And now I will show you how it is storing our conversation history. So

[18:46] is storing our conversation history. So let's save this code. Then again run this. Python chat demo.py. Here type as hi. Hello, how can I help you today? Hi Simply Bot. Who are you?

[19:00] Basically. Let's talk a little bit now. I am an AI assistant here to help you. I am an AI assistant here to help you. Good. Hi. Or we can say good to hear that. My name is Stuti. Nice to meet you, Stuti. How can

[19:13] Stuti. Nice to meet you, Stuti. How can I help you? Just I'm going to show you how it remembers the history. What is my name, simply bought? Your name is Stuti. So, you can clearly see the difference. Now, we can say this is a good chatbot.

[19:29] So, let's end chat and clear our console. Now, you got the idea what our chatbot is doing and we have implemented the feature called chat conversation history. Now, here you can see that we have provided our own logic to generate

[19:46] the history of the conversation. Like, we have created the list, then we pass the that particular list in the general content. So, we have provided our own logic. But, here we do have the inbuilt functionality provided by Google Gemini

[20:01] with the provided SDK by Google. So, let us copy this particular code into an another file as chat_main.py. Let's rename this chat_main.py.

[20:19] this entire code where we have applied the logic to generate the chat conversation history. We will remove this and we will keep this much of the code. We will even remove this because we need to remove this list. This much

[20:32] we need to remove this list. This much we need. Now, we will create a session. Let me show you how we can create. So, this is a particular command to create the chat session and this particular session will work internally just as

[20:45] generate content. Here, you can see we have written the entire logic for generate content, right? So, this particular session will work similarly and this is the inbuilt feature or functionality given by Gemini SDK. Now,

[21:01] here we need to pass the model. Once the session has been created, we have passed session has been created, we have passed the model Gemini 3.1 flashlight. And this complete session will be stored in a variable called and now we will get

[21:13] the response as response is equals to chat.send_message user input. It means this particular input will be stored in the variable Chat.send_message which is a pre-built function and the

[21:29] variable user input is being passed here. And whatever our simply bought will reply will be printed as response.text. See whatever user input will be given, so accordingly the according to the user

[21:43] input the response of the system will be stored in the variable called response and then the particular response will be converted into text format which will be printed on our screen using print command. So this was the meaning of this

[21:59] whole two line. No logic, nothing just the inbuilt function provided by SDK. the inbuilt function provided by SDK. Now let's keep this inside the while loop. So once the user will type its input, while user input is not is equals

[22:13] to end chat, this both the commands will continue until the user input is not end chat. Be very sure about the indentation because it is very important in Python. So these two commands will come inside while loop and this will run till then

[22:29] while loop and this will run till then the input is end chat. So this entire code will just work like this. That's it. We just don't have used generate content method. Instead we have used an automated method which will

[22:44] automatically create the backend system of conversation history. Let's save this. Now let's run this. Python chat main.py. Python chat main.py. It's not chat demo, it's chat main. Hi.

[22:59] So here we can type hi. Hello, how can I help you? Hello again. Hello, hello, hello, and this is running in the loop. So, it is replying is hi, hello, how can I help you today? My name is Stuti. Okay, my name is It's

[23:17] nice to meet you, Stuti. How is your day going so far? Is there anything I can help you with? So, we just need to check the conversation history. So, I'm asking, what is my name? Your name is Stuti. So, this is how we

[23:31] can execute the chat conversation history through the inbuilt function provided by SDK Google. So, this was our chatbot which was being created by our own self according to our need, and we can chat with our

[23:46] friend. And I have named my friend as Simply Bot. You can name your Simply Bot according to your own preference, and you can also start generating one and creating one for yourself, and start chatting with your own friend. And with

[24:00] that, you have successfully built your first generative AI application using Python. Try changing the assistant instructions and converting this chatbot into an application for your own use case. You can create a Python tutor, an

[24:15] interview preparation assistant, a content writing assistant, or a question answering tool for your documents. So, the best way to learn generative AI application development is to build small projects, test them, identify

[24:29] their limitations, and gradually add more advanced features to it. So, if you found this tutorial helpful, then like this video, share it with others, and subscribe to the channel. Also, turn on the notification bell so that you do not

[24:42] miss upcoming tutorials on Python, generative AI, machine learning, application development, and artificial intelligence. Thanks for watching, and intelligence. Thanks for watching, and I'll see you in the next one.

More from Simplilearn

View all

⚡ Saved you 0h 25m reading this? Transcribe any YouTube video for free — no signup needed.