-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Magnus Hartvig Grønbech
committed
Jan 23, 2025
1 parent
ec3252b
commit 60e78da
Showing
4 changed files
with
194 additions
and
1 deletion.
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) | ||
{ | ||
} | ||
|
||
} |
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 9970 "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; | ||
|
||
|
||
} |
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// 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; | ||
|
||
/// <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('', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeInvoiceFailureLbl, GetLastErrorText(), '', Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||
exit; | ||
end; | ||
|
||
FeatureTelemetry.LogUsage('', 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 | ||
FeatureTelemetry.LogError('', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeInvoiceFailureLbl, GetLastErrorText(), '', Enum::"AL Telemetry Scope"::All, CustomDimensions); | ||
exit; | ||
end; | ||
|
||
FeatureTelemetry.LogUsage('', AzureDocumentIntelligenceCapabilityTok, TelemetryAnalyzeInvoiceCompletedLbl, 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; | ||
Check failure on line 66 in src/System Application/App/AI/src/DocumentIntelligence/AzureDIImpl.Codeunit.al
|
||
ALCopilotCapability: DotNet ALCopilotCapability; | ||
Check failure on line 67 in src/System Application/App/AI/src/DocumentIntelligence/AzureDIImpl.Codeunit.al
|
||
ALCopilotResponse: DotNet ALCopilotOperationResponse; | ||
Check failure on line 68 in src/System Application/App/AI/src/DocumentIntelligence/AzureDIImpl.Codeunit.al
|
||
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(Base64Data, ALCopilotCapability); | ||
Enum::"ADI Model Type"::Recepit: | ||
ALCopilotResponse := ALCopilotFunctions.GenerateReceiptIntelligence(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; | ||
|
||
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.'; | ||
|
||
} |