Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,11 @@ internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<Chat
break;

case UriContent uriContent when uriContent.HasTopLevelMediaType("image"):
(parts ??= []).Add(ResponseContentPart.CreateInputImagePart(uriContent.Uri));
(parts ??= []).Add(ResponseContentPart.CreateInputImagePart(uriContent.Uri, GetImageDetail(item)));
break;

case DataContent dataContent when dataContent.HasTopLevelMediaType("image"):
(parts ??= []).Add(ResponseContentPart.CreateInputImagePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType));
(parts ??= []).Add(ResponseContentPart.CreateInputImagePart(BinaryData.FromBytes(dataContent.Data), dataContent.MediaType, GetImageDetail(item)));
break;

case DataContent dataContent when dataContent.MediaType.StartsWith("application/pdf", StringComparison.OrdinalIgnoreCase):
Expand Down Expand Up @@ -1385,6 +1385,21 @@ private static ImageGenerationToolResultContent GetImageGenerationResult(Streami
return null;
}

private static ResponseImageDetailLevel? GetImageDetail(AIContent content)
{
if (content.AdditionalProperties?.TryGetValue("detail", out object? value) is true)
{
return value switch
{
string detailString => new ResponseImageDetailLevel(detailString),
ResponseImageDetailLevel detail => detail,
_ => null
};
}

return null;
}

/// <summary>Provides an <see cref="AITool"/> wrapper for a <see cref="ResponseTool"/>.</summary>
internal sealed class ResponseToolAITool(ResponseTool tool) : AITool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4246,7 +4246,9 @@ public async Task UserMessageWithVariousContentTypes_ConvertsCorrectly()
"content":[
{"type":"input_text","text":"Check this image: "},
{"type":"input_image","image_url":"https://example.com/image.png"},
{"type":"input_image","image_url":"https://example.com/image.png","detail":"high"},
{"type":"input_image","image_url":"data:image/png;base64,iVBORw0KGgo="},
{"type":"input_image","image_url":"data:image/png;base64,iVBORw0KGgo=","detail":"low"},
{"type":"input_file","file_data":"data:application/pdf;base64,cGRmZGF0YQ==","filename":"doc.pdf"},
{"type":"input_file","file_id":"file-123"},
{"type":"refusal","refusal":"I cannot process this"}
Expand Down Expand Up @@ -4278,7 +4280,9 @@ public async Task UserMessageWithVariousContentTypes_ConvertsCorrectly()
new ChatMessage(ChatRole.User, [
new TextContent("Check this image: "),
new UriContent(new Uri("https://example.com/image.png"), "image/png"),
new UriContent(new Uri("https://example.com/image.png"), "image/png") { AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = "high" }},
new DataContent(imageData, "image/png"),
new DataContent(imageData, "image/png") { AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = ResponseImageDetailLevel.Low }},
new DataContent(pdfData, "application/pdf") { Name = "doc.pdf" },
new HostedFileContent("file-123"),
new ErrorContent("I cannot process this") { ErrorCode = "Refusal" }
Expand Down
Loading