-
Notifications
You must be signed in to change notification settings - Fork 2
/
AzureMLServerlessMarkdownDocumentDataExtractor.cs
36 lines (31 loc) · 1.28 KB
/
AzureMLServerlessMarkdownDocumentDataExtractor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Globalization;
using System.Text;
using EvaluationTests.Shared.Markdown;
using EvaluationTests.Shared.Storage;
namespace EvaluationTests.Shared.Extraction.AzureML;
public class AzureMLServerlessMarkdownDocumentDataExtractor(
AzureMLServerlessClient client,
AzureMLServerlessChatCompletionOptions chatCompletionOptions,
IDocumentMarkdownConverter markdownConverter,
TestOutputStorage? outputStorage = null)
: AzureMLServerlessDocumentDataExtractor(client, chatCompletionOptions)
{
public override async Task<DataExtractionResult> FromDocumentBytesAsync(
byte[] documentBytes,
CancellationToken cancellationToken = default)
{
var result = new DataExtractionResult();
var markdownContent = await markdownConverter.FromByteArrayAsync(documentBytes, cancellationToken);
if (markdownContent == null)
{
return result;
}
if (outputStorage != null)
{
await outputStorage.SaveBytesAsync(markdownContent,
$"{DateTime.UtcNow.ToString("yy-MM-dd", CultureInfo.InvariantCulture)}.Markdown.md");
}
return await GetChatCompletionsAsync(
new AzureMLServerlessChatRequestMessage("user", Encoding.UTF8.GetString(markdownContent)));
}
}