Feb
5
2022

Using OPEN AI GPT-3 API in Unity

** 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/ **

short clip: testing open ai dll

17 Comments + Add Comment

  • 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

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.