Skip to content

Commit

Permalink
Add field to table, to exclude from pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Hartvig Grønbech committed Feb 10, 2025
1 parent 5ca1c58 commit 1ce1417
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// ------------------------------------------------------------------------------------------------
namespace System.AI.DocumentIntelligence;

using System.Privacy;
using System.Telemetry;
using System;
using System.AI;
Expand Down Expand Up @@ -35,6 +34,11 @@ codeunit 7779 "Azure DI Impl."
CopilotCapabilityImpl.SetCopilotCapability(Capability, CallerModuleInfo, AzureAIServiceName);
end;

procedure RegisterCopilotCapability(CopilotCapability: Enum "Copilot Capability"; CopilotAvailability: Enum "Copilot Availability"; LearnMoreUrl: Text[2048]; CallerModuleInfo: ModuleInfo)
begin
CopilotCapabilityImpl.RegisterCapability(CopilotCapability, CopilotAvailability, Enum::"Azure AI Service Type"::"Azure Document Intelligence", LearnMoreUrl, CallerModuleInfo);
end;

/// <summary>
/// Analyze a single invoice.
/// </summary>
Expand All @@ -46,7 +50,8 @@ codeunit 7779 "Azure DI Impl."
CustomDimensions: Dictionary of [Text, Text];
begin
CopilotCapabilityImpl.CheckCapabilitySet();
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure Document Intelligence");
CopilotCapabilityImpl.IsCapabilityActive(CallerModuleInfo);
CopilotCapabilityImpl.CheckCapabilityServiceType(Enum::"Azure AI Service Type"::"Azure Document Intelligence");
CopilotCapabilityImpl.AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo);

if not SendRequest(Base64Data, Enum::"ADI Model Type"::Invoice, CallerModuleInfo, Result) then begin
Expand All @@ -69,7 +74,7 @@ codeunit 7779 "Azure DI Impl."
CustomDimensions: Dictionary of [Text, Text];
begin
CopilotCapabilityImpl.CheckCapabilitySet();
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure Document Intelligence");
CopilotCapabilityImpl.IsCapabilityActive(CallerModuleInfo);
CopilotCapabilityImpl.AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo);

if not SendRequest(Base64Data, Enum::"ADI Model Type"::Receipt, CallerModuleInfo, Result) then begin
Expand Down Expand Up @@ -131,15 +136,4 @@ codeunit 7779 "Azure DI Impl."
exit(AzureAiDocumentIntelligenceTxt);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Privacy Notice", OnRegisterPrivacyNotices, '', false, false)]
local procedure CreatePrivacyNoticeRegistrations(var TempPrivacyNotice: Record "Privacy Notice" temporary)
begin
TempPrivacyNotice.Init();
TempPrivacyNotice.ID := GetAzureAIDocumentIntelligenceCategory();
TempPrivacyNotice."Integration Service Name" := AzureAiDocumentIntelligenceTxt;
if not TempPrivacyNotice.Insert() then;
end;



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ codeunit 7780 "Azure Document Intelligence"
var
AzureDIImpl: Codeunit "Azure DI Impl.";


/// <summary>
/// Analyze the invoice.
/// </summary>
Expand Down Expand Up @@ -47,6 +46,19 @@ codeunit 7780 "Azure Document Intelligence"
exit(AzureDIImpl.AnalyzeReceipt(Base64Data, CallerModuleInfo));
end;

/// <summary>
/// Register a capability for Azure Document Intelligence.
/// </summary>
/// <param name="CopilotCapability">The capability.</param>
/// <param name="CopilotAvailability">The availability.</param>
/// <param name="LearnMoreUrl">The learn more url.</param>
procedure RegisterCopilotCapability(CopilotCapability: Enum "Copilot Capability"; CopilotAvailability: Enum "Copilot Availability"; LearnMoreUrl: Text[2048])
var
CallerModuleInfo: ModuleInfo;
begin
NavApp.GetCallerModuleInfo(CallerModuleInfo);
AzureDIImpl.RegisterCopilotCapability(CopilotCapability, CopilotAvailability, LearnMoreUrl, CallerModuleInfo);
end;

/// <summary>
/// Sets the copilot capability that the API is running for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ codeunit 7772 "Azure OpenAI Impl"

procedure IsEnabled(Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo): Boolean
begin
CopilotCapabilityImpl.IsCapabilityEnabled(Capability, CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure OpenAI");
CopilotCapabilityImpl.IsCapabilityEnabled(Capability, CallerModuleInfo);
end;

procedure IsEnabled(Capability: Enum "Copilot Capability"; Silent: Boolean; CallerModuleInfo: ModuleInfo): Boolean
begin
CopilotCapabilityImpl.IsCapabilityEnabled(Capability, Silent, CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure OpenAI");
CopilotCapabilityImpl.IsCapabilityEnabled(Capability, Silent, CallerModuleInfo);
end;

procedure SetCopilotCapability(Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo; AzureAIServiceName: Text)
Expand Down Expand Up @@ -163,7 +163,7 @@ codeunit 7772 "Azure OpenAI Impl"
GuiCheck(TextCompletionsAOAIAuthorization);

CopilotCapabilityImpl.CheckCapabilitySet();
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure OpenAI");
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo);
CheckAuthorizationEnabled(TextCompletionsAOAIAuthorization, CallerModuleInfo);

CopilotCapabilityImpl.AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo);
Expand Down Expand Up @@ -197,7 +197,7 @@ codeunit 7772 "Azure OpenAI Impl"
GuiCheck(EmbeddingsAOAIAuthorization);

CopilotCapabilityImpl.CheckCapabilitySet();
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure OpenAI");
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo);
CheckAuthorizationEnabled(EmbeddingsAOAIAuthorization, CallerModuleInfo);

Payload.Add('input', Input.Unwrap());
Expand Down Expand Up @@ -251,7 +251,7 @@ codeunit 7772 "Azure OpenAI Impl"
GuiCheck(ChatCompletionsAOAIAuthorization);

CopilotCapabilityImpl.CheckCapabilitySet();
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo, Enum::"Azure AI Service Type"::"Azure OpenAI");
CopilotCapabilityImpl.CheckEnabled(CallerModuleInfo);
CheckAuthorizationEnabled(ChatCompletionsAOAIAuthorization, CallerModuleInfo);
CopilotCapabilityImpl.AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ page 7775 "Copilot AI Capabilities"
CopilotSettings: Record "Copilot Settings";
begin
CopilotSettings.SetRange(Availability, Enum::"Copilot Availability"::"Early Preview");
CopilotSettings.SetRange("Service Type", Enum::"Azure AI Service Type"::"Azure OpenAI");
exit(not CopilotSettings.IsEmpty());
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ page 7770 "Copilot Cap. Early Preview"
Editable = false;
Extensible = false;
SourceTable = "Copilot Settings";
SourceTableView = where(Availability = const("Early Preview"));
SourceTableView = where(Availability = const("Early Preview"), "Service Type" = const("Azure AI Service Type"::"Azure OpenAI"));
Permissions = tabledata "Copilot Settings" = rm;
InherentEntitlements = X;
InherentPermissions = X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ page 7774 "Copilot Capabilities GA"
Editable = false;
Extensible = false;
SourceTable = "Copilot Settings";
SourceTableView = where(Availability = const("Generally Available"));
SourceTableView = where(Availability = const("Generally Available"), "Service Type" = const("Azure AI Service Type"::"Azure OpenAI"));
Permissions = tabledata "Copilot Settings" = rm;
InherentEntitlements = X;
InherentPermissions = X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ page 7773 "Copilot Capabilities Preview"
Editable = false;
Extensible = false;
SourceTable = "Copilot Settings";
SourceTableView = where(Availability = const(Preview));
SourceTableView = where(Availability = const(Preview), "Service Type" = const("Azure AI Service Type"::"Azure OpenAI"));
Permissions = tabledata "Copilot Settings" = rm;
InherentEntitlements = X;
InherentPermissions = X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using System.Environment;
using System.Environment.Configuration;
using System.Globalization;
using System.Privacy;
using System.AI.DocumentIntelligence;
using System.Security.User;
using System.Telemetry;

Expand Down Expand Up @@ -58,6 +57,11 @@ codeunit 7774 "Copilot Capability Impl"
end;

procedure RegisterCapability(CopilotCapability: Enum "Copilot Capability"; CopilotAvailability: Enum "Copilot Availability"; LearnMoreUrl: Text[2048]; CallerModuleInfo: ModuleInfo)
begin
RegisterCapability(CopilotCapability, CopilotAvailability, Enum::"Azure AI Service Type"::"Azure OpenAI", LearnMoreUrl, CallerModuleInfo);
end;

procedure RegisterCapability(CopilotCapability: Enum "Copilot Capability"; CopilotAvailability: Enum "Copilot Availability"; AzureAIServiceType: Enum "Azure AI Service Type"; LearnMoreUrl: Text[2048]; CallerModuleInfo: ModuleInfo)
var
CustomDimensions: Dictionary of [Text, Text];
begin
Expand All @@ -71,6 +75,7 @@ codeunit 7774 "Copilot Capability Impl"
CopilotSettings.Publisher := CopyStr(CallerModuleInfo.Publisher, 1, MaxStrLen(CopilotSettings.Publisher));
CopilotSettings.Availability := CopilotAvailability;
CopilotSettings."Learn More Url" := LearnMoreUrl;
CopilotSettings."Service Type" := AzureAIServiceType;
if CopilotSettings.Availability = Enum::"Copilot Availability"::"Early Preview" then
CopilotSettings.Status := Enum::"Copilot Status"::Inactive
else
Expand Down Expand Up @@ -165,6 +170,11 @@ codeunit 7774 "Copilot Capability Impl"
exit(not CopilotSettings.IsEmpty());
end;

procedure IsCapabilityActive(CallerModuleInfo: ModuleInfo): Boolean
begin
exit(IsCapabilityActive(CopilotSettings.Capability, CallerModuleInfo.Id()));
end;

procedure IsCapabilityActive(CopilotCapability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo): Boolean
begin
exit(IsCapabilityActive(CopilotCapability, CallerModuleInfo.Id()));
Expand Down Expand Up @@ -217,22 +227,28 @@ codeunit 7774 "Copilot Capability Impl"
Error(CopilotCapabilityNotSetErr);
end;

procedure CheckEnabled(CallerModuleInfo: ModuleInfo; ServiceType: Enum "Azure AI Service Type")
procedure CheckCapabilityServiceType(ServiceType: Enum "Azure AI Service Type")
begin
if CopilotSettings."Service Type" <> ServiceType then
Error(CopilotCapabilityNotSetErr);
end;

procedure CheckEnabled(CallerModuleInfo: ModuleInfo)
begin
if not IsCapabilityEnabled(CopilotSettings.Capability, true, CallerModuleInfo, ServiceType) then
if not IsCapabilityEnabled(CopilotSettings.Capability, true, CallerModuleInfo) then
Error(CopilotNotEnabledErr);
end;

procedure IsCapabilityEnabled(Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo; ServiceType: Enum "Azure AI Service Type"): Boolean
procedure IsCapabilityEnabled(Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo): Boolean
begin
exit(IsCapabilityEnabled(Capability, false, CallerModuleInfo, ServiceType));
exit(IsCapabilityEnabled(Capability, false, CallerModuleInfo));
end;

procedure IsCapabilityEnabled(Capability: Enum "Copilot Capability"; Silent: Boolean; CallerModuleInfo: ModuleInfo; ServiceType: Enum "Azure AI Service Type"): Boolean
procedure IsCapabilityEnabled(Capability: Enum "Copilot Capability"; Silent: Boolean; CallerModuleInfo: ModuleInfo): Boolean
var
CopilotNotAvailable: Page "Copilot Not Available";
begin
if not IsTenantAllowed(ServiceType) then begin
if not IsTenantAllowedToUseAOAI() then begin
if not Silent then
Error(CopilotDisabledForTenantErr); // Copilot capabilities cannot be run on this environment.

Expand All @@ -248,15 +264,14 @@ codeunit 7774 "Copilot Capability Impl"
exit(false);
end;

exit(CheckPrivacyNoticeState(Silent, Capability, ServiceType));
exit(CheckPrivacyNoticeState(Silent, Capability));
end;

[NonDebuggable]
local procedure IsTenantAllowed(ServiceType: Enum "Azure AI Service Type"): Boolean
local procedure IsTenantAllowedToUseAOAI(): Boolean
var
EnvironmentInformation: Codeunit "Environment Information";
AzureOpenAIImpl: Codeunit "Azure OpenAI Impl";
AzureDIImpl: Codeunit "Azure DI Impl.";
AzureKeyVault: Codeunit "Azure Key Vault";
AzureAdTenant: Codeunit "Azure AD Tenant";
ModuleInfo: ModuleInfo;
Expand All @@ -269,13 +284,7 @@ codeunit 7774 "Copilot Capability Impl"
if ModuleInfo.Publisher <> 'Microsoft' then
exit(true);

case ServiceType of
Enum::"Azure AI Service Type"::"Azure OpenAI":
TelemtryTok := AzureOpenAIImpl.GetAzureOpenAICategory();
Enum::"Azure AI Service Type"::"Azure Document Intelligence":
TelemtryTok := AzureDIImpl.GetAzureAIDocumentIntelligenceCategory()
end;

TelemtryTok := AzureOpenAIImpl.GetAzureOpenAICategory();
if (not AzureKeyVault.GetAzureKeyVaultSecret(EnabledKeyTok, BlockList)) or (BlockList.Trim() = '') then begin
FeatureTelemetry.LogError('0000KYC', TelemtryTok, TelemetryIsEnabledLbl, TelemetryUnableToCheckEnvironmentKVTxt);
exit(false);
Expand All @@ -289,21 +298,14 @@ codeunit 7774 "Copilot Capability Impl"
exit(true);
end;

local procedure CheckPrivacyNoticeState(Silent: Boolean; Capability: Enum "Copilot Capability"; ServiceType: Enum "Azure AI Service Type"): Boolean
local procedure CheckPrivacyNoticeState(Silent: Boolean; Capability: Enum "Copilot Capability"): Boolean
var
PrivacyNotice: Codeunit "Privacy Notice";
AzureOpenAIImpl: Codeunit "Azure OpenAI Impl";
AzureDIImpl: Codeunit "Azure DI Impl.";
CopilotNotAvailable: Page "Copilot Not Available";
PrivacyNoticeApprovalState: Enum "Privacy Notice Approval State";
begin
case ServiceType of
Enum::"Azure AI Service Type"::"Azure OpenAI":
PrivacyNoticeApprovalState := PrivacyNotice.GetPrivacyNoticeApprovalState(AzureOpenAIImpl.GetAzureOpenAICategory(), false);
Enum::"Azure AI Service Type"::"Azure Document Intelligence":
PrivacyNoticeApprovalState := PrivacyNotice.GetPrivacyNoticeApprovalState(AzureDIImpl.GetAzureAIDocumentIntelligenceCategory(), false);
end;

PrivacyNoticeApprovalState := PrivacyNotice.GetPrivacyNoticeApprovalState(AzureOpenAIImpl.GetAzureOpenAICategory(), false);
case PrivacyNoticeApprovalState of
Enum::"Privacy Notice Approval State"::Agreed:
exit(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ table 7775 "Copilot Settings"
{
DataClassification = SystemMetadata;
}
field(7; "Service Type"; Enum "Azure AI Service Type")
{
DataClassification = SystemMetadata;
}
}

keys
Expand Down

0 comments on commit 1ce1417

Please sign in to comment.