I am happy to announce that Q.Bo Stem, but also the Q.BO One version, (without touch screen), can use the artificial CHAT-GPT intelligence, with an appropriate update.
The use of Python3 (version 3.7 or higher), the Raspbian Buster operating system and a series of bookstores specially installed to give the chance to Q.BO to express itself in many languages is necessary.
In this regard, the "Robotics in Education" paper "text is available, at the moment in the English version (Amazon.com) and in the Italian version (Amazon.it), but soon also in the Portuguese, French and Spanish versions.
Link:
https://www.amazon.com/ROBOTICS-EDUCATION-CODING-English-version/dp/B0BRMT29KC/ref=sr_1_2?qid=1678982556&refinements=p_27%3ARomeo&s=books&sr=1-2
(ISBN-13 - 979-8372562745)
https://www.amazon.it/ROBOTICS-EDUCATION-Q-BO-CODING-STEM/dp/B0BCS36XHM
(ISBN-13- 979-8849977416)
It is possible to see some performances of Q.BO STEM at these sites:
https://www.youtube.com/playlist?list=PLeK5UVm7TTbYETUwOMdrXbcyv9ftrG9_V
https://www.tiktok.com/@qbo_robot
https://www.instagram.com/romeo_ceccato/
https://www.facebook.com/groups/114831101881687
I remain at your disposal for more information about it and thank you for your kind attention.
Is there some easy instal instructions for running this on QBO? our one stopped working with the google integration about a year ago and has not been doing anything since, he is an original backer version of QBO, my 8 year old would love him to be working again :) edit: he is always looking up too, would be nice if he looked straight and not up lol
In order for Q.bo STEM to be able to use CHAT-GPT, it is necessary to have the OpenAI credentials, in the example shown below, in python code, the complexity of use can be deduced.
Note that many things have changed compared to the original version of Q.bo One.
I recommend reading the text Robotics in education, to learn more about the topic.
# import the necessary packages
import speech_recognition as sr
import re
import os
import subprocess
import wave
import QboCmd_test_base_v3
import time
#import yaml
import time
import sys
import serial
port = '/dev/serial0'
import openai as ai
ai.organization = "your code"
#openai.api_key = os.getenv(" your code")
ai.api_key = "your code"
#openai.Model.list()
try:
print(port)
# Open serial port
ser = serial.Serial(port, baudrate=115200, bytesize=serial.EIGHTBITS, stopbits=serial.STOPBITS_ONE, parity=serial.PARITY_NONE, rtscts=False, dsrdtr=False, timeout=0)
print ("Open serial port sucessfully.")
print(ser.name)
QBO = QboCmd_test_base_v3.Controller(ser)
except:
print ("Error opening serial port.")
sys.exit()
# setting
for i, mic_name in enumerate(sr.Microphone.list_microphone_names()):
if mic_name == "dmicQBO_sv":
m = sr.Microphone(i)
print ("microphone is", m)
Query = ""
start = True
end = False
command = ""
counter = 0
repeat = False
prompt_txt = ""
response_txt = ""
Txt_start= (
"ask me a question, let's see if I can give you an interesting answer!"
)
Txt_end = "all right bye"
Txt_end1 = "I hope I was helpful"
Txt_end2 = "call me when you need me!"
class listen():
def __init__(self):
"""Class constructor
It is the constructor of the class. It does:
- listen to messages
- reply to messages
"""
#with m as source:
#self.r.adjust_for_ambient_noise(source)
# creating take_commands() function which
# can take some audio, Recognize and return
# if there are not any errors
def control_commands(self):
global command, end
print ("command in control command is = ", command)
if command != "":
if "switch off" in command:
print ("shutdown command activated")
command = ""
end = True
#.....
if re.search(r'\s*thanks*', command):
print ("job completion request")
end = True
def take_commands(self):
global m, Query, command
# initializing speech_recognition
r = sr.Recognizer()
# opening physical microphone of computer
with m as source:
r.adjust_for_ambient_noise(source)
r.pause_threshold = 1
print('I listen...')
# storing audio/sound to audio variable
audio = r.listen(source)
try:
print("Vocal recognition")
# Recognizing audio using google api
command = r.recognize_google(audio, language="us_EN")
Query = r.recognize_google(audio, language="us_EN")
#Query = r.recognize_google(audio) solo inglese
command= command.lower()
Query = Query.lower()
print("This is what I figured out with command", command)
print("This is what I figured out with Query", Query)
except Exception as e:
print(e)
print("Try to repeat, I think I don't understand")
# returning none if there are errors
return "None"
# returning audio as text
#time.sleep(1)
return command
#---------------
def Speak(self):
global Txt
print ("spoken sentence", Txt)
spk_now = 'espeak -v mb-en1 -s 120 -p 90 -w /tmp/temp.wav' +' " '+ Txt + ' " '+ '&& aplay -r 8000 -D convertQBO /tmp/temp.wav'
subprocess.call(spk_now, shell=True)
#----------
def Response():
global response_txt
# Set the model and prompt
model_engine = "text-davinci-003"
# Set the maximum number of tokens to generate in the response
max_tokens = 1024
print ("this is the prompt text: ", prompt_txt)
# Generate a response
completion = ai.Completion.create(
engine=model_engine,
prompt=prompt_txt,
max_tokens=max_tokens,
temperature=0.5,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
# Print the response
print(completion.choices[0].text)
response_txt = (completion.choices[0].text)
return response_txt
#-----------------------
def Q_bo_CHAT():
global command
global Query
global end
global counter
global Txt, Txt_start, Txt_end1, Txt_end2
global prompt_txt
print("start conversation")
while True:
print("do i have to make a speech?")
print("or understand a command?", command)
Txt = (Txt_start)
listen.Speak(Txt)
command = listen.take_commands(m)
listen.control_commands(command)
print ("command = ", command)
print ("command check done", "end=", end)
if end == True:
print ("game over")
print ("shutdown command running")
Txt = Txt_end
command = ""
start = False
listen.Speak(Txt)
Txt = Txt_end1
listen.Speak(Txt)
Txt = Txt_end2
listen.Speak(Txt)
#os.system("shutdown -h now")
break
if Query!= "":
command = ""
#command = listen.take_commands(m)
prompt_txt = Query
Txt = "If I understand correctly, this is your question," + prompt_txt
print (Txt)
listen.Speak(Txt)
time.sleep(1)
# Query =""
Txt = "give me a moment, I'll go to the library to see"
listen.Speak(Txt)
time.sleep(1)
Txt = ""
if prompt_txt !="":
print ("function request to OPEN_AI")
Response()
Txt = "this is my answer, hope you like it!"
listen.Speak(Txt)
Txt = ""
time.sleep(1)
Txt = response_txt
listen.Speak (Txt)
Txt = ""
response = ""
Query = ""
prompt_txt = ""
elif Query != "":
Txt = "I think I understand," + Query
listen.Speak(Txt)
Query = ""
Txt = "but I don't know how I can do to fulfill your wish!"
listen.Speak(Txt)
Query = ""
Txt = "Do you want to ask me another question or I'll switch off?"
#------------------------
print ("P_language ", P_language)
listen.Speak(Txt)
Txt = ""
command =""
Query = ""
print ("final check")
else:
print ("wait for commands")
command = listen.take_commands(m)
listen.control_commands(command)
Query = ""
Txt = ""
command = ""
counter += 1
print (" in all other cases increment counter", counter)
if __name__=='__main__':
""" Main void.
Is the main void executed when started. It does:
- Start the node
- Create an object of the class
- Run the node
"""
Q_bo_CHAT()
Txt = ""
command = ""
Phrase = ""
Query = ""
response_txt =""
prompt_txt = ""
prompt= ""
#Response()