Skip to content

Commit

Permalink
Update Obsolete Concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerBarreto committed Sep 24, 2024
1 parent de0c4f2 commit a783563
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,37 @@ public async Task SimpleTextToImageExampleAsync()
this.Output.WriteLine(generatedImages[0].Uri!.ToString());
}

[Fact(Skip = "Generating the Image can take too long and often break the test")]
public async Task AzureOpenAIDallEAsync()
[Fact]
public async Task OpenAIDallE3Async()
{
Console.WriteLine("========Azure OpenAI DALL-E 3 Text To Image ========");
Console.WriteLine("======== OpenAI DALL-E 3 Text To Image ========");

var builder = Kernel.CreateBuilder()
.AddAzureOpenAITextToImage( // Add your text to image service
deploymentName: TestConfiguration.AzureOpenAI.ImageDeploymentName,
endpoint: TestConfiguration.AzureOpenAI.ImageEndpoint,
apiKey: TestConfiguration.AzureOpenAI.ImageApiKey,
modelId: TestConfiguration.AzureOpenAI.ImageModelId,
apiVersion: "2024-02-15-preview") //DALL-E 3 is only supported in this version
.AddAzureOpenAIChatCompletion( // Add your chat completion service
deploymentName: TestConfiguration.AzureOpenAI.ChatDeploymentName,
endpoint: TestConfiguration.AzureOpenAI.Endpoint,
apiKey: TestConfiguration.AzureOpenAI.ApiKey);
.AddOpenAITextToImage( // Add your text to image service
modelId: "dall-e-3",
apiKey: TestConfiguration.OpenAI.ApiKey) //DALL-E 3 is only supported in this version
.AddOpenAIChatCompletion( // Add your chat completion service
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey);

builder.Services.ConfigureHttpClientDefaults(c =>
{
// Use a standard resiliency policy, augmented to retry 5 times
c.AddStandardResilienceHandler().Configure(o =>
{
o.Retry.MaxRetryAttempts = 5;
o.TotalRequestTimeout.Timeout = TimeSpan.FromSeconds(60);
o.TotalRequestTimeout.Timeout = TimeSpan.FromSeconds(120);
});
});

var kernel = builder.Build();

ITextToImageService dallE = kernel.GetRequiredService<ITextToImageService>();
var imageDescription = "A cute baby sea otter";
var image = await dallE.GenerateImageAsync(imageDescription, 1024, 1024);
var images = await dallE.GetImageContentsAsync(imageDescription, new OpenAITextToImageExecutionSettings { Size = (1024, 1024) });

Console.WriteLine(imageDescription);
Console.WriteLine("Image URL: " + image);
Console.WriteLine("Image URL: " + images[0].Uri!.ToString());

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, ubuntu-latest, Release, true, integration)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Debug)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

Check failure on line 130 in dotnet/samples/Concepts/TextToImage/OpenAI_TextToImageDalle3.cs

View workflow job for this annotation

GitHub Actions / dotnet-build-and-test (8.0, windows-latest, Release)

Remove redundant 'ToString' call (https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1097)

/* Output:
Expand All @@ -155,7 +151,8 @@ A cute baby sea otter

var reply = await chatGPT.GetChatMessageContentAsync(chatHistory);
chatHistory.Add(reply);
image = await dallE.GenerateImageAsync(reply.Content!, 1024, 1024);
images = await dallE.GetImageContentsAsync(reply.Content!, new OpenAITextToImageExecutionSettings { Size = (1024, 1024) });
var image = images[0].Uri!.ToString();
Console.WriteLine("Bot: " + image);
Console.WriteLine("Img description: " + reply);

Expand All @@ -165,7 +162,8 @@ A cute baby sea otter

reply = await chatGPT.GetChatMessageContentAsync(chatHistory);
chatHistory.Add(reply);
image = await dallE.GenerateImageAsync(reply.Content!, 1024, 1024);
images = await dallE.GetImageContentsAsync(reply.Content!, new OpenAITextToImageExecutionSettings { Size = (1024, 1024) });
image = images[0].Uri!.ToString();
Console.WriteLine("Bot: " + image);
Console.WriteLine("Img description: " + reply);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ public async Task OpenAITextToImageDalle3GetImagesTestAsync()
// Assert
Assert.NotNull(result);
Assert.NotEmpty(result);
Assert.NotEmpty(result[0].Uri!.ToString());
Assert.NotEmpty(result[0].Uri!.ToString());
}
}

0 comments on commit a783563

Please sign in to comment.