Use ReadOnlyMemory<byte> for binary data to eliminate UTF-16 transcoding (#1070)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com> Co-authored-by: Eric StJohn <ericstj@microsoft.com>
This commit is contained in:
parent
a3ce9e9606
commit
80b1ad21d7
1 changed files with 400 additions and 103 deletions
|
|
@ -7,6 +7,7 @@ using System.Diagnostics;
|
|||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
|
@ -391,7 +392,12 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
|
|||
|
||||
DataContent dc => new()
|
||||
{
|
||||
Contents = [new BlobResourceContents { Uri = request.Params!.Uri, MimeType = dc.MediaType, Blob = dc.Base64Data.ToString() }],
|
||||
Contents = [new BlobResourceContents
|
||||
{
|
||||
Uri = request.Params!.Uri,
|
||||
MimeType = dc.MediaType,
|
||||
Blob = EncodingUtilities.GetUtf8Bytes(dc.Base64Data.Span)
|
||||
}],
|
||||
},
|
||||
|
||||
string text => new()
|
||||
|
|
@ -420,7 +426,7 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
|
|||
{
|
||||
Uri = request.Params!.Uri,
|
||||
MimeType = dc.MediaType,
|
||||
Blob = dc.Base64Data.ToString()
|
||||
Blob = EncodingUtilities.GetUtf8Bytes(dc.Base64Data.Span)
|
||||
},
|
||||
|
||||
_ => throw new InvalidOperationException($"Unsupported AIContent type '{ac.GetType()}' returned from resource function."),
|
||||
|
|
|
|||
Loading…
Reference in a new issue