From c241d3e662acd164dedbe32cca0287161e96f91e Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Tue, 5 Nov 2024 11:07:23 +0100 Subject: [PATCH] Refactor response handling and add ToString method Replaced `response.GetContent()` with `response` in `AskStreamAsync` method of `Application` class. Added `ToString` method to `ChatGptResponse` class to return response content. --- samples/ChatGptStreamConsole/Application.cs | 3 +-- src/ChatGptNet/Models/ChatGptResponse.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/ChatGptStreamConsole/Application.cs b/samples/ChatGptStreamConsole/Application.cs index 413a6ce..f3cbad8 100644 --- a/samples/ChatGptStreamConsole/Application.cs +++ b/samples/ChatGptStreamConsole/Application.cs @@ -1,5 +1,4 @@ using ChatGptNet; -using ChatGptNet.Extensions; namespace ChatGptStreamConsole; @@ -44,7 +43,7 @@ public async Task ExecuteAsync() await foreach (var response in responseStream) { - Console.Write(response.GetContent()); + Console.Write(response); await Task.Delay(80); } diff --git a/src/ChatGptNet/Models/ChatGptResponse.cs b/src/ChatGptNet/Models/ChatGptResponse.cs index dc11a73..d11573f 100644 --- a/src/ChatGptNet/Models/ChatGptResponse.cs +++ b/src/ChatGptNet/Models/ChatGptResponse.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; +using ChatGptNet.Extensions; using ChatGptNet.Models.Common; using ChatGptNet.Models.Converters; @@ -59,4 +60,11 @@ public class ChatGptResponse : Response /// /// public bool IsContentFiltered => Choices.FirstOrDefault()?.IsFiltered ?? false; + + /// + /// Gets the content of the response. + /// + /// The content of the response. + public override string? ToString() + => this.GetContent(); } \ No newline at end of file