This wrapper serves as an easy-to-use tool for those looking to explore ChatGPT applications in game development.
In its current state, this wrapper is not suitable for production use. If you ship a game with your API key inside, it has potential to get leaked. I will work on setting up a proxy server template that can be self-hosted or hosted on Cloudflare so you can protect your key, and the server will also be able to pipe your data into a database so you can save your conversations and load them in later. In the mean time, happy prototyping :-)
-
Either download the zip and extract it into an existing Unity project, or clone the repo into your project's Assets directory.
If you are using a version of Unity that does not support Unity's UI Toolkit, you can just delete the whole UI folder as it's not required.
Also you can import package using Unity Package Manager (Add package from Git URL - https://github.com/GraesonB/ChatGPT-Wrapper-For-Unity.git) or just add "com.graesonb.chat-gpt-wrapper-for-unity": "https://github.com/GraesonB/ChatGPT-Wrapper-For-Unity.git" to Packages/manifest.json -
Create an empty game object, and add the "ChatGPTConversation" script to it.
-
Add your API key (you can generate your own key on OpenAI's website), and set your parameters.
-
Use the UnityEvent below the parameters to subscribe something to ChatGPT's response (a function/method that takes a string as an argument).
-
Create a UnityStringEvent somewhere else in your project, and add ChatGPTConversation's method "SendToChatGPT" to the newly created event.
Congrats, now whenever your new UnityEvent is invoked, a request will be sent to ChatGPT's API, and whatever is subscribed to ChatGPT's response will be notified as soon as a response is received. Have fun!
Here's a screenshot of a demo I put together with a simple UI. The UI files are included in the repo, however, you'll have to setup the UnityEvents and plugin the UI elements yourself. If anyone is interested I can also upload the whole project file.
This repo gave me the idea to do this in Unity:
https://github.com/acheong08/ChatGPT