Refactored chat completion data records

This commit is contained in:
Thorsten Sommer 2025-09-02 22:14:43 +02:00
parent 3288ddb66f
commit 9d31ce62c3
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 34 additions and 22 deletions

View File

@ -0,0 +1,13 @@
namespace AIStudio.Provider.OpenAI;
/// <summary>
/// Data model for a choice made by the AI.
/// </summary>
/// <param name="Index">The index of the choice.</param>
/// <param name="Delta">The delta text of the choice.</param>
public record ChatCompletionChoice(int Index, ChatCompletionDelta Delta)
{
public ChatCompletionChoice() : this(0, new (string.Empty))
{
}
}

View File

@ -0,0 +1,12 @@
namespace AIStudio.Provider.OpenAI;
/// <summary>
/// The delta text of a choice.
/// </summary>
/// <param name="Content">The content of the delta text.</param>
public record ChatCompletionDelta(string Content)
{
public ChatCompletionDelta() : this(string.Empty)
{
}
}

View File

@ -9,7 +9,7 @@ namespace AIStudio.Provider.OpenAI;
/// <param name="Model">The model used for the response.</param> /// <param name="Model">The model used for the response.</param>
/// <param name="SystemFingerprint">The system fingerprint; together with the seed, this allows you to reproduce the response.</param> /// <param name="SystemFingerprint">The system fingerprint; together with the seed, this allows you to reproduce the response.</param>
/// <param name="Choices">The choices made by the AI.</param> /// <param name="Choices">The choices made by the AI.</param>
public record ChatCompletionResponseStreamLine(string Id, string Object, uint Created, string Model, string SystemFingerprint, IList<Choice> Choices) : IResponseStreamLine public record ChatCompletionResponseStreamLine(string Id, string Object, uint Created, string Model, string SystemFingerprint, IList<ChatCompletionChoice> Choices) : IResponseStreamLine
{ {
public ChatCompletionResponseStreamLine() : this(string.Empty, string.Empty, 0, string.Empty, string.Empty, []) public ChatCompletionResponseStreamLine() : this(string.Empty, string.Empty, 0, string.Empty, string.Empty, [])
{ {
@ -20,27 +20,14 @@ public record ChatCompletionResponseStreamLine(string Id, string Object, uint Cr
/// <inheritdoc /> /// <inheritdoc />
public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []); public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []);
}
/// <summary> #region Implementation of IAnnotationStreamLine
/// Data model for a choice made by the AI.
/// </summary>
/// <param name="Index">The index of the choice.</param>
/// <param name="Delta">The delta text of the choice.</param>
public record Choice(int Index, Delta Delta)
{
public Choice() : this(0, new (string.Empty))
{
}
}
/// <summary> /// <inheritdoc />
/// The delta text of a choice. public bool ContainsSources() => false;
/// </summary>
/// <param name="Content">The content of the delta text.</param> /// <inheritdoc />
public record Delta(string Content) public IList<ISource> GetSources() => [];
{
public Delta() : this(string.Empty) #endregion
{
}
} }