Generate Pictures from Azure Open AI in Business Central

Generate Pictures from Azure Open AI in Business Central

Everyone is talking about ChatGPT and I have also been working last weeks with Azure Open AI and the way to generate picture from a description.
When you want to use that you have to use the “DALL E” model of AI. And when I was exploring this model you haven’t got allot of documentation about it.

So in this post I will show you how you can integrate with Azure Open AI model DALL E with Business Central to create an Item picture based from the item description.

First of all you need access to Azure Open AI service. You can apply for it using below link:
What is Azure OpenAI Service? – Azure Cognitive Services | Microsoft Learn

When you have access, you have to generate a deployment of the type “DALL E” (this model is only available in US region when trying it out).

After you have done you can get your API endpoint and key in below print screen (when push on the action “View Code”:

To retrieve the image you have to do the following three API calls:

  1. Send a POST call with an description
  2. Send a GET call to get the result
  3. Download the picture
Send a POST Call with an description

First you have to Post a http call with the following structure to your endpoint:

{
   "caption": "create a waterpainting of the construction industry",
   "resolution": "1024x1024"
}

The caption is the description and the resolution is the resolution that the picture is.
When you receive a 202 status back your call is OK and in the header you get two options: “retry-after” and “operation-location”.
This retry-after is how long it will take when the picture is generated. The second header is where you get the information about that picture.

Send a GET Call to get the result

After you have set a wait time you can do the second call and get information where you can download the generated picture. When you receive the status code 200 you can find the header “result.contentUrl” where you can download the picture.

Download the picture

Then you can simply download the content of the picture and use it:

In this scenario I have used it for generate a picture based on the description:

When you click on picture it wil wait a couple of seconds and generate

The AL code of this small project you can find here:
Bertverbeek4PS/AzureOpenAI (github.com)

2 COMMENTS

Chat GPT

Great article! I found your insights on using Azure and Open AI to generate pictures in Business Central really fascinating. It’s amazing to see how technology has advanced and how we can leverage it for practical purposes in business settings. Keep up the great work! CGPTOnline

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.