Member-only story

Build Your Own Chatbot 🤖 with openAI GPT-3 and Streamlit 🎈

Avra
4 min readDec 24, 2022

--

Creating a Chatbot Has Never Been Easier with GPT-3 and Streamlit

👨🏾‍💻 GitHub ⭐️| 🐦 Twitter | 📹 YouTube | ☕️ BuyMeaCoffee | Ko-fi💜

Not a medium member ? Use this link and read the article for free!

TL;DR

  • Streamlit is used to create the chatbot interface and initialize variables to store the chat history.
  • The chat history is displayed by iterating through the generated and past lists and using the message function to display each message.
  • The tutorial provides a detailed guide on how to build a chatbot using OpenAI’s GPT-3 API and Streamlit.

The current blog post is well explained in this video ⤵️

Note : Consider this post/video tutorial as a continutation of the previous tutorial on Summarizing Scientific Articles with OpenAI ✨ and Streamlit 🎈 .

📌 Importing the libraries

The first step is to import the necessary libraries. We will be using openai to access the text generation API and streamlit to create the chatbot interface.

import openai 
import streamlit as st

# pip install streamlit-chat
from streamlit_chat import message

Next, we will need to set the API key for OpenAI. This key is used to authenticate our requests to the API.

openai.api_key = st.secrets["api_secret"]

Refer to the "🔧 Setting Up" section in the previous article for generating openAI API key and Streamlit secrets.

📢 Generating responses from the API

We create a function called generate_response that takes in a prompt and generates a response using the OpenAI API. The openai.Completion.create function allows us to generate text by providing it with a starting prompt. We can specify the engine to use, the prompt to generate text from, the maximum number of…

--

--

Avra
Avra

Written by Avra

Community Lead, Databutton. Biophysics, PhD Candidate

Responses (8)