Skip to content

Commit 729ca97

Browse files
committed
Update tests and readme due to removal of publishable API keys
1 parent 0f661e0 commit 729ca97

File tree

2 files changed

+29
-54
lines changed

2 files changed

+29
-54
lines changed

OpenAI_Tests/AuthTests.cs

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,28 @@ public class AuthTests
99
[SetUp]
1010
public void Setup()
1111
{
12-
File.WriteAllText(".openai", "OPENAI_KEY=pk-test12" + Environment.NewLine + "OPENAI_SECRET_KEY: sk-test34");
12+
File.WriteAllText(".openai", "OPENAI_KEY=pk-test12");
1313
Environment.SetEnvironmentVariable("OPENAI_KEY", "pk-test-env");
14-
Environment.SetEnvironmentVariable("OPENAI_SECRET_KEY", "sk-test-env");
14+
//Environment.SetEnvironmentVariable("OPENAI_SECRET_KEY", "sk-test-env");
1515
}
1616

1717
[Test]
1818
public void GetAuthFromEnv()
1919
{
2020
var auth = OpenAI_API.APIAuthentication.LoadFromEnv();
2121
Assert.IsNotNull(auth);
22-
Assert.IsNotNull(auth.APIKey);
23-
Assert.IsNotEmpty(auth.APIKey);
24-
Assert.AreEqual("pk-test-env", auth.APIKey);
25-
26-
Assert.IsNotNull(auth.Secretkey);
27-
Assert.IsNotEmpty(auth.Secretkey);
28-
Assert.AreEqual("sk-test-env", auth.Secretkey);
29-
22+
Assert.IsNotNull(auth.ApiKey);
23+
Assert.IsNotEmpty(auth.ApiKey);
24+
Assert.AreEqual("pk-test-env", auth.ApiKey);
3025
}
3126

3227
[Test]
3328
public void GetAuthFromFile()
3429
{
3530
var auth = OpenAI_API.APIAuthentication.LoadFromPath();
3631
Assert.IsNotNull(auth);
37-
Assert.IsNotNull(auth.APIKey);
38-
Assert.AreEqual("pk-test12", auth.APIKey);
39-
Assert.IsNotNull(auth.Secretkey);
40-
Assert.AreEqual("sk-test34", auth.Secretkey);
32+
Assert.IsNotNull(auth.ApiKey);
33+
Assert.AreEqual("pk-test12", auth.ApiKey);
4134
}
4235

4336

@@ -55,10 +48,8 @@ public void GetDefault()
5548
var auth = OpenAI_API.APIAuthentication.Default;
5649
var envAuth = OpenAI_API.APIAuthentication.LoadFromEnv();
5750
Assert.IsNotNull(auth);
58-
Assert.IsNotNull(auth.APIKey);
59-
Assert.AreEqual(envAuth.APIKey, auth.APIKey);
60-
Assert.IsNotNull(auth.Secretkey);
61-
Assert.AreEqual(envAuth.Secretkey, auth.Secretkey);
51+
Assert.IsNotNull(auth.ApiKey);
52+
Assert.AreEqual(envAuth.ApiKey, auth.ApiKey);
6253
}
6354

6455

@@ -67,57 +58,42 @@ public void GetDefault()
6758
public void testHelper()
6859
{
6960
OpenAI_API.APIAuthentication defaultAuth = OpenAI_API.APIAuthentication.Default;
70-
OpenAI_API.APIAuthentication manualAuth = new OpenAI_API.APIAuthentication("pk-testAA", "sk-testBB");
61+
OpenAI_API.APIAuthentication manualAuth = new OpenAI_API.APIAuthentication("pk-testAA");
7162
OpenAI_API.OpenAIAPI api = new OpenAI_API.OpenAIAPI();
7263
OpenAI_API.APIAuthentication shouldBeDefaultAuth = api.Auth;
7364
Assert.IsNotNull(shouldBeDefaultAuth);
74-
Assert.IsNotNull(shouldBeDefaultAuth.APIKey);
75-
Assert.AreEqual(defaultAuth.APIKey, shouldBeDefaultAuth.APIKey);
76-
Assert.IsNotNull(shouldBeDefaultAuth.Secretkey);
77-
Assert.AreEqual(defaultAuth.Secretkey, shouldBeDefaultAuth.Secretkey);
65+
Assert.IsNotNull(shouldBeDefaultAuth.ApiKey);
66+
Assert.AreEqual(defaultAuth.ApiKey, shouldBeDefaultAuth.ApiKey);
7867

79-
OpenAI_API.APIAuthentication.Default = new OpenAI_API.APIAuthentication("pk-testAA", "sk-testBB");
68+
OpenAI_API.APIAuthentication.Default = new OpenAI_API.APIAuthentication("pk-testAA");
8069
api = new OpenAI_API.OpenAIAPI();
8170
OpenAI_API.APIAuthentication shouldBeManualAuth = api.Auth;
8271
Assert.IsNotNull(shouldBeManualAuth);
83-
Assert.IsNotNull(shouldBeManualAuth.APIKey);
84-
Assert.AreEqual(manualAuth.APIKey, shouldBeManualAuth.APIKey);
85-
Assert.IsNotNull(shouldBeManualAuth.Secretkey);
86-
Assert.AreEqual(manualAuth.Secretkey, shouldBeManualAuth.Secretkey);
72+
Assert.IsNotNull(shouldBeManualAuth.ApiKey);
73+
Assert.AreEqual(manualAuth.ApiKey, shouldBeManualAuth.ApiKey);
8774
}
8875

8976
[Test]
9077
public void GetKey()
9178
{
92-
var auth = new OpenAI_API.APIAuthentication("pk-testAA", "sk-testBB");
93-
Assert.IsNotNull(auth.GetKey());
94-
Assert.AreEqual("sk-testBB", auth.GetKey());
95-
96-
auth = new OpenAI_API.APIAuthentication("pk-testAA", null);
97-
Assert.IsNotNull(auth.GetKey());
98-
Assert.AreEqual("pk-testAA", auth.GetKey());
79+
var auth = new OpenAI_API.APIAuthentication("pk-testAA");
80+
Assert.IsNotNull(auth.ApiKey);
81+
Assert.AreEqual("pk-testAA", auth.ApiKey);
9982
}
10083

10184
[Test]
10285
public void ParseKey()
10386
{
10487
var auth = new OpenAI_API.APIAuthentication("pk-testAA");
105-
Assert.IsNotNull(auth.APIKey);
106-
Assert.IsNull(auth.Secretkey);
107-
Assert.AreEqual("pk-testAA", auth.APIKey);
88+
Assert.IsNotNull(auth.ApiKey);
89+
Assert.AreEqual("pk-testAA", auth.ApiKey);
10890
auth = "pk-testCC";
109-
Assert.IsNotNull(auth.APIKey);
110-
Assert.IsNull(auth.Secretkey);
111-
Assert.AreEqual("pk-testCC", auth.APIKey);
91+
Assert.IsNotNull(auth.ApiKey);
92+
Assert.AreEqual("pk-testCC", auth.ApiKey);
11293

11394
auth = new OpenAI_API.APIAuthentication("sk-testBB");
114-
Assert.IsNotNull(auth.Secretkey);
115-
Assert.IsNull(auth.APIKey);
116-
Assert.AreEqual("sk-testBB", auth.Secretkey);
117-
auth = "sk-testDD";
118-
Assert.IsNotNull(auth.Secretkey);
119-
Assert.IsNull(auth.APIKey);
120-
Assert.AreEqual("sk-testDD", auth.Secretkey);
95+
Assert.IsNotNull(auth.ApiKey);
96+
Assert.AreEqual("sk-testBB", auth.ApiKey);
12197
}
12298

12399
}

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@ Install-Package OpenAI
3636
### Authentication
3737
There are 3 ways to provide your API keys, in order of precedence:
3838
1. Pass keys directly to `APIAuthentication(string key)` constructor
39-
2. Set environment vars for OPENAI_KEY and/or OPENAI_SECRET_KEY
39+
2. Set environment var for OPENAI_KEY
4040
3. Include a config file in the local directory or in your user directory named `.openai` and containing one or both lines:
4141
```shell
42-
OPENAI_KEY=pk-aaaabbbbbccccddddd
43-
OPENAI_SECRET_KEY=sk-aaaabbbbbccccddddd
42+
OPENAI_KEY=sk-aaaabbbbbccccddddd
4443
```
4544

4645
You use the `APIAuthentication` when you initialize the API as shown:
4746
```csharp
4847
// for example
49-
OpenAIAPI api = new OpenAIAPI("sk-mysecretkeyhere"); // shorthand
48+
OpenAIAPI api = new OpenAIAPI("sk-mykeyhere"); // shorthand
5049
// or
51-
OpenAIAPI api = new OpenAIAPI(new APIAuthentication("pk-publishkey","sk-secretkey")); // specify manually
50+
OpenAIAPI api = new OpenAIAPI(new APIAuthentication("sk-secretkey")); // create object manually
5251
// or
5352
OpenAIAPI api = new OpenAIAPI(APIAuthentication LoadFromEnv()); // use env vars
5453
// or
@@ -74,7 +73,7 @@ You can create your `CompletionRequest` ahead of time or use one of the helper o
7473
#### Streaming
7574
Streaming allows you to get results are they are generated, which can help your application feel more responsive, especially on slow models like Davinci.
7675

77-
Using the new C# 8.0 async interators:
76+
Using the new C# 8.0 async iterators:
7877
```csharp
7978
IAsyncEnumerable<CompletionResult> StreamCompletionEnumerableAsync(CompletionRequest request)
8079

0 commit comments

Comments
 (0)