openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
joseharriaga/ReorganizeExamples

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Chat/Example05_ChatWithVision.cs

31lines · modecode

1using NUnit.Framework;
2using OpenAI.Chat;
3using System;
4using System.Collections.Generic;
5using System.IO;
6
7namespace OpenAI.Examples;
8
9public partial class ChatExamples
10{
11 [Test]
12 public void Example05_ChatWithVision()
13 {
14 ChatClient client = new("gpt-4o", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
15
16 string imageFilePath = Path.Combine("Assets", "images_dog_and_cat.png");
17 using Stream imageStream = File.OpenRead(imageFilePath);
18 BinaryData imageBytes = BinaryData.FromStream(imageStream);
19
20 List<ChatMessage> messages =
21 [
22 new UserChatMessage(
23 ChatMessageContentPart.CreateTextPart("Please describe the following image."),
24 ChatMessageContentPart.CreateImagePart(imageBytes, "image/png")),
25 ];
26
27 ChatCompletion completion = client.CompleteChat(messages);
28
29 Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");
30 }
31}