File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,6 +56,12 @@ private async void SendRequest()
5656}
5757```
5858
59+ You can also pass your API key into OpenAIApi ctor when creating an instance of it but again, this is not recommended!
60+
61+ ``` csharp
62+ var openai = new OpenAIApi (" sk-Me8...6yi" );
63+ ```
64+
5965### Sample Projects
6066This package includes two sample scenes that you can import via the Package Manager:
6167
Original file line number Diff line number Diff line change @@ -20,19 +20,30 @@ public class Configuration
2020 }
2121 } ;
2222
23- public Configuration ( )
23+ public Configuration ( string apiKey = null , string organization = null )
2424 {
25- var userPath = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
26- var authPath = $ "{ userPath } /.openai/auth.json";
27-
28- if ( File . Exists ( authPath ) )
25+ if ( apiKey == null )
2926 {
30- var json = File . ReadAllText ( authPath ) ;
31- Auth = JsonConvert . DeserializeObject < Auth > ( json , jsonSerializerSettings ) ;
27+ var userPath = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
28+ var authPath = $ "{ userPath } /.openai/auth.json";
29+
30+ if ( File . Exists ( authPath ) )
31+ {
32+ var json = File . ReadAllText ( authPath ) ;
33+ Auth = JsonConvert . DeserializeObject < Auth > ( json , jsonSerializerSettings ) ;
34+ }
35+ else
36+ {
37+ Debug . LogError ( $ "auth.json does not exist. Please check https://github.com/srcnalt/OpenAI-Unity#saving-your-credentials") ;
38+ }
3239 }
3340 else
3441 {
35- Debug . LogError ( $ "auth.json does not exist. Please check https://github.com/srcnalt/OpenAI-Unity#saving-your-credentials") ;
42+ Auth = new Auth ( )
43+ {
44+ ApiKey = apiKey ,
45+ Organization = organization
46+ } ;
3647 }
3748 }
3849 }
Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ private Configuration Configuration
3232
3333 /// OpenAI API base path for requests.
3434 private const string BASE_PATH = "https://api.openai.com/v1" ;
35+
36+ public OpenAIApi ( string apiKey = null , string organization = null )
37+ {
38+ if ( apiKey != null )
39+ {
40+ configuration = new Configuration ( apiKey , organization ) ;
41+ }
42+ }
3543
3644 /// Used for serializing and deserializing PascalCase request object fields into snake_case format for JSON. Ignores null fields when creating JSON strings.
3745 private readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings ( )
Original file line number Diff line number Diff line change 11{
22 "name" : " com.srcnalt.openai-unity" ,
3- "version" : " 0.1.4 " ,
3+ "version" : " 0.1.5 " ,
44 "displayName" : " OpenAI Unity" ,
55 "description" : " An unofficial OpenAI Unity Package that aims to help you use OpenAI API directly in Unity Game engine." ,
66 "unity" : " 2020.3" ,
You can’t perform that action at this time.
0 commit comments