Educational Interaction Tool- AI
This document describes how to use the Educational Interaction Tool in SightLab. This can be connected to an interactive, intelligent AI agent powered by various large language models like GPT-4 and Claude Opus. You can customize the agent's personality, use speech recognition, and leverage high-quality text-to-speech models. You can also record your own annotations that work with those. Can be connected to a virtual avatar or just use a voice-over.
Tagged objects can show a 3D text annotation and trigger an audio explanation. If connected with the AI integration, users can ask follow up questions. Objects that are added to a 3D scene should automatically be able to be tagged for interactions and conversational information.
Requires installation of Vizard and SightLab
Can be found in ExampleScripts\Education_Application_AI
Key Features
Interact and converse with custom AI Large Language Models in real-time VR or XR simulations.
Choose from OpenAI models (including GPT-4, custom GPTs), Anthropic models (like Claude 3 Opus). Requires an API key.
Customize the agent's personality, contextual awareness, emotional state, interactions, and more. Save your creations as custom agents.
Use speech recognition to converse using your voice or text-based input.
Choose from high-quality voices from Open AI TTS or Eleven Labs (requires API)
Train the agent as it adapts using conversation history and interactions.
Works with all features of SightLab, including data collection and visualizations, transcript saving, and more.
Automatically tag objects in a scene to prompt questions and information
Instructions
Installation
Ensure you have the required libraries installed using the Vizard Package Manager. These include:
openai (for OpenAI GPT agents)
anthropic (for Anthropic Claude agent)
elevenlabs (for ElevenLabs text-to-speech)
SpeechRecognition
sounddevice (pyaudio for older versions of Sightlab)
python-vlc
numpy
Need to install vlc player (for Open AI TTS). Seems to need at least version 3.0.20
For elevenlabs you may need to install ffmpeg and mpv player (see below)
Note: Requires an active internet connection
If using Vizard 8 or higher, copy the contents of the "updated speech recognition files" to C:\Program Files\WorldViz\Vizard8\bin\lib\site-packages\speech_recognition overwriting the _init_ and audio.py files. You will need to also do this again if updating the SpeechRecognition library.
API Keys
Obtain API keys from OpenAI (if using Chat GPT), Anthropic (if using that model), and ElevenLabs (if using elevenlabs instead of OpenAI's TTS). See below for specific information on obtaining API keys.
Create a folder named "keys" in your SightLab root directory and place these text files inside:
key.txt: Contains your OpenAI API key.
elevenlabs_key.txt: Contains your ElevenLabs API key (if using elevenlabs)
ffmpeg_path.txt: Contains the path to the ffmpeg bin folder. On some setups this is not needed. ffmpeg download
Copy path where bin directory is and paste that into this text file
If using the Anthropic model, create an anthropic_key.txt file containing your Anthropic API key.
For Gemini can place a text file called gemini_key.txt
Configuration
Open the AI_Agent_Config_Education.py script (now in the confgis folder) and configure the following options. Add new config files if wanting to have multiple configurations (would then change the top line in the AI_Agent.py script where it's being imported)
AI_MODEL: Choose between 'CHAT_GPT' and 'CLAUDE'.
OPENAI_MODEL: Specify the OpenAI model name (e.g., "gpt-4").
ANTHROPIC_MODEL: Specify the Anthropic model name (e.g., "claude-3-opus-20240229")
MAX_TOKENS: The amount of tokens each exchange will use. Set to a higher number to increase number of responses (token limit for most models is 4096, gpt-4 has 8192)
USE_SPEECH_RECOGNITION: Toggle on or off using speech recognition vs. text based interactions
SPEECH_MODEL: Choose Open AI TTS or Eleven Labs
ELEVEN_LABS_VOICE: Choose Voice for Eleven Labs
OPEN_AI_VOICE: Choose Voice for Open AI TTS
USE_GUI: Choose if you want to use the SightLab GUI to select environments and options
chatgpt_prompt_file: Save prompts as text files in "prompts" folder. Reference which one to use here
USE_PASSTHROUGH: Choose if using Mixed Reality Passthrough (select 'empty.osgb' for environment)
ENVIRONMENT: Not necessary to set if using GUI. User your own or find ones in sightlab_resources/environments
AVATAR_MODEL: Add avatar model to use. Use your own or find some in sightlab_resources/avatar/full_body
BIOPAC_ON: Choose whether to connect with Biopac Acqknowledge to measure physiological responses
REGION_1_OBJECT = Name that will be displayed in 3D Text
REGION_1_NAME = Name of the object in the actual model (can find this in Inspector)
And other configurations as needed such as GUI options, max token size, history and more (refer to the script for details).
Running the Script
Run AI_Agent_Education.py to start
Interaction
Press either RH or LH grip or right mouse button to bring up highlighter, RH trigger or left click to select and object to prompt for information
Hold either the 'c' key or the RH grip button to start speaking, let go to stop and AI agent will respond. If INTERUPT_AI is True, you can press 'c' or RH grip to interrupt and speak again, or left click to select another object.
3D text will appear with either head position or eye gaze
Modifying Environment and Avatar(s)
Place environment model in resources/environments for default location, or reference the new path
Modify the config file to update the environment and avatar path, as well as avatar options
Open the SightLab VR GUI and select which objects in the scene you want to collect interactions on
Obtaining API Keys
To use certain features of the AI Agent, you'll need to obtain API keys from the following services:
OpenAI (for ChatGPT and Open AI Text to Speech):
Visit the OpenAI website (not the ChatGPT login page): https://openai.com/
Sign up for an account if you don't have one, or log in if you already do (you may also need to buy some credits, but don't need much for this (most likely would not surpass a few dollars a month))
Navigate to the API section of your account.
Click "Create a new secret key" and copy the key.
Paste the copied key into a text file named "key.txt" and place it in your root SightLab folder.
Eleven Labs (for ElevenLabs Text-to-Speech):
Log in to your ElevenLabs account: https://elevenlabs.io/
Click your profile icon in the top-right corner.
Click the eye icon next to the "API Key" field.
Copy your API key.
Paste the copied key into a text file named "elevenlabs_key.txt" and place it in your root SightLab folder.
Anthropic API:
Go to the Anthropic website (https://www.anthropic.com/) and click on the "Sign Up" button in the top right corner.
Fill out the sign-up form with your email address and other required information. You may need to provide details about your intended use case for the API.
After submitting the form, you should receive a confirmation email. Follow the instructions in the email to verify your account.
Once your account is verified, log in to the Anthropic website using your credentials.
Navigate to the API section of your account dashboard
Additional Information:
For prompts, add "" quotation marks around GPT prompt and use "I am... " for configuring agent. For Anthropic do not need quotes and can use "You are..."
For elevenlabs, refer to the ElevenLabs Python documentation for more details: https://github.com/elevenlabs.
Issues and Troubleshooting
There may be an error if you have your microphone set to your VR headset and the sound output device set to not be the headset
May see an error if are using the free version of elevenlabs and run out of the 10,000 character limit (paid accounts get larger quotas)
ffplay error with elevenlabs - may need to install ffmpeg and add it to the Vizard environment path https://www.gyan.dev/ffmpeg/builds/
mpv player error with elevenlabs- may need to install mpv and add it to the Vizard environment path https://mpv.io/installation/
Tips
To give your agent an understanding of the environment it is in, take a screenshot (can use the '/' key in SightLab, which is saved to utils/screenCaptures), then upload that to Chat GPT online and ask to generate a description, you can then put this in your text prompt to use.
To add an event for the button to hold for speaking, can modify your vizconnect (in utils/vizconnect_configs - see "settings.py" for which vizconnect files go with which hardware choice). Double click to open and go to Advanced- Events, from there either modify the Mappings for the existing "triggerDown" and "triggerUp", or create new ones if there are none. See here for more information.
You can connect "Assistants" through the openai API, but not custom GPTs.