openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

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 new UserChatMessage(
22 ChatMessageContentPart.CreateTextMessageContentPart("Please describe the following image."),
23 ChatMessageContentPart.CreateImageMessageContentPart(imageBytes, "image/png"))
24 ];
25
26 ChatCompletion chatCompletion = client.CompleteChat(messages);
27
28 Console.WriteLine($"[ASSISTANT]:");
29 Console.WriteLine($"{chatCompletion.Content[0].Text}");
30 }
31}