Skip to content

Commit fe1de92

Browse files
committed
Resolve merge conflicts
1 parent 8dc19dd commit fe1de92

File tree

4 files changed

+19
-89
lines changed

4 files changed

+19
-89
lines changed

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -466,19 +466,6 @@ outputItemDoneUpdate.Item is MessageResponseItem mri &&
466466
yield return CreateUpdate(GetImageGenerationResult(streamingImageGenUpdate, options));
467467
break;
468468

469-
case StreamingResponseImageGenerationCallInProgressUpdate imageGenInProgress:
470-
yield return CreateUpdate(new ImageGenerationToolCallContent
471-
{
472-
ImageId = imageGenInProgress.ItemId,
473-
RawRepresentation = imageGenInProgress,
474-
475-
});
476-
goto default;
477-
478-
case StreamingResponseImageGenerationCallPartialImageUpdate streamingImageGenUpdate:
479-
yield return CreateUpdate(GetImageGenerationResult(streamingImageGenUpdate, options));
480-
break;
481-
482469
default:
483470
yield return CreateUpdate();
484471
break;
@@ -1308,26 +1295,13 @@ private static ImageGenerationToolResultContent GetImageGenerationResult(Streami
13081295
var imageGenTool = options?.Tools.OfType<ImageGenerationTool>().FirstOrDefault();
13091296
var outputType = imageGenTool?.OutputFileFormat?.ToString() ?? "png";
13101297

1311-
var bytes = update.PartialImageBytes;
1312-
1313-
if (bytes is null || bytes.Length == 0)
1314-
{
1315-
// workaround https://github.com/openai/openai-dotnet/issues/809
1316-
if (update.Patch.TryGetJson("$.partial_image_b64"u8, out var jsonBytes))
1317-
{
1318-
Utf8JsonReader reader = new(jsonBytes.Span);
1319-
_ = reader.Read();
1320-
bytes = BinaryData.FromBytes(reader.GetBytesFromBase64());
1321-
}
1322-
}
1323-
13241298
return new ImageGenerationToolResultContent
13251299
{
13261300
ImageId = update.ItemId,
13271301
RawRepresentation = update,
13281302
Outputs = new List<AIContent>
13291303
{
1330-
new DataContent(bytes, $"image/{outputType}")
1304+
new DataContent(update.PartialImageBytes, $"image/{outputType}")
13311305
{
13321306
AdditionalProperties = new()
13331307
{

src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ public override async Task<IngestionDocument> ReadAsync(FileInfo source, string
4343
throw new FileNotFoundException("The specified file does not exist.", source.FullName);
4444
}
4545

46-
// Read file content as base64 data URI
46+
// Read file content and create DataContent
4747
#if NET
48-
byte[] fileBytes = await File.ReadAllBytesAsync(source.FullName, cancellationToken).ConfigureAwait(false);
48+
ReadOnlyMemory<byte> fileBytes = await File.ReadAllBytesAsync(source.FullName, cancellationToken).ConfigureAwait(false);
4949
#else
50-
byte[] fileBytes;
50+
ReadOnlyMemory<byte> fileBytes;
5151
using (FileStream fs = new(source.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 1, FileOptions.Asynchronous))
5252
{
53-
using MemoryStream ms = new();
53+
using MemoryStream ms = new((int)Math.Min(int.MaxValue, fs.Length));
5454
await fs.CopyToAsync(ms).ConfigureAwait(false);
55-
fileBytes = ms.ToArray();
55+
fileBytes = ms.GetBuffer().AsMemory(0, (int)ms.Length);
5656
}
5757
#endif
58-
string dataUri = CreateDataUri(fileBytes, mediaType);
58+
DataContent dataContent = new(
59+
fileBytes,
60+
string.IsNullOrEmpty(mediaType) ? "application/octet-stream" : mediaType!);
5961

60-
string markdown = await ConvertToMarkdownAsync(dataUri, cancellationToken).ConfigureAwait(false);
62+
string markdown = await ConvertToMarkdownAsync(dataContent, cancellationToken).ConfigureAwait(false);
6163

6264
return MarkdownParser.Parse(markdown, identifier);
6365
}
@@ -68,31 +70,23 @@ public override async Task<IngestionDocument> ReadAsync(Stream source, string id
6870
_ = Throw.IfNull(source);
6971
_ = Throw.IfNullOrEmpty(identifier);
7072

71-
// Read stream content as base64 data URI
72-
using MemoryStream ms = new();
73+
// Read stream content and create DataContent
74+
using MemoryStream ms = source.CanSeek ? new((int)Math.Min(int.MaxValue, source.Length)) : new();
7375
#if NET
7476
await source.CopyToAsync(ms, cancellationToken).ConfigureAwait(false);
7577
#else
7678
await source.CopyToAsync(ms).ConfigureAwait(false);
7779
#endif
78-
byte[] fileBytes = ms.ToArray();
79-
string dataUri = CreateDataUri(fileBytes, mediaType);
80+
DataContent dataContent = new(
81+
ms.GetBuffer().AsMemory(0, (int)ms.Length),
82+
string.IsNullOrEmpty(mediaType) ? "application/octet-stream" : mediaType);
8083

81-
string markdown = await ConvertToMarkdownAsync(dataUri, cancellationToken).ConfigureAwait(false);
84+
string markdown = await ConvertToMarkdownAsync(dataContent, cancellationToken).ConfigureAwait(false);
8285

8386
return MarkdownParser.Parse(markdown, identifier);
8487
}
8588

86-
#pragma warning disable S3995 // URI return values should not be strings
87-
private static string CreateDataUri(byte[] fileBytes, string? mediaType)
88-
#pragma warning restore S3995 // URI return values should not be strings
89-
{
90-
string base64Content = Convert.ToBase64String(fileBytes);
91-
string mimeType = string.IsNullOrEmpty(mediaType) ? "application/octet-stream" : mediaType!;
92-
return $"data:{mimeType};base64,{base64Content}";
93-
}
94-
95-
private async Task<string> ConvertToMarkdownAsync(string dataUri, CancellationToken cancellationToken)
89+
private async Task<string> ConvertToMarkdownAsync(DataContent dataContent, CancellationToken cancellationToken)
9690
{
9791
// Create HTTP client transport for MCP
9892
HttpClientTransport transport = new(new HttpClientTransportOptions
@@ -110,7 +104,7 @@ private async Task<string> ConvertToMarkdownAsync(string dataUri, CancellationTo
110104
// Build parameters for convert_to_markdown tool
111105
Dictionary<string, object?> parameters = new()
112106
{
113-
["uri"] = dataUri
107+
["uri"] = dataContent.Uri
114108
};
115109

116110
// Call the convert_to_markdown tool

src/Libraries/Microsoft.Extensions.DataIngestion/Utils/Batching.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6-
#if NET10_0_OR_GREATER
76
using System.Linq;
8-
#endif
97
using System.Runtime.CompilerServices;
108
using System.Threading;
119
using System.Threading.Tasks;
@@ -69,40 +67,4 @@ internal static async IAsyncEnumerable<IngestionChunk<string>> ProcessAsync<TMet
6967
}
7068
}
7169
}
72-
73-
#if !NET10_0_OR_GREATER
74-
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
75-
private static IAsyncEnumerable<TSource[]> Chunk<TSource>(this IAsyncEnumerable<TSource> source, int count)
76-
#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods
77-
{
78-
_ = Throw.IfNull(source);
79-
_ = Throw.IfLessThanOrEqual(count, 0);
80-
81-
return CoreAsync(source, count);
82-
83-
static async IAsyncEnumerable<TSource[]> CoreAsync(IAsyncEnumerable<TSource> source, int count,
84-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
85-
{
86-
var buffer = new TSource[count];
87-
int index = 0;
88-
89-
await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
90-
{
91-
buffer[index++] = item;
92-
93-
if (index == count)
94-
{
95-
index = 0;
96-
yield return buffer;
97-
}
98-
}
99-
100-
if (index > 0)
101-
{
102-
Array.Resize(ref buffer, index);
103-
yield return buffer;
104-
}
105-
}
106-
}
107-
#endif
10870
}

src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/ChatWithCustomData-CSharp.Web.csproj.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="${TemplatePackageVersion_MicrosoftMLTokenizers}" />
4141
<PackageReference Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="${TemplatePackageVersion_MicrosoftMLTokenizers}" />
4242
<!--#if (IsNET9) -->
43-
<PackageReference Include="System.Linq.Async" Version="${TemplatePackageVersion_SystemLinqAsync}" />
43+
<PackageReference Include="System.Linq.AsyncEnumerable" Version="${TemplatePackageVersion_SystemLinqAsyncEnumerable}" />
4444
<!--#endif -->
4545
<!--#if (IsAzureAISearch && IsAspire)
4646
<PackageReference Include="Aspire.Azure.Search.Documents" Version="${TemplatePackageVersion_Aspire}" />

0 commit comments

Comments
 (0)