This commit is contained in:
2026-10-02 22:12:26 +03:30
parent 755eafa7d2
commit 26df2c7ebc
2 changed files with 132 additions and 0 deletions
+61
View File
@@ -191,6 +191,67 @@ namespace xAiModels.Extensions
return result;
}
/// <summary>
/// Validate a File Extraction Result ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XFileExtractionResult source)
{
//
var result =
!source.IsNullOrDefault() &&
(
source.Images.HasChild() ||
!source.Text.IsNullOrEmpty() ||
!source.AudioTranscript.IsNullOrEmpty()
);
return result;
}
/// <summary>
/// Converts a File Extraction Result to AI Contents ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<AIContent> ToAIContents(this XFileExtractionResult source)
{
//
var result = new List<AIContent>();
//
if (source.IsValid())
{
//
// Main Text ...
if (!source.Text.IsNullOrEmpty())
{
result.Add(new TextContent(source.Text));
}
//
// Images ...
if (source.Images.HasChild())
{
//
foreach (var img in source.Images)
{
result.Add(new DataContent(img.Bytes, img.MimeType));
}
}
//
// Transcripted Audio ...
if (!source.AudioTranscript.IsNullOrEmpty())
{
result.Add(new TextContent($"[Audio Transcript]\n{source.AudioTranscript}"));
}
}
//
return result;
}
/// <summary>
/// Check a Collection Contains Default Project for Specified Owner or not ...
/// </summary>