{"id":5493,"date":"2022-02-05T23:49:27","date_gmt":"2022-02-05T21:49:27","guid":{"rendered":"https:\/\/unitycoder.com\/blog\/?p=5493"},"modified":"2023-01-10T22:20:25","modified_gmt":"2023-01-10T20:20:25","slug":"using-open-ai-gpt-3-api-in-unity","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2022\/02\/05\/using-open-ai-gpt-3-api-in-unity\/","title":{"rendered":"Using OPEN AI GPT-3 API in Unity"},"content":{"rendered":"\n<p>** 10.01.2023: New example project here, uses webrequest, doesn&#8217;t require any DLL files <a rel=\"noreferrer noopener\" href=\"https:\/\/unitycoder.com\/blog\/2023\/01\/10\/using-openai-api-with-webrequest-from-unity\/\" target=\"_blank\">https:\/\/unitycoder.com\/blog\/2023\/01\/10\/using-openai-api-with-webrequest-from-unity\/<\/a> **<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Download OpenAI dll (netstandard2.0): <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nuget.org\/packages\/OpenAI\/\" target=\"_blank\">https:\/\/www.nuget.org\/packages\/OpenAI\/<\/a> (*click Download Package on right side)<\/li><li>Download required (netstandard2.0) dll files:<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Bcl.AsyncInterfaces\/\" target=\"_blank\">https:\/\/www.nuget.org\/packages\/Microsoft.Bcl.AsyncInterfaces\/<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.nuget.org\/packages\/System.Threading.Tasks.Extensions\/\" target=\"_blank\">https:\/\/www.nuget.org\/packages\/System.Threading.Tasks.Extensions\/<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.nuget.org\/packages\/System.Runtime.CompilerServices.Unsafe\/\" target=\"_blank\">https:\/\/www.nuget.org\/packages\/System.Runtime.CompilerServices.Unsafe\/<\/a><\/li><\/ul><\/li><li>Unzip downloaded *.nupgk files (using 7zip, or rename them as *.zip) and copy dll files from unzipped package, lib\/.. folder into Unity project, &#8220;Assets\/Plugins\/x64\/&#8221; folder<\/li><li>Signup for open ai API key: <a rel=\"noreferrer noopener\" href=\"https:\/\/beta.openai.com\/\" target=\"_blank\">https:\/\/beta.openai.com\/<\/a><\/li><li>Use one of the methods for your api key: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/OkGoDoIt\/OpenAI-API-dotnet#authentication\" target=\"_blank\">https:\/\/github.com\/OkGoDoIt\/OpenAI-API-dotnet#authentication<\/a><\/li><li>My test script (note: reads api key from text file inside StreamingAssets\/apikey.txt): <a rel=\"noreferrer noopener\" href=\"https:\/\/gist.github.com\/unitycoder\/0bc4e0205bc24d17765e6df5c2a3fb64\" target=\"_blank\">https:\/\/gist.github.com\/unitycoder\/0bc4e0205bc24d17765e6df5c2a3fb64<\/a><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"835\" height=\"187\" data-attachment-id=\"5494\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2022\/02\/05\/using-open-ai-gpt-3-api-in-unity\/image-30\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?fit=835%2C187&amp;ssl=1\" data-orig-size=\"835,187\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?fit=835%2C187&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?resize=835%2C187&#038;ssl=1\" alt=\"\" class=\"wp-image-5494\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?w=835&amp;ssl=1 835w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?resize=768%2C172&amp;ssl=1 768w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/Suabq44rhzY?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span>\n<\/div><figcaption>short clip: testing open ai dll<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>** 10.01.2023: New example project here, uses webrequest, doesn&#8217;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: https:\/\/www.nuget.org\/packages\/Microsoft.Bcl.AsyncInterfaces\/ https:\/\/www.nuget.org\/packages\/System.Threading.Tasks.Extensions\/ https:\/\/www.nuget.org\/packages\/System.Runtime.CompilerServices.Unsafe\/ Unzip downloaded *.nupgk files (using 7zip, or rename them as *.zip) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5494,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[89,419,1233,1235,939,1232],"class_list":["post-5493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-ai","tag-artificial-intelligence","tag-deep-learning","tag-gpt-3","tag-machine-learning","tag-openai"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2022\/02\/image.png?fit=835%2C187&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1qB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=5493"}],"version-history":[{"count":4,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5493\/revisions"}],"predecessor-version":[{"id":5612,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5493\/revisions\/5612"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/5494"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=5493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=5493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=5493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}