Few examples based on my ChatGPT with Unity video series on YouTube which is now supporting ChatGPT API and ChatGPT Python Wrapper BUT highly experimental.
Support all my work by Subscribing to YouTube thank you !
Scenes | |
---|---|
ChatGPTLogger.unity: a simple scene showing you how to ask ChatGPT to generate code which creates primitive cubes | ChatGPTPlayerClones: loads a player armature from resources, clones players every 1/2 a second, gets the starter assets input component, and makes players move and jump |
Unity 2021.3.8f or greater
Roslyn C# - Runtime DLLs which you can get from the Resources folder. I'm also planning to add the Class Library project to GitHub which should allow you to generate these DLLs yourself.
Open any of the available scenes
Create an account in OpenAI
Get a new API Key and your API Organization
Update ChatGPTSettings file located under Assets/Settings/ChatGPT/
Each scene has a ChatGPTTester game object & script in the hierarchy, feel free to associate a new ChatGPTQuestion scriptable object as a reference as shown below:
Deprecated - the latest changes use ChatGPT API instead of a python wrapper, however you could still use this but the python service may need some refactoring as the incoming object changed**
ChatGPT is not officially available which means there're unofficial solutions which allow you to use code which gets ChatGPT answers from OpenAI by using browser automation tools. To do this do the following:
python -m venv chatgpt_env
cd chatgpt_env
.\Scripts\activate
pip install pyreadline3
pip install git+https://github.com/mmabrouk/chatgpt-wrapper
playwright install firefox
pip install flask
chatgpt install
Run our ChatGPT flask service which exposes an endpoint at /chatgpt/question/
python .\chatgpt_service.py
Test the ChatGPT flask service by doing a GET request at http://127.0.0.1:5000/chatgpt/status if you get the response below proceed to step 4:
{
"status": "ok"
}
Open the Unity project and scene located at Assets > Scenes > ChatGPTLogger.unity
Go to Assets > Settings > ChatGPTSettings.asset and point the API Url to your ChatGPT flask service URL:
Ask ChatGPT a question as shown by clicking on "ChatGPTTester" game object:
Hit Play In Unity