Skip to content

Commit

Permalink
Rename GetResponseFromChatbot to GetResponseFromChatbotAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
OkGoDoIt committed Apr 2, 2023
1 parent 1265387 commit ebecfe7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 10 additions & 2 deletions OpenAI_API/Chat/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public OpenAI_API.Models.Model Model
}

/// <summary>
/// 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.
/// 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.
/// </summary>
public ChatResult MostResentAPIResult { get; private set; }

Expand Down Expand Up @@ -117,7 +117,7 @@ public void AppendMessage(ChatMessage message)
/// 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"/>.
/// </summary>
/// <returns>The string of the response from the chatbot API</returns>
public async Task<string> GetResponseFromChatbot()
public async Task<string> GetResponseFromChatbotAsync()
{
ChatRequest req = new ChatRequest(RequestParameters);
req.Messages = _Messages.ToList();
Expand All @@ -134,6 +134,14 @@ public async Task<string> GetResponseFromChatbot()
return null;
}

/// <summary>
/// OBSOLETE: GetResponseFromChatbot() has been renamed to <see cref="GetResponseFromChatbotAsync"/> to follow .NET naming guidelines. This alias will be removed in a future version.
/// </summary>
/// <returns>The string of the response from the chatbot API</returns>
[Obsolete("Conversation.GetResponseFromChatbot() has been renamed to GetResponseFromChatbotAsync to follow .NET naming guidelines. Please update any references to GetResponseFromChatbotAsync(). This alias will be removed in a future version.", false)]
public Task<string> GetResponseFromChatbot() => GetResponseFromChatbotAsync();


#endregion

#region Streaming
Expand Down
8 changes: 4 additions & 4 deletions OpenAI_Tests/ChatEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public void ChatBackAndForth(string model)
chat.AppendUserInput("Is this an animal? House");
chat.AppendExampleChatbotOutput("No");
chat.AppendUserInput("Is this an animal? Dog");
string res = chat.GetResponseFromChatbot().Result;
string res = chat.GetResponseFromChatbotAsync().Result;
Assert.NotNull(res);
Assert.IsNotEmpty(res);
Assert.AreEqual("Yes", res.Trim());
chat.AppendUserInput("Is this an animal? Chair");
res = chat.GetResponseFromChatbot().Result;
res = chat.GetResponseFromChatbotAsync().Result;
Assert.NotNull(res);
Assert.IsNotEmpty(res);
Assert.AreEqual("No", res.Trim());
Expand All @@ -164,12 +164,12 @@ public void ChatWithNames()
chat.AppendUserInputWithName("Cindy", "Is John here? Answer yes or no.");
chat.AppendExampleChatbotOutput("Yes");
chat.AppendUserInputWithName("Cindy", "Is Monica here? Answer yes or no.");
string res = chat.GetResponseFromChatbot().Result;
string res = chat.GetResponseFromChatbotAsync().Result;
Assert.NotNull(res);
Assert.IsNotEmpty(res);
Assert.That(res.ToLower().Contains("no"));
chat.AppendUserInputWithName("Cindy", "Is Edward here? Answer yes or no.");
res = chat.GetResponseFromChatbot().Result;
res = chat.GetResponseFromChatbotAsync().Result;
Assert.NotNull(res);
Assert.IsNotEmpty(res);
Assert.That(res.ToLower().Contains("yes"));
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Console.WriteLine(result);

Added support for GPT4, streaming conversations with ChatGPT, and supporting [`IHttpClientFactory`](#ihttpclientfactory).

Now also should work with the Azure OpenAI Service, although this is untested. See the [Azure](#azure) section for further details.
Should work with the Azure OpenAI Service. See the [Azure](#azure) section for further details.

Thank you [@babrekel](https://github.com/babrekel), [@JasonWei512](https://github.com/JasonWei512), [@GotMike](https://github.com/gotmike), [@megalon](https://github.com/megalon), [@stonelv](https://github.com/stonelv), [@ncface](https://github.com/ncface), [@KeithHenry](https://github.com/KeithHenry), [@gmilano](https://github.com/gmilano), [@metjuperry](https://github.com/metjuperry), [@pandapknaepel](https://github.com/pandapknaepel), and [@Alexei000](https://github.com/Alexei000) for your contributions!

Expand Down Expand Up @@ -101,13 +101,13 @@ chat.AppendExampleChatbotOutput("No");
// now let's ask it a question'
chat.AppendUserInput("Is this an animal? Dog");
// and get the response
string response = await chat.GetResponseFromChatbot();
string response = await chat.GetResponseFromChatbotAsync();
Console.WriteLine(response); // "Yes"
// and continue the conversation by asking another
chat.AppendUserInput("Is this an animal? Chair");
// and get another response
response = await chat.GetResponseFromChatbot();
response = await chat.GetResponseFromChatbotAsync();
Console.WriteLine(response); // "No"
// the entire chat history is available in chat.Messages
Expand Down

0 comments on commit ebecfe7

Please sign in to comment.