last ...
This commit is contained in:
@@ -191,6 +191,67 @@ namespace xAiModels.Extensions
|
|||||||
return result;
|
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>
|
/// <summary>
|
||||||
/// Check a Collection Contains Default Project for Specified Owner or not ...
|
/// Check a Collection Contains Default Project for Specified Owner or not ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace xAiModels.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Holds File Extraction Result ...
|
||||||
|
/// </summary>
|
||||||
|
public class XFileExtractionResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extracted String Content ...
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extracted Images for Vision Model ...
|
||||||
|
/// </summary>
|
||||||
|
public IList<XExtractedImage> Images { get; set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extracted Content from Audio File ...
|
||||||
|
/// </summary>
|
||||||
|
public string AudioTranscript { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main File Name ...
|
||||||
|
/// </summary>
|
||||||
|
public string FileName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main File MIME Type ...
|
||||||
|
/// </summary>
|
||||||
|
public string MimeType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specified Fallback done using Images or not ...
|
||||||
|
/// </summary>
|
||||||
|
public bool UsedImageFallback { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error Message ...
|
||||||
|
/// </summary>
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extracted Image ...
|
||||||
|
/// </summary>
|
||||||
|
public class XExtractedImage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Content as Byte ...
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Bytes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MIME Type of Image ...
|
||||||
|
/// </summary>
|
||||||
|
public string MimeType { get; set; } = "image/png";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// for PDF Files ...
|
||||||
|
/// </summary>
|
||||||
|
public int? PageNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Describe Image ...
|
||||||
|
/// </summary>
|
||||||
|
public string Description { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user