Skip to content

Commit 82df6fb

Browse files
committed
Additional tests from @Alexei000 and cleanup of usings (Thanks Alex Dragan!)
1 parent f80e06c commit 82df6fb

18 files changed

+535
-166
lines changed

OpenAI_API/APIAuthentication.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Dynamic;
42
using System.IO;
5-
using System.Linq;
6-
using System.Runtime.CompilerServices;
7-
using System.Text;
83

94
namespace OpenAI_API
105
{

OpenAI_API/Completions/CompletionEndpoint.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
using Newtonsoft.Json;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
4-
using System.IO;
5-
using System.Linq;
63
using System.Net.Http;
7-
using System.Runtime.CompilerServices;
8-
using System.Security.Authentication;
9-
using System.Text;
104
using System.Threading.Tasks;
115

126
namespace OpenAI_API

OpenAI_API/Completions/CompletionRequest.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.ComponentModel;
5-
using System.Data.Common;
62
using System.Linq;
7-
using System.Runtime;
8-
using System.Text;
93

104
namespace OpenAI_API
115
{
@@ -18,7 +12,7 @@ public class CompletionRequest
1812
/// ID of the model to use. You can use <see cref="ModelsEndpoint.GetModelsAsync()"/> to see all of your available models, or use a standard model like <see cref="Model.DavinciText"/>.
1913
/// </summary>
2014
[JsonProperty("model")]
21-
public string Model { get; set; }
15+
public string Model { get; set; } = OpenAI_API.Model.DavinciText;
2216

2317
/// <summary>
2418
/// This is only used for serializing the request into JSON, do not use it directly.
@@ -171,7 +165,7 @@ public string StopSequence
171165
/// </summary>
172166
public CompletionRequest()
173167
{
174-
168+
this.Model = OpenAI_API.Model.DefaultModel;
175169
}
176170

177171
/// <summary>

OpenAI_API/Completions/CompletionResult.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Linq;
3-
using System;
42
using System.Collections.Generic;
5-
using System.Text;
6-
using System.Threading;
73

84
namespace OpenAI_API
95
{
@@ -82,7 +78,7 @@ public class Logprobs
8278
public List<string> Tokens { get; set; }
8379

8480
[JsonProperty("token_logprobs")]
85-
public List<double> TokenLogprobs { get; set; }
81+
public List<double?> TokenLogprobs { get; set; }
8682

8783
[JsonProperty("top_logprobs")]
8884
public IList<IDictionary<string, double>> TopLogprobs { get; set; }

OpenAI_API/EndpointBase.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Linq;
77
using System.Net.Http;
8-
using System.Runtime.Serialization;
98
using System.Security.Authentication;
109
using System.Text;
1110
using System.Threading.Tasks;
@@ -18,17 +17,17 @@ namespace OpenAI_API
1817
public abstract class EndpointBase
1918
{
2019
/// <summary>
21-
///
20+
/// The internal reference to the API, mostly used for authentication
2221
/// </summary>
23-
protected readonly OpenAIAPI Api;
22+
protected readonly OpenAIAPI _Api;
2423

2524
/// <summary>
2625
/// Constructor of the api endpoint base, to be called from the contructor of any devived classes. Rather than instantiating any endpoint yourself, access it through an instance of <see cref="OpenAIAPI"/>.
2726
/// </summary>
2827
/// <param name="api"></param>
2928
internal EndpointBase(OpenAIAPI api)
3029
{
31-
this.Api = api;
30+
this._Api = api;
3231
}
3332

3433
/// <summary>
@@ -43,7 +42,7 @@ protected string Url
4342
{
4443
get
4544
{
46-
return $"{Api.ApiUrlBase}{Endpoint}";
45+
return $"{_Api.ApiUrlBase}{Endpoint}";
4746
}
4847
}
4948

@@ -54,15 +53,15 @@ protected string Url
5453
/// <exception cref="AuthenticationException">Thrown if there is no valid authentication. Please refer to <see href="https://github.com/OkGoDoIt/OpenAI-API-dotnet#authentication"/> for details.</exception>
5554
protected HttpClient GetClient()
5655
{
57-
if (Api.Auth?.ApiKey is null)
56+
if (_Api.Auth?.ApiKey is null)
5857
{
5958
throw new AuthenticationException("You must provide API authentication. Please refer to https://github.com/OkGoDoIt/OpenAI-API-dotnet#authentication for details.");
6059
}
6160

6261
HttpClient client = new HttpClient();
63-
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Api.Auth.ApiKey);
62+
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _Api.Auth.ApiKey);
6463
client.DefaultRequestHeaders.Add("User-Agent", "okgodoit/dotnet_openai_api");
65-
if (!string.IsNullOrEmpty(Api.Auth.OpenAIOrganization)) client.DefaultRequestHeaders.Add("OpenAI-Organization", Api.Auth.OpenAIOrganization);
64+
if (!string.IsNullOrEmpty(_Api.Auth.OpenAIOrganization)) client.DefaultRequestHeaders.Add("OpenAI-Organization", _Api.Auth.OpenAIOrganization);
6665

6766
return client;
6867
}

OpenAI_API/Files/File.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace OpenAI_API.Files
94
{

OpenAI_API/Files/FilesEndpoint.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using Newtonsoft.Json;
2-
using System;
32
using System.Collections.Generic;
43
using System.IO;
5-
using System.Linq;
64
using System.Net.Http;
7-
using System.Reflection;
8-
using System.Text;
95
using System.Threading.Tasks;
106

117
namespace OpenAI_API.Files

OpenAI_API/Model/Model.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Net.Http;
5-
using System.Text;
62
using System.Threading.Tasks;
73

84
namespace OpenAI_API
@@ -60,6 +56,10 @@ public Model()
6056

6157
}
6258

59+
/// <summary>
60+
/// The default model to use in requests if no other model is specified.
61+
/// </summary>
62+
public static Model DefaultModel { get; set; } = DavinciText;
6363

6464

6565
/// <summary>

OpenAI_API/Model/ModelsEndpoint.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
using Newtonsoft.Json;
2-
using System;
32
using System.Collections.Generic;
4-
using System.IO;
5-
using System.Net.Http;
6-
using System.Runtime.CompilerServices;
7-
using System.Security.Authentication;
8-
using System.Text;
93
using System.Threading.Tasks;
104

115
namespace OpenAI_API
@@ -33,7 +27,7 @@ internal ModelsEndpoint(OpenAIAPI api) : base(api) { }
3327
/// <returns>Asynchronously returns the <see cref="Model"/> with all available properties</returns>
3428
public Task<Model> RetrieveModelDetailsAsync(string id)
3529
{
36-
return RetrieveModelDetailsAsync(id, Api?.Auth);
30+
return RetrieveModelDetailsAsync(id, _Api?.Auth);
3731
}
3832

3933
/// <summary>

OpenAI_API/OpenAIAPI.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using Newtonsoft.Json;
2-
using OpenAI_API.Files;
1+
using OpenAI_API.Files;
32
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Net.Http;
8-
using System.Text;
9-
using System.Threading.Tasks;
103

114
namespace OpenAI_API
125
{

0 commit comments

Comments
 (0)