-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Document Intelligence Module #2834
Open
Groenbech96
wants to merge
9
commits into
main
Choose a base branch
from
private/magnushar/ADI
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+322
−68
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
60e78da
Add ADI
6e860fb
tags
838fba7
Minor corrections
b91bdb9
Fix unused label
d3ab47c
Merge branch 'private/magnushar/ADI' of https://github.com/microsoft/…
e351912
pack into json
b002636
Fix id
8b1a432
Update namespell
e0ea026
Can we decouple OpenAI and Copilot module
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ | |
"idRanges": [ | ||
{ | ||
"from": 7758, | ||
"to": 7778 | ||
"to": 7780 | ||
} | ||
], | ||
"target": "OnPrem", | ||
|
29 changes: 29 additions & 0 deletions
29
src/System Application/App/AI/src/DocumentIntelligence/ADIModelType.Enum.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||
// ------------------------------------------------------------------------------------------------ | ||||||||||||||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||||||||||||||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||||||||||||||
// ------------------------------------------------------------------------------------------------ | ||||||||||||||
namespace System.AI; | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// The supported model types for Azure OpenAI. | ||||||||||||||
/// </summary> | ||||||||||||||
enum 7779 "ADI Model Type" | ||||||||||||||
{ | ||||||||||||||
Access = Public; | ||||||||||||||
Extensible = false; | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Invoice model type. | ||||||||||||||
/// </summary> | ||||||||||||||
value(0; Invoice) | ||||||||||||||
{ | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// <summary> | ||||||||||||||
/// Recepit model type. | ||||||||||||||
/// </summary> | ||||||||||||||
value(1; Recepit) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
{ | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} |
49 changes: 49 additions & 0 deletions
49
src/System Application/App/AI/src/DocumentIntelligence/AzureDI.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
namespace System.Azure.DI; | ||
|
||
/// <summary> | ||
/// Azure Document Intelligence implementation. | ||
/// </summary> | ||
codeunit 7780 "Azure DI" | ||
{ | ||
Access = Public; | ||
InherentEntitlements = X; | ||
InherentPermissions = X; | ||
|
||
var | ||
AzureOpenAIImpl: Codeunit "Azure DI Impl."; | ||
|
||
|
||
/// <summary> | ||
/// Analyze the invoice. | ||
/// </summary> | ||
/// <param name="Base64Data">Data to analyze.</param> | ||
/// <returns>The analyzed result.</returns> | ||
[Scope('OnPrem')] | ||
procedure AnalyzeInvoice(Base64Data: Text): Text | ||
var | ||
CallerModuleInfo: ModuleInfo; | ||
begin | ||
NavApp.GetCallerModuleInfo(CallerModuleInfo); | ||
exit(AzureOpenAIImpl.AnalyzeInvoice(Base64Data, CallerModuleInfo)); | ||
end; | ||
|
||
/// <summary> | ||
/// Analyze the Receipt. | ||
/// </summary> | ||
/// <param name="Base64Data">Data to analyze.</param> | ||
/// <returns>The analyzed result.</returns> | ||
[Scope('OnPrem')] | ||
procedure AnalyzeReceipt(Base64Data: Text): Text | ||
var | ||
CallerModuleInfo: ModuleInfo; | ||
begin | ||
NavApp.GetCallerModuleInfo(CallerModuleInfo); | ||
exit(AzureOpenAIImpl.AnalyzeReceipt(Base64Data, CallerModuleInfo)); | ||
end; | ||
|
||
|
||
} |
135 changes: 135 additions & 0 deletions
135
src/System Application/App/AI/src/DocumentIntelligence/AzureDIImpl.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,135 @@ | ||||||
// ------------------------------------------------------------------------------------------------ | ||||||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||||||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||||||
// ------------------------------------------------------------------------------------------------ | ||||||
namespace System.Azure.DI; | ||||||
using System.AI; | ||||||
using System.Globalization; | ||||||
using System.Telemetry; | ||||||
using System; | ||||||
|
||||||
/// <summary> | ||||||
/// Azure Document Intelligence implementation. | ||||||
/// </summary> | ||||||
codeunit 7779 "Azure DI Impl." | ||||||
{ | ||||||
Access = Internal; | ||||||
InherentEntitlements = X; | ||||||
InherentPermissions = X; | ||||||
|
||||||
/// <summary> | ||||||
/// Analyze the invoice. | ||||||
/// </summary> | ||||||
/// <param name="Base64Data">Data to analyze.</param> | ||||||
/// <param name="CallerModuleInfo">The module info of the caller.</param> | ||||||
/// <returns>The analyzed result.</returns> | ||||||
[NonDebuggable] | ||||||
procedure AnalyzeInvoice(Base64Data: Text; CallerModuleInfo: ModuleInfo) Result: Text | ||||||
var | ||||||
CustomDimensions: Dictionary of [Text, Text]; | ||||||
begin | ||||||
AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo); | ||||||
|
||||||
if not SendRequest(Base64Data, Enum::"ADI Model Type"::Invoice, CallerModuleInfo, Result) then begin | ||||||
FeatureTelemetry.LogError('0000OLK', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeInvoiceFailureLbl, GetLastErrorText(), '', Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||||||
exit; | ||||||
end; | ||||||
|
||||||
FeatureTelemetry.LogUsage('0000OLM', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeInvoiceCompletedLbl, Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||||||
|
||||||
end; | ||||||
|
||||||
/// <summary> | ||||||
/// Analyze the receipt. | ||||||
/// </summary> | ||||||
/// <param name="Base64Data">Data to analyze.</param> | ||||||
/// <param name="CallerModuleInfo">The module info of the caller.</param> | ||||||
/// <returns>The analyzed result.</returns> | ||||||
[NonDebuggable] | ||||||
procedure AnalyzeReceipt(Base64Data: Text; CallerModuleInfo: ModuleInfo) Result: Text | ||||||
var | ||||||
CustomDimensions: Dictionary of [Text, Text]; | ||||||
begin | ||||||
AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo); | ||||||
|
||||||
if not SendRequest(Base64Data, Enum::"ADI Model Type"::Recepit, CallerModuleInfo, Result) then begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FeatureTelemetry.LogError('0000OLL', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeReceiptFailureLbl, GetLastErrorText(), '', Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||||||
exit; | ||||||
end; | ||||||
|
||||||
FeatureTelemetry.LogUsage('0000OLN', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeReceiptCompletedLbl, Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||||||
end; | ||||||
|
||||||
[TryFunction] | ||||||
[NonDebuggable] | ||||||
local procedure SendRequest(Base64Data: Text; ModelType: Enum "ADI Model Type"; CallerModuleInfo: ModuleInfo; var Result: Text) | ||||||
var | ||||||
ALCopilotFunctions: DotNet ALCopilotFunctions; | ||||||
Jose-agg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
ALCopilotCapability: DotNet ALCopilotCapability; | ||||||
ALCopilotResponse: DotNet ALCopilotOperationResponse; | ||||||
ErrorMsg: Text; | ||||||
begin | ||||||
ClearLastError(); | ||||||
ALCopilotCapability := ALCopilotCapability.ALCopilotCapability(CallerModuleInfo.Publisher(), CallerModuleInfo.Id(), Format(CallerModuleInfo.AppVersion()), AzureDocumentIntelligenceCapabilityTok); | ||||||
case ModelType of | ||||||
Enum::"ADI Model Type"::Invoice: | ||||||
ALCopilotResponse := ALCopilotFunctions.GenerateInvoiceIntelligence(GenerateJson(Base64Data), ALCopilotCapability); | ||||||
Enum::"ADI Model Type"::Recepit: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ALCopilotResponse := ALCopilotFunctions.GenerateReceiptIntelligence(GenerateJson(Base64Data), ALCopilotCapability); | ||||||
end; | ||||||
ErrorMsg := ALCopilotResponse.ErrorText(); | ||||||
if ErrorMsg <> '' then | ||||||
Error(ErrorMsg); | ||||||
|
||||||
if not ALCopilotResponse.IsSuccess() then | ||||||
Error(GenerateRequestFailedErr); | ||||||
|
||||||
Result := ALCopilotResponse.Result(); | ||||||
end; | ||||||
|
||||||
|
||||||
local procedure AddTelemetryCustomDimensions(var CustomDimensions: Dictionary of [Text, Text]; CallerModuleInfo: ModuleInfo) | ||||||
var | ||||||
Language: Codeunit Language; | ||||||
SavedGlobalLanguageId: Integer; | ||||||
begin | ||||||
SavedGlobalLanguageId := GlobalLanguage(); | ||||||
GlobalLanguage(Language.GetDefaultApplicationLanguageId()); | ||||||
|
||||||
CustomDimensions.Add('Capability', AzureDocumentIntelligenceCapabilityTok); | ||||||
CustomDimensions.Add('AppId', CallerModuleInfo.Id); | ||||||
CustomDimensions.Add('Publisher', CallerModuleInfo.Publisher); | ||||||
CustomDimensions.Add('UserLanguage', Format(GlobalLanguage())); | ||||||
|
||||||
GlobalLanguage(SavedGlobalLanguageId); | ||||||
end; | ||||||
|
||||||
local procedure GenerateJson(Base64: Text): Text | ||||||
var | ||||||
JsonObject: JsonObject; | ||||||
InputsObject: JsonObject; | ||||||
InnerObject: JsonObject; | ||||||
JsonText: Text; | ||||||
begin | ||||||
// Create the inner object with the base64Encoded property | ||||||
InnerObject.Add('base64_encoded', Base64); | ||||||
// Create the inputs object and add the inner object to it | ||||||
InputsObject.Add('1', InnerObject); | ||||||
// Create the main JSON object and add the inputs object to it | ||||||
JsonObject.Add('inputs', InputsObject); | ||||||
// Convert the JSON object to text | ||||||
JsonObject.WriteTo(JsonText); | ||||||
// Return the JSON text | ||||||
exit(JsonText); | ||||||
end; | ||||||
|
||||||
var | ||||||
FeatureTelemetry: Codeunit "Feature Telemetry"; | ||||||
AzureDocumentIntelligenceCapabilityTok: Label 'ADI', Locked = true; | ||||||
TelemetryAnalyzeInvoiceFailureLbl: Label 'Analyze invoice failed.', Locked = true; | ||||||
TelemetryAnalyzeInvoiceCompletedLbl: Label 'Analyze invoice completed.', Locked = true; | ||||||
TelemetryAnalyzeReceiptFailureLbl: Label 'Analyze receipt failed.', Locked = true; | ||||||
TelemetryAnalyzeReceiptCompletedLbl: Label 'Analyze receipt completed.', Locked = true; | ||||||
GenerateRequestFailedErr: Label 'The request did not return a success status code.'; | ||||||
|
||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentional?