Skip to content

Instantly share code, notes, and snippets.

@vman
Last active September 22, 2024 08:55
Show Gist options
  • Select an option

  • Save vman/627f07413cf4d3997236bfb61a946e56 to your computer and use it in GitHub Desktop.

Select an option

Save vman/627f07413cf4d3997236bfb61a946e56 to your computer and use it in GitHub Desktop.
var chatClient = openAiClient.GetChatClient(deploymentName);
string dataURI = "data:image/jpeg;base64,<long-data-uri-of-image>";
//convert data uri to binary data
byte[] binaryData = Convert.FromBase64String(dataURI.Split(',')[1]);
List<ChatMessage> messages = [
new UserChatMessage(
ChatMessageContentPart.CreateImageMessageContentPart(BinaryData.FromBytes(binaryData), "image/jpeg",
ImageChatMessageContentPartDetail.High)
),
new UserChatMessage("What is in this image?")
];
ChatCompletion chatCompletion = chatClient.CompleteChat(messages);
Console.WriteLine($"[ASSISTANT]: {chatCompletion}");

[ASSISTANT]: The image depicts a dramatic scene of a dragon with red scales and glowing eyes emerging from the clouds. Sunlight beams illuminate the creature, highlighting its sharp features and wings. The setting gives a mystical and powerful atmosphere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment