MyChatGPT is a project that allows integration of OpenAI's ChatGPT into the Second Life virtual world. With this setup, you can communicate in Second Life via chat commands. The responses generated by ChatGPT are relayed back to the Second Life environment.
-
MyChatGPT.lsl
: This is a Second Life LSL script. It listens for chat commands starting with/chatgpt
and sends the message following the command to the Python server for processing. -
lslserver.py
: This Python server uses Flask to accept HTTP requests from the LSL script. It processes the requests using OpenAI's ChatGPT API to generate responses.
-
Ensure you have Python 3 installed. You can download it here.
-
Install the required Python packages:
pip install Flask openai python-dotenv langchain
-
Clone this repository to your local machine.
-
Set up an OpenAI account and obtain your API key.
-
Create a
.env
file in the project root directory and add your OpenAI API key like so:OPENAI_API_KEY=your_key_here OPENAI_ORGANIZATION=your_key_here
-
Create a
data.pkl
file in the root directory and runpickleload.py
to allow the server to interact with data.pkl -
Create a
conversations.db
file in the root directory - this will store user conversations -
Run the Python server:
python3 lslserver.py
-
Upload the
MyChatGPT.lsl
script to Second Life and attach it to an object. -
Replace the URL in
MyChatGPT.lsl
with your Python server's URL. -
Update the top of the lsl script your corresponding userId
Once you're in Second Life, type a message in the local chat near the object with the LSL script starting with /chatgpt
, followed by your question or statement. The ChatGPT-powered NPC will respond accordingly.
Responses will remind you how many user messages you've used in the conversation. Current limits are unknown, but it's reccomended to use '/chatgpt clear' to clear the conversation history.