Skip to content

Commit

Permalink
Refactor response handling and add ToString method
Browse files Browse the repository at this point in the history
Replaced `response.GetContent()` with `response` in `AskStreamAsync` method of `Application` class.
Added `ToString` method to `ChatGptResponse` class to return response content.
  • Loading branch information
marcominerva committed Nov 5, 2024
1 parent dc8ea46 commit c241d3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions samples/ChatGptStreamConsole/Application.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ChatGptNet;
using ChatGptNet.Extensions;

namespace ChatGptStreamConsole;

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions src/ChatGptNet/Models/ChatGptResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using ChatGptNet.Extensions;
using ChatGptNet.Models.Common;
using ChatGptNet.Models.Converters;

Expand Down Expand Up @@ -59,4 +60,11 @@ public class ChatGptResponse : Response
/// <seealso cref="ChatGptChoice"/>
/// <seealso cref="ChatGptChoice.IsFiltered"/>
public bool IsContentFiltered => Choices.FirstOrDefault()?.IsFiltered ?? false;

/// <summary>
/// Gets the content of the response.
/// </summary>
/// <returns>The content of the response.</returns>
public override string? ToString()
=> this.GetContent();
}

0 comments on commit c241d3e

Please sign in to comment.