Feb
5
2022
5
2022
Using OPEN AI GPT-3 API in Unity
An article by mgear
17 Comments
** 10.01.2023: New example project here, uses webrequest, doesn’t require any DLL files https://unitycoder.com/blog/2023/01/10/using-openai-api-with-webrequest-from-unity/ **
- Download OpenAI dll (netstandard2.0): https://www.nuget.org/packages/OpenAI/ (*click Download Package on right side)
- Download required (netstandard2.0) dll files:
- Unzip downloaded *.nupgk files (using 7zip, or rename them as *.zip) and copy dll files from unzipped package, lib/.. folder into Unity project, “Assets/Plugins/x64/” folder
- Signup for open ai API key: https://beta.openai.com/
- Use one of the methods for your api key: https://github.com/OkGoDoIt/OpenAI-API-dotnet#authentication
- My test script (note: reads api key from text file inside StreamingAssets/apikey.txt): https://gist.github.com/unitycoder/0bc4e0205bc24d17765e6df5c2a3fb64
Related Posts
17 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
@unitycoder_com
My TweetsSubscribe to Blog via Email
Tag Cloud
2d
3D
AI
algorithm
android
asset
build
color
custom
demo
editor
effect
error
fake
free
game
generator
greasemonkey
indie
javascript
light
line
ludumdare
mesh
paint
particles
physics
plugin
proto
prototype
script
sea
shader
shadow
sprite
terrain
texture
tutorial
ui
unity
vertex
visibility
water
waves
webgl
I’m kinda new here so please can you tell me how to do the following:
,,Download OpenAI dll (netstandard2.0): https://www.nuget.org/packages/OpenAI/”
where exactly to press and what to download
its the “Download package (27.75 KB)” on the right side
Yep, did it, but I’ve got a .nupkg type of file, but the icon of it is “empty paper (file)” and it won’t work in Unity
ah, use 7zip to unzip that package file, or rename as .zip, so can open in explorer. (i added those details to article now, thanks!)
I’ve already solved the problem, but still tnx!
I’ve found the solution. Instead of ““Download package (x.y KB)”” go for “Open in NuGet Package Explorer ” and download the file with the same name as the name that’s appearing below .NET icon on top left corner. Repeat this for all 4 documents.
but there are several files – each of them with the name below the .net icon – in every folder. So which one should I choose?
I followed the steps & downloaded ALL the dll files that exist in the folders into Unity, and there have been A LOT of errors…
thanks 🙂 just saw this conversation and couldn’t help but to join.
while we’re at it – another question:
is it possible to get DALL-E images using this method, too? It’s just another endpoint in the API after all.
Also: if I want to get full answers, similar to chat-gpt, and not just completions to sentences– how do I do that?
THANKS!! your guide is REALLY helpful. (and I hope I figure it out completely:) )
the errors I get, by the way, are:
Assembly ‘Library/ScriptAssemblies/Assembly-CSharp.dll’ will not be loaded due to errors:
Reference has errors ‘OpenAI_API’.
AND
Assembly ‘Assets/Plugins/x64/OpenAI_API.dll’ will not be loaded due to errors:
OpenAI_API references strong named Newtonsoft.Json Assembly references: 12.0.0.0 Found in project: 13.0.0.0.
Assembly Version Validation can be disabled in Player Settings “Assembly Version Validation”
no idea why they appear really…
I actually made it! the setup is fine!
(the confusion was that I downloaded dll files other than the netstandard 2.0 specified…)
Still curious if anybody managed to use it (or some other way) to produce DALL-E images.
But anyway– so thankful for that! thanks a lot!!
Hello Daniel!
I just can’t get it right. Could you, by any chance, send me x64 file you’ve managed to get at my email? dejanradoman00@gmail.com
It would be GREAT help.
I’ve finally got it!!
Turns out I;ve needed to optimize some things in Scene Options > Player.
Amen
Error calling OpenAi API to get completion. HTTP status code: TooManyRequests. Request body: {“prompt”:”o be, or not to be:”,”max_tokens”:1,”temperature”:0.0,”stream”:false}
Is this on their side? My api key has been never used, not even one prompt.
check in their playground, if it gives better error, for me it said quota exceed..
https://beta.openai.com/playground
I’m also preparing better example, using just webrequest, no need external DLL’s
Here is new example, doesn’t require any DLL files, uses simple webrequest:
https://unitycoder.com/blog/2023/01/10/using-openai-api-with-webrequest-from-unity/
Thanks! I ill try later and let you know. Question: whats the difference then between using the dll or doing a web request? Everything allowed for now in the api can be executed both ways?
webrequest, you need to manually set all the params and correct model name etc,
those libraries make it easier to call specific method or receive data etc.
theres better c# sdk here, but i think wont work in unity as is:
https://github.com/betalgo/openai