openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/sub-pr-1135

Branches

Tags

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

Clone

HTTPS

Download ZIP

examples/Images/Example01_SimpleImageGeneration.cs

37lines · modecode

1using NUnit.Framework;
2using OpenAI.Images;
3using System;
4using System.IO;
5
6namespace OpenAI.Examples;
7
8public partial class ImageExamples
9{
10 [Test]
11 public void Example01_SimpleImageGeneration()
12 {
13 ImageClient client = new("dall-e-3", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
14
15 string prompt = "The concept for a living room that blends Scandinavian simplicity with Japanese minimalism for"
16 + " a serene and cozy atmosphere. It's a space that invites relaxation and mindfulness, with natural light"
17 + " and fresh air. Using neutral tones, including colors like white, beige, gray, and black, that create a"
18 + " sense of harmony. Featuring sleek wood furniture with clean lines and subtle curves to add warmth and"
19 + " elegance. Plants and flowers in ceramic pots adding color and life to a space. They can serve as focal"
20 + " points, creating a connection with nature. Soft textiles and cushions in organic fabrics adding comfort"
21 + " and softness to a space. They can serve as accents, adding contrast and texture.";
22
23 ImageGenerationOptions options = new()
24 {
25 Quality = GeneratedImageQuality.High,
26 Size = GeneratedImageSize.W1792xH1024,
27 Style = GeneratedImageStyle.Vivid,
28 ResponseFormat = GeneratedImageFormat.Bytes
29 };
30
31 GeneratedImage image = client.GenerateImage(prompt, options);
32 BinaryData bytes = image.ImageBytes;
33
34 using FileStream stream = File.OpenWrite($"{Guid.NewGuid()}.png");
35 bytes.ToStream().CopyTo(stream);
36 }
37}
38