File tree Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,12 @@ private async void SendRequest()
56
56
}
57
57
```
58
58
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
+
59
65
### Sample Projects
60
66
This package includes two sample scenes that you can import via the Package Manager:
61
67
Original file line number Diff line number Diff line change @@ -20,19 +20,30 @@ public class Configuration
20
20
}
21
21
} ;
22
22
23
- public Configuration ( )
23
+ public Configuration ( string apiKey = null , string organization = null )
24
24
{
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 )
29
26
{
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
+ }
32
39
}
33
40
else
34
41
{
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
+ } ;
36
47
}
37
48
}
38
49
}
Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ private Configuration Configuration
32
32
33
33
/// OpenAI API base path for requests.
34
34
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
+ }
35
43
36
44
/// Used for serializing and deserializing PascalCase request object fields into snake_case format for JSON. Ignores null fields when creating JSON strings.
37
45
private readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings ( )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " com.srcnalt.openai-unity" ,
3
- "version" : " 0.1.4 " ,
3
+ "version" : " 0.1.5 " ,
4
4
"displayName" : " OpenAI Unity" ,
5
5
"description" : " An unofficial OpenAI Unity Package that aims to help you use OpenAI API directly in Unity Game engine." ,
6
6
"unity" : " 2020.3" ,
You can’t perform that action at this time.
0 commit comments