Building a ChatGPT-Powered Robot Assistant (BIA) (part1: Laptop)

by TylerDDDD in Circuits > Software

336 Views, 1 Favorites, 0 Comments

Building a ChatGPT-Powered Robot Assistant (BIA) (part1: Laptop)

IMG 2276
rpbiaspeech.png
Capture d’écran 2024-04-05 à 10.00.29.png

Hello

Hi there :) My nickname is TylerMaker, I live in France and am happy to share with you the lines below. This Instructables is the first in a serie of three.

What is BIA (AI) ?

BIA is an AI vocal assistant.. all in one software : ChatGPT, voice command, YouTube, Netflix, TV, Radio and web navigation. BIA is multi language, ... and BIA also provides AI to the educational Otto robot :)

Example of what you can do with it :

  • Chat with ChatGPT
  • Ask Bia to open a web page, YouTube, a radio, a TV channel or Netflix
  • Ask Bia to take a picture
  • Ask complex instruction with a If This Then That logic
  • Save complex instructions as a macro
  • Ask Otto the robot to dance, sing, walk, ...
  • And some more

The brain of Bia is the Python module biaspeech. I developed the the package and made it available for download. This instructable explains how to install the module, customize it and use it on a laptop.

Supplies

Capture d’écran 2024-04-05 à 08.25.22.png
Capture d’écran 2024-04-05 à 08.30.03.png
Capture d’écran 2024-04-05 à 10.48.24.png

You need a Macbook, iMac or a laptop :)

The program was developed on MacOS Catalina version 10.15.7 and Python version 3.8. Should run also on Windows or Linux, to be tested still :) .. Any MacBook can be a good starting point or any laptop, the minimum configuration is that python 3.8 minimum and Arduino IDE can be installed on it.

Please note that the links above are part of the Amazon associates program.

We are using ChatGPT, we need an OpenAI key..

As a prerequisite you need to create an open account in order to use ChatGPT. Then you need to request an API Key.

Check the instructions directly at the OpenAI help page : here.

Note : the usage of the API of chatGPT is not free but indeed very cheap. In general a few cents by month only. After 3 months developping and testing the program I was charged only 14 cents.

Take note of the API key and go to the next step.

We are using Python, you need to install it on your laptop..

Download and install Python 3.8 : link

The Concept

Capture d’écran 2024-03-25 à 22.27.34.png
Capture d’écran 2024-04-05 à 10.58.08.png
Capture d’écran 2024-04-05 à 10.57.46.png

Concept

double layer IA mechanism provide fast and accurate answers :

First layer

The first layer is powered by OpenAI (chatGPT), it takes care of answering the questions

Second layer

The second layer is processed by a native AI, it takes care of :

  • Cache management : questions and answers are cached in a local database. The goal of it is to get rid of the network latencies whenever possible (requests to chatGPT are network dependent, requests to the cache are not). The goal of it is ensuring faster answers
  • Categorization : the input is categorized with a NLP (Natural Language Processing) technique into categories like question, feedback, action, etc
  • Paraphrases : if for example you ask "how are you", and then later "how are you doing" both questions will be considered similar and the same answer will be picked up from the cache
  • Emotions : the user input is scored on several axis (positive, negative, neutral). Based on the emotion the previous answer will get promoted or deprecated in the cache
  • Scoring : each prompt/interaction is scored, in this way only the best answer is given
  • Smart actions (complex requests), like If This Then That requests, instructions to Otto Robot, etc

Install the Python Dependencies

Capture d’écran 2024-04-05 à 10.50.58.png
Capture d’écran 2024-04-05 à 08.42.31.png
Capture d’écran 2024-04-05 à 11.29.17.png
Capture d’écran 2024-04-05 à 10.00.29.png

Prerequesites

Download and install homebrew-4.2.4.pkg

Install one by one the libraries : 

pip install openai
pip install websockets
pip install argostranslate
pip install py3langid
pip install pyautogui
pip install pyaudio
pip install speechrecognition
pip install pyttsx3
pip install parrot
pip install opencv-python --verbose
pip install customtkinter
pip install pyduinocli
pip install pyserial
pip install sounddevice

Install the languages :

argospm install translate-de_en
argospm install translate-en_de
etc with all the languages needed

Download the nltk ressources :

pip install nltk
python3
>> import nltk
>> nltk.download('punkt')
>> nltk.download('vader_lexicon')

Install the Arduino Client

Programs to manage the Arduino of the robot

Install arduino-cli and arduino avr. Important : the Arduino-cli file must be in the bin folder

<<python package>>/bin/.

The command to install arduino-cli and arduino avr are :

curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
./arduino-cli core install arduino:avr

Install the Python Package Biaspeech

Package Biaspeech

Biaspeech is available online on PyPi. It is the BIA engine core program.

pip install biaspeech

Run file

Create a file run.py. Enter the code as below. Save the file

# --------------------------
# Main folder
#
# run definition
# --------------------------

import os
os.environ['OPENAI_API_KEY'] = "xxxx" # openAI API key.. replace xxxx with your own key :)
os.environ['OS'] = "macos"
os.environ['ARDUINO'] = ""

from biaspeech import biaspeech
biaspeech()

To make it easier, you can also create a shortcut on your desktop.

Play With It

Capture d&rsquo;&eacute;cran 2024-04-05 &agrave; 08.40.49.png
Capture d&rsquo;&eacute;cran 2024-04-05 &agrave; 08.38.43.png
Capture d&rsquo;&eacute;cran 2024-04-05 &agrave; 08.37.18.png
Capture d&rsquo;&eacute;cran 2024-03-27 &agrave; 20.27.21.png

Basic usage of BIA, app mode :

  • Open a terminal, then type : 
python3 run.py
  • The BIA app will open, just push the button and ask a question. BIA will answer ... Enjoy :)

Advanced usage of BIA, command line mode :

  • Open a terminal, then type : 
python3 run.py "what can I do a friday afternoon in Paris?"
python3 run.py -help
python3 run.py -version
  • BIA will answer ... Enjoy :)

Developer usage of BIA, keyboard mode :

  • Open a terminal, then type : 
python3 run.py
  • Write a question. BIA will answer ... Enjoy :)

Note : the UI parameter under the [main] section must be set to "keyboard".

The config file can be found under :

<<python package>>/utils/config.cfg

Developer usage of BIA, voice mode :

  • Open a terminal, then type : 
python3 run.py
  • Ask a question. BIA will answer ... Enjoy :)

Note : the UI parameter under the [main] section must be set to "voice".

Example of some prompt :

  • Quelle est la capitale de la France?
  • How are you today?

Advanced Options

Advanced prompts :

  • I do not like this answer => a negative prompt will decrease the scoring of the latest answer, it will go down in the cache
  • I like this answer very much => a positive prompt will increase the scoring of the latest answer, it will stays up in the cache

Skills. The special prompts are the following :

  • camera : take a picture => Example : Camera now
  • macro : save the last command as a keyword => Example : Macro salsa
  • netflix : run netflix and search for a movie => Example : Netflix breaking bad
  • python : run a combination of prompts => Example : Python if the capital of France is Paris then Arduino walk one meter
  • radio : open the web radio site and search for a station => Example : Radio deutschlandfunk
  • tv : open molotov tv => Example : TV m6
  • web : open a website => Example : Web google.com
  • youtube : open youtube and search for some => Example : Youtube dire straits
  • arduino or robot : ask the otto robot to do something
The predefined keywords for the robot are : walk, back, left, right, stop, happy, sad, surprise, moonwalkerleft, moonwalkerright, sing
A predefined keyword means that the Arduino code for the keyword/action is preloaded in Arduino. For others than those 11 predefined actions, a live request to chapGPT will dynamically build the Arduino code.
=> Example : "robot walk" .. the keyword walk is predefined... the Arduino code for it is preloaded
=> Example : "robot dance the salsa" .. this is a new action, chatGPT will generate live the Arduino code

Remote control

You can remote control BIA with VNC, this is explained in the next Instructables.

Update the paraphrases

Run the command below to update the paraphrases. Paraphrases are synonyms sentences stored in the local database. The cache will use those sentences to speedup the answers.

python3 run.py -update

Next Steps

Check those instructables

Annexes

Small donations matter : you can buy me a coffee :)

BIA(AI) © 2024 by Nicolas CHRISTOPHE is licensed under CC BY-NC-ND 4.0. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/

The python package is available on PyPi : https://pypi.org/project/biaspeech/