- Daily Build
- Posts
- Build a chatbot with GPT-4 in 20 mins
Build a chatbot with GPT-4 in 20 mins
"Joshua's Chatbot"
I built my first chatbot!
It uses the GPT-3.5-Turbo model from OpenAI
I prompted ChatGPT (using GPT-4) to help me build it
Time to completion: 20 minutes
Building it
I’ve said this before but I think GPT-4 is still the best for code.
Prompts
For the first prompt:
“Help me create a chatbot in minutes!”
GPT-4 just wanted to create a normal chatbot without the use of an LLM or artificial intelligence for the responses.
So I followed up with this prompt:
“I think we should use some AI and an LLM, thoughts?” (I made it a question to seem collaborative and get its “why” response)
Of course it defaulted to using OpenAI for the model the model. It generated this piece of code which was pretty good:
import openai
openai_api_key = "YOUR-API-KEY-HERE"
def get_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=150
)
return response.choices[0].text
# A conversation loop to engage with the bot
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
break
prompt = "The following is a conversation with a chatbot:\nYou: " + user_input + "\nBot:"
response = get_response(prompt)
print("Bot:", response)
As you can see, the engine
parameter for the function is text-davinci-003
which is a relatively basic model compared to others.
I then had to re-prompt it to help me use the gpt-3.5-turbo
model and so it did.
After this, we needed a better design because it was absolutely terrible.
So I told it what was up with this prompt:
“Can you add some CSS to this? The current chatbot looks terrible. Please make it it dazzling,”
So it spat out an updated version of the index.html
file:
…& that’s it!
If you want to build your own chatbot -
You’ll need an API key from OpenAI (if you don’t have an OpenAI account, you really really should)
Put that key in the
YOUR-API-KEY-HERE
section from my code for authentication, and you should be good to go!
Verdict
I just wanted to a) create a chatbot using an LLM, and b) do it super fast.
And I did!
All in all, this was fun! I was happy with how fast I could whip this up… seriously, like only 20-25 mins.
For more advanced folks, you could “finetune” this model to create your own chatbot with a unique “style” or “tone.” (I’ll create a finetuned one in the future).
DO THIS: steal my code and just input your own OpenAI API Key and voila!
Know someone who wants to build a chatbot?
Send them this newsletter:
Reply