0% found this document useful (0 votes)
27 views4 pages

Lecture-28 - ChatBot Using OpenAI Streamlit

Uploaded by

Tahir Mahmod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Lecture-28 - ChatBot Using OpenAI Streamlit

Uploaded by

Tahir Mahmod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1

AI Free Basic Course | Lecture 28 | ChatBot Using OpenAI


Streamlit | Live Session

Exciting! we are diving in code and showing you the its structure
today. During the coding we would tell you about ethics, rules of
coding, mindset and approach. We would present it in generic form so
that it may help you in case in doing any form of coding. It must keep
in mind that even after having vast experience of 10 or 20 years, you
will always find difficult the code that is written by others. It is
the patience that needs to be practiced at that time. Take some time
and let the brain absorb that code. You will see that code after some
time would look like technical love letter to you. To day we are going
to start the coding round of hackathon.
Although, the concept of NLP exists more than two decades, but
revolution in this area has evolved during the last two quarters. The
areas like NLP, ChatGPT, ChatBot etc are among the top searches of
Upwork which are being discussed in our lectures. These areas can play
their role in economy. Chatbot is one of these enabling technologies.
Chatbot can be applied at the areas where there is customer
interaction like reception, customer care and in many other areas. It
is most suitable to ask, what are the areas where chatbot could not be
applied? Difficult to find these areas. Every organization, business
and commerce require chatBot not only for the external interface but
also for framing the internal policies their employees have to follow,
for developing systems through which employees will communicate with
each other. For facilitating all business needs of the organizations,
chatBot is the revolutionary technology.
Previously chatBots were utilized in customer services, now due to
their application in vast areas, we say it SuperBots. In the past for
making any type of decision related to expansion of business,
financial goals, strategical goals, technical expansion, HR, a
meeting with department heads, HR heads, Accountants and CFOs etc was
called for taking inputs from them in order to reach a decision of
strategic nature. So, in order to make a strategic decision input from
5 to 6 experienced or experts was required. Input from them was based
on textual data of their relevant field or department. So if the input
is related to textual data than why humans are between input and
decision making? Let us replace SuperBot with humans which will take
input from the textual data and will help in making the best strategic
decisions. We all know that human decisions are biased but not is in
case of technological decisions which give you accuracy. That’s why we
say that ChatBot is the technology everyone needs.
Toay’s lecture will not make you expert in chatBot. We will over view
the its structure, its connectivity with front end, how APIs are
called, how cods are deployed, how communications are made, how packed
are passed, how information is passed on, how information is
retrieved.
Prepared by: Tahir Mahmood 0321-5111997, What up 0312-8536439
2

In response to our Hi, AI Mentor is introducing itself, talking about


its expertise and offering its services.
Now questions arise where does the question we ask from AI is stored?
How the response to this question is begin generated? What process is
being executed in the background?
A temporary memory called session is being utilized on the client-side
browser that records and keep record of all inputs and responses
executed during that session until the browser is refreshed. Remember
it does not mean that information will be stored in it forever if
browser is not refreshed. There is upper limit of storage of
information after which it will be removed automatically.
The information stored in session is more prone to hacking as
retrieving information from the session end is easier than retrieving
information from the server end. so the sensitive information like
passwords emails should never be store in sessions. So, there are two
sessions, one is related to server that is secure and browser session
that is although faster but is insecure. ChatGPT stores information on
server side in database not in session.
Now following aspects need to be remembered:

 Input must be safe


 Response should be generated
 Response must be displayed in parallel to the input. So the
question and answers are store in a sequence and context is
established.
Let us explain how context is established. When the response is
generated, it is store in two places. One at ChatGPT and other in
tuple or in list.
Prepared by: Tahir Mahmood 0321-5111997, What up 0312-8536439
3

Purpose of ChatBot is not limited to take the question, respond it


from the ChatGPT and pass on this response to the user. There are lot
of basic things we need to understand first. We must understand how
input is processed, how context is established? how a new input is
generated which is not visible to the user, how that input approaches
ChatGPT, how response from ChatGPT is pushed into session and how
finally it is displayed. There is need to understand that during all
this where processing can be made, how checks can be applied and what
are techniques through which we can control the code. This is all we
are going to show you.
Look a series of horrible code has been displayed in front of you on
the screen. Don’t worry about the code, 60% to 70% code will be
provided to you and rest of the code you will patch yourself.
(‘Enter the Prompt’)
We are storing user response in the variable Ener Prompt in
session state.
We need to take care of three things. First of all, we need to apply
checks related to any input, if he checks are at their place move
further otherwise do as per instruction given.
You have to save the response of AI, prompts from the user. User
prompts would now be of two types. First session would be initial
prompt given by the user, second session would be where user further
prompts would be stored and third session would store the AI generated
responses.
So, first, session state would be about User Prompt. Second session
would be about past prompts of the user and the third session would be
about AI generated responses.
The code in the third session state is check that confirms whether AI
generated response has been initiated or not, if it has not been
initialized, initialize it with the empty list. Repeat it with the
empty list whenever the AI generated response has not been
initialized.
After first step you have to define your large language model. For
this we utilize ChatGPT model called chat open.ai. We have to mention
specifically which model of chatGPT is being utilized whether it is
ChatGPT 3 or 3.5 turbo or ChatGPT 4. For using any of these models a
key would be required which have been sore in secret file created in
streamlit.
After selecting the model, we will define its parameters. Temperature
is set to define the level of creativity to use, its model name and
its key store in secret file created in streamlit.
Here come the next important stage where whole of the chatBot is
based. It is the technique through which we define the role of prompt.
For the purpose a separate function has been built named as Build
message list. Back ground of all this is that we have input from the
Prepared by: Tahir Mahmood 0321-5111997, What up 0312-8536439
4

user and response generated from AI. Now third thing which is role of
chatBot would also be included in it.
Remember chaBot is like a machine and knows nothing except what is fed
into it. So we have to remind it about its identity and function it
has to perform and keep building its memory about the scenario of
discussion.
We are defining its name as you are AI mentor. The name given to it
would exactly be reflected in the behavior while generating the
output. This is the basic working to start the prompt and by analyzing
its output more checks would be applied to Do’s and Not to Do’s for
improving its performance.
Now stage wise instructions to the ChatBot for controlling the prompt
has been given as follow: These are called guard waves.
So there is system message and have complete prompt which will act as
prompt base knowledge upon which behaviour of prompt will depend.
Now zinlongest function will comprise user past messages and messages
generated by AI, a loop comprising two variables human_message and
AI_message will be applied. Human_message will relate to past messages
and AI message variable will relate to message generated by AI

Prepared by: Tahir Mahmood 0321-5111997, What up 0312-8536439

You might also like