Introduction: DaVinci - the ChatGPT AI Virtual Assistant You Can Talk To

DaVinci - The ChatGPT AI virtual assistant is a voice-controlled and voice-response assistant that uses OpenAI’s artificial intelligence language model to assist with a wide range of tasks, such as answering questions, providing information, giving suggestions, telling jokes, writing stories and much more. In addition to providing responses verbally, DaVinci also provide written responses if your device is connected to a display.

You can watch a brief video demo of DaVinci – The ChatGPT Virtual Assistant here: https://youtu.be/r2R4Yoy8XzU.

Davinci - The ChatGPT AI virtual assistant is a python program that utilizes Picovoice Porcupine (and (PyAudio) to detect a wake word; Picovoice Cobra voice activity detection to determine when the user begins and finishes speaking their query; Picovoice Leopard to convert the spoken query to text; OpenAI ChatGPT as the artificial intelligence that responds to the query; Amazon Polly text to speech to convert the response into a natural-sounding human voice; and Pygame to play the audio. 

DaVinci uses the most current ChatGPT API that was released on March 1, 2023. DaVinci will be updated to run on GPT4 as soon as that API is widely available to developers. 

The instructions below are for running the DaVinci – The ChatGPT AI Virtual Assistant on a Raspberry Pi 4, but it can also be run on other systems with minimal modifications. The process for obtaining access keys for ChatGPT, Picovoice solutions and Amazon Polly is the same regardless of the system used.

Supplies

Raspberry Pi 4 – This needs to be a Raspberry Pi 4, so that you can run the 64-bit operating system. Earlier versions of Raspberry Pis are likely to throw memory errors while running this program. The 2 GB RAM model is sufficient: https://www.adafruit.com/product/4292

Power Supply – 5v power supply. I recommend the official Raspberry Pi power supply:

https://www.adafruit.com/product/4298

USB Microphone – for talking to the assistant. Any USB mic should work, and this inexpensive one is sufficient: https://www.adafruit.com/product/3367

USB speaker – for the assistant to talk back to you. I used this one: https://www.adafruit.com/product/3369

LEDs (optional) – The program optionally lights LEDs when it detects the wake word and pulses them when it is responding to your queries. These spherical LEDs were used in the video demo: https://www.adafruit.com/product/5430

Resistors (220 ohm) (optional) – Only needed if you decide to use the optional LEDs. I used these:

https://www.adafruit.com/product/2780

Heatsinks (optional) – The heatsinks are optional but are highly recommended if you will put your Raspberry Pi in a case or other confined container such as the one used in the video demo. I used these: https://www.amazon.com/dp/B07ZLZRDXZ?psc=1&smid=A2PL6UUXJC5K5G&ref_=chk_typ_imgToDp

Step 1: How to Run Davinci on a Raspberry Pi 4 Mini-Computer

The following steps are required to run Davinci - The ChatGPT AI Virtual Assistant on your Raspberry Pi 4:

 ·      Obtain the necessary hardware

·      Create an OpenAI account and obtain your personal secret API key

·      Create a Picovoice account and obtain your personal secret access key

·      Create an AWS account and obtain your personal access key and secret access key

·      Follow the other steps below for preparing your Raspberry Pi and downloading DaVinci - The ChatGPT AI Virtual Assistant

 Note that although account registrations are required to obtain the keys to use the outside services and that production-use of those resources requires the payment of fees, these services should all be free to a user, at least for a limited time, who only utilizes them for the hobbyist requirements of DaVinci - The ChatGPT AI Virtual Assistant for private use. 

Step 2: Optional LED Wiring

DaVinci – The ChatGPT AI Virtual Assistant includes the ability to light up LEDs that help show the status of the program. If connected, the LEDs will light up when the program hears the wake word and will pulse after the user finishes their query and while the assistant provides its response. The proper wiring of the LEDs and resistors to the Raspberry Pi is shown on this diagram. The LEDs are controlled by GPIO pins 18 and 23. The use of the LEDs is optional and will not otherwise impact the functionality of DaVinci.

Step 3: Create an OpenAI Account and Obtain Your Secret OpenAI API Key

Open a web browser on your PC and navigate to the OpenAI website - https://openai.com/.

In the upper right-hand corner, click on “API”.

On the next screen, click on "Sign Up" and then follow the prompts to create your account.

Next, on the logged-in screen, click on your Personal icon in the upper right-hand corner and then click on “View API keys”.

Then click on "+ Create new secret key" to create your new secret API key. 

Copy your API key and keep it in a secure location. You will need it in a later step.

Step 4: Create a Picovoice Account and Obtain Your Secret Picovoice Access Key

Create a free Picovoice account by opening a web browser and navigating to https://picovoice.ai/.

In the upper right-hand corner, click the "Start Free" button and follow the prompts to open your account.

As soon as you complete your sign up, you will automatically be redirected to a page with your secret access key.

Copy your "AccessKey" and keep it in a secure location. You will need it in a later step.

Step 5: Create an AWS Account

Create a free AWS account by opening a web browser and navigating to the following website to use the AWS Free Tier: https://aws.amazon.com/free/.

In the upper right-hand corner, click on the "Complete Sign Up" button and follow the prompts to open your account.  

Step 6: Create an AWS IAM User Account and Obtain Your AWS Access Key and Secret Access Key

After you create your AWS account, you will next need to create an IAM User Account on AWS. To do so, follow AWS’s instructions here: https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-set-up.html#create-an-admin

Copy your “Access key” and “Secret access key” and keep them in a secure location. You will need them in a later step.

Step 7: Prepare Your Raspberry Pi 4 to Run the Program

These instructions assume you already have a Raspberry Pi 4 set up and running. If not, set up your Raspberry Pi using the instructions found here: https://www.raspberrypi.com/tutorials/how-to-set-up-raspberry-pi/

Be certain to load the 64-bit (not the 32-bit) version of the Raspberry Pi OS when setting up your Raspberry Pi. If you use the 32-bit version, you are likely to get memory errors when running the program.

To prepare your Raspberry Pi to run DaVinci – The ChatGPT AI Virtual Assistant, do the following:

1. Edit the bashrc file on your Raspberry Pi as follows:

a. Open a terminal and enter the following command to open the bashrc file:

   sudo nano ~/.bashrc

b. Scroll to the bottom of the file using your keyboard and add the following lines at the end (be certain to include the #s):

   # sets a location where the Raspberry Pi OS and Python can look for

   # executable/configuration files

   export PATH="$HOME/.local/bin:$PATH"

c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.

d. Then enter the following command:

   sudo reboot

This will reboot your Raspberry Pi. After the reboot is completed, log back in.

2. Open a terminal and enter the following commands in the following order:

   sudo apt update

   sudo apt full-upgrade

   pip3 install --upgrade pip

   sudo apt-get install portaudio19-dev [When asked if you want to continue, enter Y

   and then press Enter]

   pip3 install pyaudio

   pip3 install pvrecorder

   pip3 install pvporcupine

   pip3 install pvcobra

   pip3 install pvleopard

   pip3 install --upgrade openai

   pip3 install boto3

   pip3 install awscli

   sudo reboot – will reboot your Raspberry Pi; log back in after the reboot.

3. Configure the AWS command line interface by opening a terminal and entering the following command:

   aws configure

The following lines will appear one-by one. Take the actions specified in the brackets:

   AWS Access Key ID [None]: [type in your access key ID and press enter]

   AWS Secret Access Key [None]: [type in your secret access key and press enter]

   Default region name [None]: [check for the name of the region closest to you here: https://docs.aws.amazon.com/general/latest/gr/rande.html#pol_region – mine is us-east-1 – then type it in and press enter]

   Default output format [None]: [leave this blank and press enter]

4. Download the GPTModelCompare.py program and associated files by opening a terminal and entering the following command:

   git clone https://github.com/DevMiser/DaVinci.git

5. Modify DaVinci.py to include the secret API key that you previously created in your OpenAI account and the secret access key that you created in your Picovoice account by doing the following:

a. Open a terminal and enter the following commands:

   cd /home/pi/Davinci

   sudo nano DaVinci.py

b. Use your keyboard to scroll down to the lines that say:

   openai.api_key = “put your secret API key between these quotation marks

   pv_access_key= “put your secret access key between these quotation marks

Now modify those lines to replace the portions that are italicized above with your secret OpenAI API key and your secret Picovoice access key, respectively.

c. Press the CTRL and X keys simultaneously on your keyboard, then press Y and then press Enter to save the revisions to the file.

6. Move the DaVinci keyword file to the Porcupine raspberry-pi folder by entering the following command:

   mv /home/pi/DaVinci/DaVinci_raspberry-pi.ppn /home/pi/.local/lib/python3.9/site-packages/pvporcupine/resources/keyword_files/raspberry-pi

[Note that there are two blank spaces in the above command - between "mv" and "/home" and between ".ppn" and "/home". Be sure to include them. There is no space in "site-packages".]

7. Reboot your Raspberry Pi.

Step 8: Run the Program

Plug your microphone and speaker into USB ports on your Raspberry Pi 4.

To run the program, open a terminal and enter the following commands:

   cd /home/pi/DaVinci

   python3 DaVinci.py

You can then wake up your ChatGPT AI Virtual Assistant by saying one of the following wake words: DaVinci, computer or Jarvis.

DaVinci – The ChatGPT AI Virtual Assistant will respond by saying “How may I assist you?”, “I’m listening.” or something similar.

Then make your request. For example, say:

Describe purple.

What is the difference between pumas and leopards?

What are the most popular tourist attractions in Tel Aviv?

What would happen if the moon disappeared?

What can you do?

Write a silly dialogue between a stapler and a coffee mug.

What is the plot of To Kill a Mockingbird?

What is the meaning of the song Stairway to Heaven by Led Zeppelin.

Tell me a story about a mouse named Mike who is looking for his lost cheese in the Astrodome.

What are the top 5 foods that should be included in a healthy diet.

Make a joke about dancing robots.

How can I avoid procrastinating today?

Write a short poem about artificial intelligence.

When you are finished with the program, press the CTRL and C keys simultaneously on your keyboard and you will exit the program.

Step 9: DaVinci 3D Printing Instructions (optional)

There are three .stl files attached for 3D Printing:

1. DaVinci-Body.stl – this is the main body that holds the mic, the speaker and the LEDs. Please see the DaVinci – The ChatGPT Virtual Assistant Instructions for a parts list. You will also need an angled USB extension cable that will fit inside the body to connect the mic and speaker. I recommend the following which will allow you to plug the mic and speaker into a single extension cable:

https://www.amazon.com/dp/B07ZV7RDNH?psc=1&ref=ppx_yo2ov_dt_b_product_details

If you want DaVinci’s hair to be a different color than his body, just insert a change filament instruction at the approximate layer that the hair begins when you use your preferred slicer.

2. DaVinci-BasePlate.stl – this is the bottom part of the body.It has four pegs that the Raspberry Pi 4 will fit onto.You can permanently affix your Pi to the bas by putting a little glue at each peg after the Pi is mounted.There is a on the back of the main body for the poser supply plug, so be certain to arrange your Pi on the base in the correct direction.

3. DaVinci-EyeSocket.stl – these fit into the holes for the eyes on the main body and the spherical LEDs will fit inside these sockets. You need to print two of them of course.

You can print the parts with whatever type of filament you prefer, but PLA works fine. I recommend using organic supports for the DaVinci-Body. The DaVinci-BasePlate and DaVinci-EyeSocket do not require supports.  The base can be attached to the body with screws or glue.