Thursday, March 23, 2023
No Result
View All Result
Get the latest A.I News on A.I. Pulses
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
No Result
View All Result
Get the latest A.I News on A.I. Pulses
No Result
View All Result

Construct an Automated, AI-Powered WhatsApp Chatbot with ChatGPT utilizing Flask | by Pragnakalp Techlabs | Jan, 2023

February 3, 2023
141 9
Home A.I News
Share on FacebookShare on Twitter


All of us agree to some extent that by now we not solely have heard about ChatGPT but additionally received a hands-on expertise with it and we Cherished it! For individuals who haven’t received an opportunity to get in contact with ChatGPT here’s a temporary introduction: ChatGPT is a big language mannequin skilled by OpenAI, and it was designed to help customers by producing human-like textual content based mostly on the given immediate. It might assist with a variety of duties, similar to answering questions, offering info, and interesting in conversations on quite a lot of subjects.

On prime of that ChatGPT has left us dumbstruck by producing unimaginable solutions to virtually something, you throw a query and it’ll give you the proper reply that we have been discovering onerous to write down.

At Pragnakalp we consider in making issues user-friendly, since ChatGPT is one thing that can ease our life by leaps and bounds, we considered making it accessible at our fingertip. So we brainstormed and got here up with the thought of utilizing ChatGPT on WhatsApp!!

Sure, you learn it proper “ChatGPT on WhatsApp!” or what if we are saying ChatGPT on any of your preferable platforms?

This weblog describes how one can combine the WhatsApp Enterprise API, hosted by Meta, and create a python utility based mostly on the Flask net framework that may obtain consumer WhatsApp messages and make the most of ChatGPT to answer these messages intimately.

Step 1: Combine WhatsApp Enterprise API

To automate the messages with the Flask utility, we should combine the WhatsApp Enterprise API. For that comply with our weblog WhatsApp Enterprise API Setup to ship and obtain messages utilizing a check telephone quantity. Please guarantee that you’ve adopted the weblog’s directions earlier than continuing.

Step 2: ChatGPT API

We’re going to make use of ChatGPT API to answer customers’ messages. Detailed directions for organising and utilizing ChatGPT are supplied on this part.

The ChatGPT API affords a straightforward strategy to embrace technologically superior language understanding in your net providers. Since there are at present no official API endpoints obtainable, the ChatGPT neighborhood has developed quite a lot of easy options that you should use.

Stipulations

Earlier than we start using the unofficial ChatGPT API, please comply with the steps listed beneath to configure the code.

1. Clone this Git repository.

git clone https://github.com/mmabrouk/chatgpt-wrapper

2. To make use of this API, please just remember to have put in setuptools

pip set up setuptools

3. Set up dependencies by working the beneath command.

pip set up git+https://github.com/mmabrouk/chatgpt-wrapper

4. Putting in a browser in Playwright is required for launching the applying. By default, the script will use Firefox.

playwright set up firefox

After working the above command it’ll give a message as proven within the beneath picture, if you’re putting in playwright for the primary time, it’ll ask you to run playwright set up command one time solely.

5. After set up is completed, you possibly can run this system in Set up mode by working beneath command

chatgpt set up

It’ll open a brand new browser window as proven within the beneath picture, and ask for login or join chat.openai.com.

Log in and cease the working program and restart it.

Now you should use it with the shell command chatgpt <your immediate> with out “Set up” as proven within the beneath picture

Word: Nonetheless after a while, if you’re not actively utilizing ChatGPT it’ll expire your session mechanically and it’s essential to log in once more with chatgpt set up

Create an occasion of the category, use the ask technique to ship a message to OpenAI, after which use the response to work together with ChatGPT through the ChatGPT class as an API.

from chatgpt_wrapper import ChatGPTimport time

immediate = “what’s coronavirus? clarify me in 2 3 strains”bot = ChatGPT()response = bot.ask(immediate)print(“Immediate: “,immediate)print(“Response: “,response)

That is the response we received from chatGPT API.

Step 3: Combine ChatGPT API with Flask Software

After our ChatGPT API received put in efficiently, it’s time to combine it with the flask utility.

Now we have to modify the flask app that we’ve created in Step 1. Substitute your current code with the beneath code to get the consumer message’s response from ChatGPT.0][‘value’][‘contacts’][0][‘wa_id’] send_msg(response,receiver_number) besides: go return ‘200 OK HTTPS.’ if __name__ == “__main__”: app.run(debug=True)

from flask import Flask, requestimport requestsfrom chatgpt_wrapper import ChatGPT

app = Flask(__name__)

def send_msg(msg,receiver_number):

headers = {‘Authorization’: ‘Bearer VERIFICATION_TOKEN’,}json_data = {‘messaging_product’: ‘whatsapp’,’to’: receiver_number,’sort’: ‘textual content’,”textual content”: {“physique”: msg}}response = requests.publish(‘ headers=headers, json=json_data)print(response.textual content)

@app.route(‘/receive_msg’, strategies=[‘POST’,’GET’])def webhook():res = request.get_json()print(res)attempt:if res[‘entry’][0][‘changes’][0][‘value’][‘messages’][0][‘id’]:chat_gpt_input=res[‘entry’][0][‘changes’][0][‘value’][‘messages’][0][‘text’][‘body’]bot = ChatGPT()response = bot.ask(chat_gpt_input) print(“ChatGPT Response=>”,response)receiver_number=res[‘entry’][0][‘changes’][0][‘value’][‘contacts’][0][‘wa_id’]send_msg(response,receiver_number)besides:passreturn ‘200 OK HTTPS.’

if __name__ == “__main__”:app.run(debug=True)

Word:

Run the flask utility within the terminal: python SCRIPT_NAME.pyRun the ngrok on terminal: ngrok http 5000

Step 4: Check Chatbot

Now come again to the “Getting Began” web page as proven within the beneath picture and click on on the “Ship Message” button.

For all occasions, together with message ship, message supply, and message learn, you’ll obtain a response in your Flask app on the receive_msg endpoint. The ChatGPT response could be checked on the server terminal as nicely.

Right here is the ChatGPT response on our server.

You may also examine the conversion with ChatGPT on WhatsApp

We hope that you’ve efficiently built-in the ChatGPT in WhatsApp and having enjoyable in utilizing it.



Source link

Tags: AIPoweredautomatedBuildChatbotChatGPTFlaskJanPragnakalpTechlabsWhatsApp
Next Post

Introduction to Robotic Security Requirements

Use of ML in HealthCare: Predictive Analytics and Prognosis

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent News

AI vs ARCHITECT – Synthetic Intelligence +

March 23, 2023

Entrepreneurs Use AI to Take Benefit of 3D Rendering

March 23, 2023

KDnuggets Prime Posts for January 2023: SQL and Python Interview Questions for Knowledge Analysts

March 22, 2023

How Is Robotic Micro Success Altering Distribution?

March 23, 2023

AI transparency in follow: a report

March 22, 2023

Most Chance Estimation for Learners (with R code) | by Jae Kim | Mar, 2023

March 22, 2023

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
A.I. Pulses

Get The Latest A.I. News on A.I.Pulses.com.
Machine learning, Computer Vision, A.I. Startups, Robotics News and more.

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
No Result
View All Result

Recent News

  • AI vs ARCHITECT – Synthetic Intelligence +
  • Entrepreneurs Use AI to Take Benefit of 3D Rendering
  • KDnuggets Prime Posts for January 2023: SQL and Python Interview Questions for Knowledge Analysts
  • Home
  • DMCA
  • Disclaimer
  • Cookie Privacy Policy
  • Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In