Technology

Check Out How to Build Your Own AI Chatbot With ChatGPT API

The idea behind ChatGPT has gained a lot of traction, and other businesses have adopted its technology. Although being only a computer, the AI chatbot answers queries in a straightforward, basic, and nearly human-like manner. How to use the ChatGPT API to create your own AI chatbot?
Below are the procedures to follow if you are familiar with ChatGPT and want to create your own version of it. Of course, it is not an easy process, but if you have some expertise and follow the instructions below, you should be able to accomplish it.

How may a custom AI chatbot be created?


The ChatGPT API model is now accessible to the public so that people may utilize it for themselves, according to a new movie by the ChatGPT creators. The new “GPT-3.5-turbo” model is ideal for novices since it is a very affordable model that can be used for practice and a variety of tasks.
Here’s a quick guide to building your own AI chatbot:

The first steps
Before beginning to really create a chatbot, you must install and update a few fundamental components. Beforehand, be sure you adhere to these.

Step 1:

Python installation on your PC is the first step. Before continuing to the following step, be sure you set it up as well.

Step 2:

Run the setup file as the next step, being careful to tick the option to “Add Python.exe to PATH” before doing so. You only need to install Python after that.

Step 3:

Make sure Python is functioning correctly on your PC right now.

Step 4:

Your computer also downloads Pip, which enables you to install all Python libraries from the Terminal, including the OpenAI and Gradio libraries. Open the Windows Terminal first to check sure it has been updated.

Step 5:

You next use the command “python -m pip install -U pip” to finish.

Step 6:

The OpenAI library must then be installed via Pip. That is really easy. Run the program by going to the Pip terminal and typing “pip install openai”. If “pip” does not work, try “pip3,” which is required if you use Linux.

Step 7:

One more thing has to be installed on Pip after OpenAI: Gradio. This will enable you to create a user-friendly web interface and distribute the chatbot to others. You may accomplish this by going to Pip Terminal, typing “pip install gradio,” and then pressing Enter.

Step 8:

Before beginning, you should also download a code editor. There are three options available.

  1. Notepad++
  2. Sublime Text
  3. Caret app

Step 9:

You have nearly finished the preliminary steps. Create a free OpenAI account first, then join up or, if you already have one, log in.

Step 10:

Once that is done, click on your profile in the top right corner of the page. The third option is “see API keys,” so choose that.

Step 11:

You must now select “Generate new secret key” to continue. This key must be copied because it only appears once before disappearing. It costs nothing for up to $5 in credit but cannot be shared.

the actions taken
Eventually, because the prior procedures have all been completed, we can begin developing your own chatbot. Here’s how to go about it.

Step 1:

Start by launching the Notepad++, Sublime Text, or Caret apps. You then need to add the slightly modified code, which is as follows:
import gradio as gr import openai

 

openai.api_key = “Your API key”

 

messages = [

    {“role”: “system”, “content”: “You are a helpful and kind AI assistant.”

]

 

def chatbot(input):

if input:

        messages. append({“role”: “user”, “content”: input})

     chat = openai.ChatCompletion.create(

            model=”gpt-3.5-turbo”, messages=messages

     )

     reply = chat.choices[0].message.content

        messages.append({“role”: “assistant”, “content”: reply})

     return reply

inputs = gr.inputs.Textbox(lines=7, label=”Chat with AI”)

outputs = gr.outputs.Textbox(label=”Reply”)

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=”AI Chatbot”,

             description=”Ask anything you want”,

             theme=”compact”).launch(share=True)

Make sure to replace the “Your API key” with the API key that you have.

Step 2:

The file must now be saved. Change the “Save as type” to “All kinds,” choose “Save as,” and give the file the name “XYZ.py.” The “XYZ” portion can be changed, but be sure to include “.py.”

Step 3:

Right-click the “XYZ.py” file by going to where it is saved. Choose “Copy as Path” after that, then head to your Terminal.

Step 4:

Type “python” in the Terminal, paste the “Copy as Path” file you previously copied, and then execute it.

Step 5:

Copy the “Running on local URL” from the very end of the program after it has finished executing.

Step 6:

Copy this URL, not the one that says “Running on public URL.” then, enter the Link into your computer browser..

Step 7:

You’ve finished now. The “Running on public URL” URL can be copied and forwarded to relatives and acquaintances. You must leave your computer on for the whole 72 hours that this connection is active. You must execute “step 4” once more in order to reactivate the chatbot.

Summary


Although there are many stages involved, creating your own chatbot is fairly basic and straightforward. Even if your first attempt is unsuccessful, you may try again and figure out what went wrong. It can be a lot of fun to do this. You should now be able to create your own chatbot after reading this post, hopefully!

 

Related Articles

Back to top button