Files
AI-Studio/app/MindWork AI Studio/Provider/Fireworks/ResponseStreamLine.cs
T

47 lines
1.7 KiB
C#
Raw Normal View History

using AIStudio.Provider.OpenAI;
2024-07-25 15:29:44 +02:00
namespace AIStudio.Provider.Fireworks;
/// <summary>
/// Data model for a line in the response stream, for streaming completions.
/// </summary>
/// <param name="Id">The id of the response.</param>
/// <param name="Object">The object describing the response.</param>
/// <param name="Created">The timestamp of the response.</param>
/// <param name="Model">The model used for the response.</param>
/// <param name="Choices">The choices made by the AI.</param>
2025-01-04 14:11:32 +01:00
public readonly record struct ResponseStreamLine(string Id, string Object, uint Created, string Model, IList<Choice> Choices) : IResponseStreamLine
{
/// <inheritdoc />
public bool ContainsContent() => this != default && this.Choices.Count > 0;
/// <inheritdoc />
2025-08-31 14:27:35 +02:00
public ContentStreamChunk GetContent() => new(this.Choices[0].Delta.Content, []);
2025-09-03 10:08:04 +02:00
/// <summary>
/// What Fireworks says the request cost, on the one line which carries it.
/// </summary>
/// <remarks>
/// The same block the OpenAI chat completion API sends, because this is that wire format.
/// Not a positional parameter: the struct is built from JSON, and a further parameter would
/// only be a value nobody passes.
/// </remarks>
public ChatCompletionUsage? Usage { get; init; }
/// <inheritdoc />
public TokenUsage GetUsage() => this.Usage?.ToTokenUsage() ?? TokenUsage.UNKNOWN;
2025-09-03 10:08:04 +02:00
#region Implementation of IAnnotationStreamLine
//
// Currently, Fireworks does not provide source citations in their response stream.
//
/// <inheritdoc />
public bool ContainsSources() => false;
/// <inheritdoc />
public IList<ISource> GetSources() => [];
#endregion
2026-09-04 15:48:07 +02:00
}