Business Central, Copilot and the new PromptDialog
Last week at Directions EMEA 2023 Microsoft introduced the new page type “PromptDialog”.
With this new page type you can create very easily a nice dialog page for the interaction with Copilot:
And I much say I really like the new page type!
The release notes you can find here:
Easily integrate generative AI with your AL solutions | Microsoft Learn
Note:
When created this blog the PrompDialog is only available in the insiderbuilds of Business Central.
Prepare for major updates with preview environments – Business Central | Microsoft Learn
Inside VS Code – PageType
You can just create a page with the PageType set to “PromptDialog”. This page doesn’t have to attache to a SourceTable. But if you include a SourceTable you have to put it on temporary because generated answers of Copilot need always a confirmation of the user.
With the preview property is set to true you can indicate that the feature is in preview and you get a nice label on the PromptDialog:
In the lay-out you have two different areas. The first is the Prompt and the second is the Content.
In the prompt you can let the user create the input of the request. This can be an multiline textbox. But you can also create a part where the user can select some lines (see below in my example).
In the area of the content you can put the response of the AI.
In the last part you can create some systemactions:
Systemactions are: Generate, OK (to confirm the message), Cancel or Regenerate.
Inside VS Code – Generation
When the PromptDialog is ready you need create the interaction with Azure Open AI. There are a couple of Codeunits that takes care of the integration so you don’t have to build it yourself like I did in my previous blog:
Generate Pictures from Azure Open AI in Business Central – Discover Microsoft Business Central (bertverbeek.nl)
First you need to set the authorization and inside that authorization you have set the model type. You can choose for: Embeddings, Text Completion and Chat Completions.
After that you can set the parameters with the codeunit “AOAI Chat Completion Params” like the maximum of tokens or Temperature.
As last you can set the systemprompt and the user prompt.
In my example a have added the following systemprompt (what the AI model has to do):
And the following user prompt:
After this you can send everything to Azure Open AI with the “GenerateChatCompletion”
In the Business Central Client
But how does it looks like for the end user? In this case I have created an example that you want to predict the payment date of an Sales Invoice.
So in the prompt you can choose the entries that are closed (last 10 entries) and you can choose the open entries:
When you push generate you get a nice dialog:
And after a while you get the answer:
If you do Confirm you take the values.
Disable AI capabilities
Each Copilot has to register itself:
In this way a system admin can block or active the capability in the “Copilot & AI capabilities” page inside Business Central:
Note:
When creating this feature I get sometimes an unknow error (error code is empty). But when I try the next morning everything works OK. So it looks like the API cannot handle that much requests.
The source of this example you can look up here:
Bertverbeek4PS/Copilot-PrompDialog (github.com)
2 COMMENTS