Skip to content

Commit e616d0c

Browse files
committed
Async suffix added so the intent is clear and there's no ambiguity.
1 parent 6661723 commit e616d0c

13 files changed

+41
-41
lines changed

OpenAI_API/APIAuthentication.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static APIAuthentication LoadFromPath(string directory = null, string fil
163163
/// Tests the api key against the OpenAI API, to ensure it is valid. This hits the models endpoint so should not be charged for usage.
164164
/// </summary>
165165
/// <returns><see langword="true"/> if the api key is valid, or <see langword="false"/> if empty or not accepted by the OpenAI API.</returns>
166-
public async Task<bool> ValidateAPIKey()
166+
public async Task<bool> ValidateAPIKeyAsync()
167167
{
168168
if (string.IsNullOrEmpty(ApiKey))
169169
return false;

OpenAI_API/Chat/ChatEndpoint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Conversation CreateConversation()
4747
/// <returns>Asynchronously returns the completion result. Look in its <see cref="ChatResult.Choices"/> property for the results.</returns>
4848
public async Task<ChatResult> CreateChatCompletionAsync(ChatRequest request)
4949
{
50-
return await HttpPost<ChatResult>(postData: request);
50+
return await HttpPostAsync<ChatResult>(postData: request);
5151
}
5252

5353
/// <summary>
@@ -167,7 +167,7 @@ public async Task StreamChatAsync(ChatRequest request, Action<ChatResult> result
167167
public IAsyncEnumerable<ChatResult> StreamChatEnumerableAsync(ChatRequest request)
168168
{
169169
request = new ChatRequest(request) { Stream = true };
170-
return HttpStreamingRequest<ChatResult>(Url, HttpMethod.Post, request);
170+
return HttpStreamingRequestAsync<ChatResult>(Url, HttpMethod.Post, request);
171171
}
172172

173173
/// <summary>

OpenAI_API/Chat/Conversation.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public OpenAI_API.Models.Model Model
4040
}
4141

4242
/// <summary>
43-
/// After calling <see cref="GetResponseFromChatbot"/>, this contains the full response object which can contain useful metadata like token usages, <see cref="ChatChoice.FinishReason"/>, etc. This is overwritten with every call to <see cref="GetResponseFromChatbot"/> and only contains the most recent result.
43+
/// After calling <see cref="GetResponseFromChatbotAsync"/>, this contains the full response object which can contain useful metadata like token usages, <see cref="ChatChoice.FinishReason"/>, etc. This is overwritten with every call to <see cref="GetResponseFromChatbotAsync"/> and only contains the most recent result.
4444
/// </summary>
4545
public ChatResult MostResentAPIResult { get; private set; }
4646

@@ -106,7 +106,7 @@ public void AppendMessage(ChatMessage message)
106106
/// Calls the API to get a response, which is appended to the current chat's <see cref="Messages"/> as an <see cref="ChatMessageRole.Assistant"/> <see cref="ChatMessage"/>.
107107
/// </summary>
108108
/// <returns>The string of the response from the chatbot API</returns>
109-
public async Task<string> GetResponseFromChatbot()
109+
public async Task<string> GetResponseFromChatbotAsync()
110110
{
111111
ChatRequest req = new ChatRequest(RequestParameters);
112112
req.Messages = _Messages.ToList();

OpenAI_API/Completions/CompletionEndpoint.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal CompletionEndpoint(OpenAIAPI api) : base(api) { }
3636
/// <returns>Asynchronously returns the completion result. Look in its <see cref="CompletionResult.Completions"/> property for the completions.</returns>
3737
public async Task<CompletionResult> CreateCompletionAsync(CompletionRequest request)
3838
{
39-
return await HttpPost<CompletionResult>(postData: request);
39+
return await HttpPostAsync<CompletionResult>(postData: request);
4040
}
4141

4242
/// <summary>
@@ -153,7 +153,7 @@ public async Task StreamCompletionAsync(CompletionRequest request, Action<Comple
153153
public IAsyncEnumerable<CompletionResult> StreamCompletionEnumerableAsync(CompletionRequest request)
154154
{
155155
request = new CompletionRequest(request) { Stream = true };
156-
return HttpStreamingRequest<CompletionResult>(Url, HttpMethod.Post, request);
156+
return HttpStreamingRequestAsync<CompletionResult>(Url, HttpMethod.Post, request);
157157
}
158158

159159
/// <summary>
@@ -211,7 +211,7 @@ public IAsyncEnumerable<CompletionResult> StreamCompletionEnumerableAsync(string
211211
/// </summary>
212212
/// <param name="request">The request to send to the API. This does not fall back to default values specified in <see cref="DefaultCompletionRequestArgs"/>.</param>
213213
/// <returns>A string of the prompt followed by the best completion</returns>
214-
public async Task<string> CreateAndFormatCompletion(CompletionRequest request)
214+
public async Task<string> CreateAndFormatCompletionAsync(CompletionRequest request)
215215
{
216216
string prompt = request.Prompt;
217217
var result = await CreateCompletionAsync(request);
@@ -223,7 +223,7 @@ public async Task<string> CreateAndFormatCompletion(CompletionRequest request)
223223
/// </summary>
224224
/// <param name="prompt">The prompt to complete</param>
225225
/// <returns>The best completion</returns>
226-
public async Task<string> GetCompletion(string prompt)
226+
public async Task<string> GetCompletionAsync(string prompt)
227227
{
228228
CompletionRequest request = new CompletionRequest(DefaultCompletionRequestArgs)
229229
{

OpenAI_API/Completions/ICompletionEndpoint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ IAsyncEnumerable<CompletionResult> StreamCompletionEnumerableAsync(string prompt
123123
/// </summary>
124124
/// <param name="request">The request to send to the API. This does not fall back to default values specified in <see cref="DefaultCompletionRequestArgs"/>.</param>
125125
/// <returns>A string of the prompt followed by the best completion</returns>
126-
Task<string> CreateAndFormatCompletion(CompletionRequest request);
126+
Task<string> CreateAndFormatCompletionAsync(CompletionRequest request);
127127

128128
/// <summary>
129129
/// Simply returns the best completion
130130
/// </summary>
131131
/// <param name="prompt">The prompt to complete</param>
132132
/// <returns>The best completion</returns>
133-
Task<string> GetCompletion(string prompt);
133+
Task<string> GetCompletionAsync(string prompt);
134134
}
135135
}

OpenAI_API/Embedding/EmbeddingEndpoint.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public async Task<EmbeddingResult> CreateEmbeddingAsync(string input)
4242
/// <returns>Asynchronously returns the embedding result. Look in its <see cref="Data.Embedding"/> property of <see cref="EmbeddingResult.Data"/> to find the vector of floating point numbers</returns>
4343
public async Task<EmbeddingResult> CreateEmbeddingAsync(EmbeddingRequest request)
4444
{
45-
return await HttpPost<EmbeddingResult>(postData: request);
45+
return await HttpPostAsync<EmbeddingResult>(postData: request);
4646
}
4747

4848
/// <summary>

OpenAI_API/EndpointBase.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected string GetErrorMessage(string resultAsString, HttpResponseMessage resp
101101
/// <param name="streaming">(optional) If true, streams the response. Otherwise waits for the entire response before returning.</param>
102102
/// <returns>The HttpResponseMessage of the response, which is confirmed to be successful.</returns>
103103
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned</exception>
104-
private async Task<HttpResponseMessage> HttpRequestRaw(string url = null, HttpMethod verb = null, object postData = null, bool streaming = false)
104+
private async Task<HttpResponseMessage> HttpRequestRawAsync(string url = null, HttpMethod verb = null, object postData = null, bool streaming = false)
105105
{
106106
if (string.IsNullOrEmpty(url))
107107
url = this.Url;
@@ -166,9 +166,9 @@ private async Task<HttpResponseMessage> HttpRequestRaw(string url = null, HttpMe
166166
/// <param name="url">(optional) If provided, overrides the url endpoint for this request. If omitted, then <see cref="Url"/> will be used.</param>
167167
/// <returns>The text string of the response, which is confirmed to be successful.</returns>
168168
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned</exception>
169-
internal async Task<string> HttpGetContent<T>(string url = null)
169+
internal async Task<string> HttpGetContentAsync<T>(string url = null)
170170
{
171-
var response = await HttpRequestRaw(url);
171+
var response = await HttpRequestRawAsync(url);
172172
return await response.Content.ReadAsStringAsync();
173173
}
174174

@@ -182,9 +182,9 @@ internal async Task<string> HttpGetContent<T>(string url = null)
182182
/// <param name="postData">(optional) A json-serializable object to include in the request body.</param>
183183
/// <returns>An awaitable Task with the parsed result of type <typeparamref name="T"/></returns>
184184
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned or if the result couldn't be parsed.</exception>
185-
private async Task<T> HttpRequest<T>(string url = null, HttpMethod verb = null, object postData = null) where T : ApiResultBase
185+
private async Task<T> HttpRequestAsync<T>(string url = null, HttpMethod verb = null, object postData = null) where T : ApiResultBase
186186
{
187-
var response = await HttpRequestRaw(url, verb, postData);
187+
var response = await HttpRequestRawAsync(url, verb, postData);
188188
string resultAsString = await response.Content.ReadAsStringAsync();
189189

190190
var res = JsonConvert.DeserializeObject<T>(resultAsString);
@@ -246,9 +246,9 @@ private async Task<T> StreamingHttpRequest<T>(string url = null, HttpMethod verb
246246
/// <param name="url">(optional) If provided, overrides the url endpoint for this request. If omitted, then <see cref="Url"/> will be used.</param>
247247
/// <returns>An awaitable Task with the parsed result of type <typeparamref name="T"/></returns>
248248
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned or if the result couldn't be parsed.</exception>
249-
internal async Task<T> HttpGet<T>(string url = null) where T : ApiResultBase
249+
internal async Task<T> HttpGetAsync<T>(string url = null) where T : ApiResultBase
250250
{
251-
return await HttpRequest<T>(url, HttpMethod.Get);
251+
return await HttpRequestAsync<T>(url, HttpMethod.Get);
252252
}
253253

254254
/// <summary>
@@ -259,9 +259,9 @@ internal async Task<T> HttpGet<T>(string url = null) where T : ApiResultBase
259259
/// <param name="postData">(optional) A json-serializable object to include in the request body.</param>
260260
/// <returns>An awaitable Task with the parsed result of type <typeparamref name="T"/></returns>
261261
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned or if the result couldn't be parsed.</exception>
262-
internal async Task<T> HttpPost<T>(string url = null, object postData = null) where T : ApiResultBase
262+
internal async Task<T> HttpPostAsync<T>(string url = null, object postData = null) where T : ApiResultBase
263263
{
264-
return await HttpRequest<T>(url, HttpMethod.Post, postData);
264+
return await HttpRequestAsync<T>(url, HttpMethod.Post, postData);
265265
}
266266

267267
/// <summary>
@@ -272,9 +272,9 @@ internal async Task<T> HttpPost<T>(string url = null, object postData = null) wh
272272
/// <param name="postData">(optional) A json-serializable object to include in the request body.</param>
273273
/// <returns>An awaitable Task with the parsed result of type <typeparamref name="T"/></returns>
274274
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned or if the result couldn't be parsed.</exception>
275-
internal async Task<T> HttpDelete<T>(string url = null, object postData = null) where T : ApiResultBase
275+
internal async Task<T> HttpDeleteAsync<T>(string url = null, object postData = null) where T : ApiResultBase
276276
{
277-
return await HttpRequest<T>(url, HttpMethod.Delete, postData);
277+
return await HttpRequestAsync<T>(url, HttpMethod.Delete, postData);
278278
}
279279

280280

@@ -286,9 +286,9 @@ internal async Task<T> HttpDelete<T>(string url = null, object postData = null)
286286
/// <param name="postData">(optional) A json-serializable object to include in the request body.</param>
287287
/// <returns>An awaitable Task with the parsed result of type <typeparamref name="T"/></returns>
288288
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned or if the result couldn't be parsed.</exception>
289-
internal async Task<T> HttpPut<T>(string url = null, object postData = null) where T : ApiResultBase
289+
internal async Task<T> HttpPutAsync<T>(string url = null, object postData = null) where T : ApiResultBase
290290
{
291-
return await HttpRequest<T>(url, HttpMethod.Put, postData);
291+
return await HttpRequestAsync<T>(url, HttpMethod.Put, postData);
292292
}
293293

294294

@@ -336,9 +336,9 @@ private async IAsyncEnumerable<string> HttpStreamingRequestRaw(string url = null
336336
/// <param name="postData">(optional) A json-serializable object to include in the request body.</param>
337337
/// <returns>The HttpResponseMessage of the response, which is confirmed to be successful.</returns>
338338
/// <exception cref="HttpRequestException">Throws an exception if a non-success HTTP response was returned</exception>
339-
protected async IAsyncEnumerable<T> HttpStreamingRequest<T>(string url = null, HttpMethod verb = null, object postData = null) where T : ApiResultBase
339+
protected async IAsyncEnumerable<T> HttpStreamingRequestAsync<T>(string url = null, HttpMethod verb = null, object postData = null) where T : ApiResultBase
340340
{
341-
var response = await HttpRequestRaw(url, verb, postData, true);
341+
var response = await HttpRequestRawAsync(url, verb, postData, true);
342342

343343
string organization = null;
344344
string requestId = null;

OpenAI_API/Files/FilesEndpoint.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal FilesEndpoint(OpenAIAPI api) : base(api) { }
2929
/// <exception cref="HttpRequestException"></exception>
3030
public async Task<List<File>> GetFilesAsync()
3131
{
32-
return (await HttpGet<FilesData>()).Data;
32+
return (await HttpGetAsync<FilesData>()).Data;
3333
}
3434

3535
/// <summary>
@@ -39,7 +39,7 @@ public async Task<List<File>> GetFilesAsync()
3939
/// <returns></returns>
4040
public async Task<File> GetFileAsync(string fileId)
4141
{
42-
return await HttpGet<File>($"{Url}/{fileId}");
42+
return await HttpGetAsync<File>($"{Url}/{fileId}");
4343
}
4444

4545

@@ -50,7 +50,7 @@ public async Task<File> GetFileAsync(string fileId)
5050
/// <returns></returns>
5151
public async Task<string> GetFileContentAsStringAsync(string fileId)
5252
{
53-
return await HttpGetContent<File>($"{Url}/{fileId}/content");
53+
return await HttpGetContentAsync<File>($"{Url}/{fileId}/content");
5454
}
5555

5656
/// <summary>
@@ -60,7 +60,7 @@ public async Task<string> GetFileContentAsStringAsync(string fileId)
6060
/// <returns></returns>
6161
public async Task<File> DeleteFileAsync(string fileId)
6262
{
63-
return await HttpDelete<File>($"{Url}/{fileId}");
63+
return await HttpDeleteAsync<File>($"{Url}/{fileId}");
6464
}
6565

6666

@@ -77,7 +77,7 @@ public async Task<File> UploadFileAsync(string filePath, string purpose = "fine-
7777
{ new ByteArrayContent(System.IO.File.ReadAllBytes(filePath)), "file", Path.GetFileName(filePath) }
7878
};
7979

80-
return await HttpPost<File>(Url, content);
80+
return await HttpPostAsync<File>(Url, content);
8181
}
8282

8383
/// <summary>

OpenAI_API/Images/ImageGenerationEndpoint.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public async Task<ImageResult> CreateImageAsync(string input)
4040
/// <returns>Asynchronously returns the image result. Look in its <see cref="Data.Url"/> </returns>
4141
public async Task<ImageResult> CreateImageAsync(ImageGenerationRequest request)
4242
{
43-
return await HttpPost<ImageResult>(postData: request);
43+
return await HttpPostAsync<ImageResult>(postData: request);
4444
}
4545
}
4646
}

OpenAI_API/Model/ModelsEndpoint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal ModelsEndpoint(OpenAIAPI api) : base(api) { }
2828
/// <returns>Asynchronously returns the <see cref="Model"/> with all available properties</returns>
2929
public async Task<Model> RetrieveModelDetailsAsync(string id)
3030
{
31-
string resultAsString = await HttpGetContent<JsonHelperRoot>($"{Url}/{id}");
31+
string resultAsString = await HttpGetContentAsync<JsonHelperRoot>($"{Url}/{id}");
3232
var model = JsonConvert.DeserializeObject<Model>(resultAsString);
3333
return model;
3434
}
@@ -39,7 +39,7 @@ public async Task<Model> RetrieveModelDetailsAsync(string id)
3939
/// <returns>Asynchronously returns the list of all <see cref="Model"/>s</returns>
4040
public async Task<List<Model>> GetModelsAsync()
4141
{
42-
return (await HttpGet<JsonHelperRoot>()).data;
42+
return (await HttpGetAsync<JsonHelperRoot>()).data;
4343
}
4444

4545
/// <summary>

OpenAI_API/Moderation/ModerationEndpoint.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<ModerationResult> CallModerationAsync(string input)
4545
/// <returns>Asynchronously returns the classification result</returns>
4646
public async Task<ModerationResult> CallModerationAsync(ModerationRequest request)
4747
{
48-
return await HttpPost<ModerationResult>(postData: request);
48+
return await HttpPostAsync<ModerationResult>(postData: request);
4949
}
5050
}
5151
}

OpenAI_Tests/AuthTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ public void ParseKey()
110110
public async Task TestBadKey()
111111
{
112112
var auth = new OpenAI_API.APIAuthentication("pk-testAA");
113-
Assert.IsFalse(await auth.ValidateAPIKey());
113+
Assert.IsFalse(await auth.ValidateAPIKeyAsync());
114114

115115
auth = new OpenAI_API.APIAuthentication(null);
116-
Assert.IsFalse(await auth.ValidateAPIKey());
116+
Assert.IsFalse(await auth.ValidateAPIKeyAsync());
117117
}
118118

119119
[Test]
120120
public async Task TestValidateGoodKey()
121121
{
122122
var auth = new OpenAI_API.APIAuthentication(Environment.GetEnvironmentVariable("TEST_OPENAI_SECRET_KEY"));
123-
Assert.IsTrue(await auth.ValidateAPIKey());
123+
Assert.IsTrue(await auth.ValidateAPIKeyAsync());
124124
}
125125

126126
}

OpenAI_Tests/ChatEndpointTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ public void ChatBackAndForth()
9797
chat.AppendUserInput("Is this an animal? House");
9898
chat.AppendExampleChatbotOutput("No");
9999
chat.AppendUserInput("Is this an animal? Dog");
100-
string res = chat.GetResponseFromChatbot().Result;
100+
string res = chat.GetResponseFromChatbotAsync().Result;
101101
Assert.NotNull(res);
102102
Assert.IsNotEmpty(res);
103103
Assert.AreEqual("Yes", res.Trim());
104104
chat.AppendUserInput("Is this an animal? Chair");
105-
res = chat.GetResponseFromChatbot().Result;
105+
res = chat.GetResponseFromChatbotAsync().Result;
106106
Assert.NotNull(res);
107107
Assert.IsNotEmpty(res);
108108
Assert.AreEqual("No", res.Trim());

0 commit comments

Comments
 (0)