AI-Studio/app/MindWork AI Studio/Provider/OpenAI/ResponsesAnnotationStreamLine.cs
Thorsten Sommer 38ec098430
Some checks are pending
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Improved the OpenAI provider (#548)
2025-09-03 10:08:04 +02:00

45 lines
1.9 KiB
C#

namespace AIStudio.Provider.OpenAI;
/// <summary>
/// Data structure for a line in the response stream of the Responses API, containing an annotation.
/// </summary>
/// <param name="Type">The type of the annotation.</param>
/// <param name="AnnotationIndex">The continuous index of the annotation in the response.</param>
/// <param name="Annotation">The annotation details.</param>
public sealed record ResponsesAnnotationStreamLine(string Type, int AnnotationIndex, Annotation Annotation) : IAnnotationStreamLine
{
#region Implementation of IAnnotationStreamLine
/// <inheritdoc />
public bool ContainsSources()
{
return this.Annotation is not AnnotatingUnknown;
}
/// <inheritdoc />
public IList<ISource> GetSources()
{
//
// Check for the unexpected annotation type of the chat completion API.
//
// This seems weird at first. But there are two possibilities why this could happen:
// - Anyone of the open source providers such as ollama, LM Studio, etc. could
// implement and use the chat completion API data structures for annotations in their
// Responses API endpoint.
//
// - Our custom JSON converter checks for all possible annotation data types. So,
// when the streamed data is valid for any annotation type, it will be deserialized
// into that type, even though we are calling the Responses API endpoint.
//
if (this.Annotation is ChatCompletionAnnotatingURL urlAnnotation)
return [new Source(urlAnnotation.UrlCitation.Title, urlAnnotation.UrlCitation.URL)];
// Check for the expected annotation type of the Responses API:
if (this.Annotation is ResponsesAnnotatingUrlCitationData urlCitationData)
return [new Source(urlCitationData.Title, urlCitationData.URL)];
return [];
}
#endregion
}