Skip to content
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

[Copilot] Remove allowlisting logic for toolkit #3020

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ codeunit 7767 "AOAI Authorization"
[NonDebuggable]
procedure IsConfigured(CallerModule: ModuleInfo): Boolean
var
AzureOpenAiImpl: Codeunit "Azure OpenAI Impl";
CurrentModule: ModuleInfo;
ALCopilotFunctions: DotNet ALCopilotFunctions;
begin
Expand All @@ -41,7 +40,7 @@ codeunit 7767 "AOAI Authorization"
Enum::"AOAI Resource Utilization"::"Self-Managed":
exit((Deployment <> '') and (Endpoint <> '') and (not ApiKey.IsEmpty()));
Enum::"AOAI Resource Utilization"::"Microsoft Managed":
exit((Deployment <> '') and (Endpoint <> '') and (not ApiKey.IsEmpty()) and (ManagedResourceDeployment <> '') and AzureOpenAiImpl.IsTenantAllowlistedForFirstPartyCopilotCalls());
exit((Deployment <> '') and (Endpoint <> '') and (not ApiKey.IsEmpty()) and (ManagedResourceDeployment <> ''));
end;

exit(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ codeunit 7769 "AOAI Deployments Impl"

var
Telemetry: Codeunit Telemetry;
UnableToGetDeploymentNameErr: Label 'Unable to get deployment name, if this is a third party capability you must specify your own deployment name. You may need to contact your partner.';
GPT4oLatestLbl: Label 'gpt-4o-latest', Locked = true;
GPT4oPreviewLbl: Label 'gpt-4o-preview', Locked = true;
GPT4oMiniLatestLbl: Label 'gpt-4o-mini-latest', Locked = true;
Expand All @@ -42,7 +41,7 @@ codeunit 7769 "AOAI Deployments Impl"
EnviromentInformation: Codeunit "Environment Information";
begin
if EnviromentInformation.IsSaaS() then
exit(GetDeploymentName(Turbo0301SaasLbl, CallerModuleInfo));
exit(GetDeploymentName(Turbo0301SaasLbl));

exit(Turbo0301Lbl);
end;
Expand All @@ -52,7 +51,7 @@ codeunit 7769 "AOAI Deployments Impl"
EnviromentInformation: Codeunit "Environment Information";
begin
if EnviromentInformation.IsSaaS() then
exit(GetDeploymentName(GPT40613SaasLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT40613SaasLbl));

exit(GPT40613Lbl);
end;
Expand All @@ -62,50 +61,50 @@ codeunit 7769 "AOAI Deployments Impl"
EnviromentInformation: Codeunit "Environment Information";
begin
if EnviromentInformation.IsSaaS() then
exit(GetDeploymentName(Turbo0613SaasLbl, CallerModuleInfo));
exit(GetDeploymentName(Turbo0613SaasLbl));

exit(Turbo031316kLbl);
end;

procedure GetGPT35TurboPreview(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT35TurboPreviewLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT35TurboPreviewLbl));
end;

procedure GetGPT35TurboLatest(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT35TurboLatestLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT35TurboLatestLbl));
end;

procedure GetGPT4Preview(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4PreviewLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4PreviewLbl));
end;

procedure GetGPT4Latest(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4LatestLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4LatestLbl));
end;
#endif

procedure GetGPT4oPreview(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4oPreviewLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4oPreviewLbl));
end;

procedure GetGPT4oLatest(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4oLatestLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4oLatestLbl));
end;

procedure GetGPT4oMiniPreview(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4oMiniPreviewLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4oMiniPreviewLbl));
end;

procedure GetGPT4oMiniLatest(CallerModuleInfo: ModuleInfo): Text
begin
exit(GetDeploymentName(GPT4oMiniLatestLbl, CallerModuleInfo));
exit(GetDeploymentName(GPT4oMiniLatestLbl));
end;

// Initializes dictionary of deprecated models
Expand Down Expand Up @@ -149,18 +148,14 @@ codeunit 7769 "AOAI Deployments Impl"
end;
end;

local procedure GetDeploymentName(DeploymentName: Text; CallerModuleInfo: ModuleInfo): Text
local procedure GetDeploymentName(DeploymentName: Text): Text
var
AzureOpenAiImpl: Codeunit "Azure OpenAI Impl";
CurrentModuleInfo: ModuleInfo;
begin
LogDeprecationTelemetry(DeploymentName);

NavApp.GetCurrentModuleInfo(CurrentModuleInfo);

if (CallerModuleInfo.Publisher <> CurrentModuleInfo.Publisher) and not AzureOpenAiImpl.IsTenantAllowlistedForFirstPartyCopilotCalls() then
Error(UnableToGetDeploymentNameErr);

exit(DeploymentName);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace System.AI;

using System;
using System.Azure.Identity;
using System.Azure.KeyVault;
using System.Environment;
using System.Privacy;
Expand Down Expand Up @@ -37,7 +36,6 @@ codeunit 7772 "Azure OpenAI Impl" implements "AI Service Name"
EmptyMetapromptErr: Label 'The metaprompt has not been set, please provide a metaprompt.';
MetapromptLoadingErr: Label 'Metaprompt not found.';
FunctionCallingFunctionNotFoundErr: Label 'Function call not found, %1.', Comment = '%1 is the name of the function';
AllowlistedTenantsAkvKeyTok: Label 'AOAI-Allow-1P-Auth', Locked = true;
TelemetryGenerateTextCompletionLbl: Label 'Text completion generated.', Locked = true;
TelemetryGenerateEmbeddingLbl: Label 'Embedding generated.', Locked = true;
TelemetryGenerateChatCompletionLbl: Label 'Chat Completion generated.', Locked = true;
Expand All @@ -47,8 +45,6 @@ codeunit 7772 "Azure OpenAI Impl" implements "AI Service Name"
TelemetryTokenCountLbl: Label 'Metaprompt token count: %1, Prompt token count: %2, Total token count: %3', Comment = '%1 is the number of tokens in the metaprompt, %2 is the number of tokens in the prompt, %3 is the total number of tokens', Locked = true;
TelemetryMetapromptRetrievalErr: Label 'Unable to retrieve metaprompt from Azure Key Vault.', Locked = true;
TelemetryFunctionCallingFailedErr: Label 'Function calling failed for function: %1', Comment = '%1 is the name of the function', Locked = true;
TelemetryEmptyTenantIdErr: Label 'Empty or malformed tenant ID.', Locked = true;
TelemetryTenantAllowlistedMsg: Label 'Current tenant allowlisted for first party auth.', Locked = true;
AzureOpenAiTxt: Label 'Azure OpenAI', Locked = true;

procedure IsEnabled(Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo): Boolean
Expand Down Expand Up @@ -576,41 +572,6 @@ codeunit 7772 "Azure OpenAI Impl" implements "AI Service Name"
exit(SessionInformation.AITokensUsed);
end;

[NonDebuggable]
internal procedure IsTenantAllowlistedForFirstPartyCopilotCalls(): Boolean
var
EnvironmentInformation: Codeunit "Environment Information";
AzureKeyVault: Codeunit "Azure Key Vault";
AzureAdTenant: Codeunit "Azure AD Tenant";
AllowlistedTenants: Text;
EntraTenantIdAsText: Text;
EntraTenantIdAsGuid: Guid;
ModuleInfo: ModuleInfo;
begin
if not EnvironmentInformation.IsSaaSInfrastructure() then
exit(false);

NavApp.GetCurrentModuleInfo(ModuleInfo);
if ModuleInfo.Publisher <> 'Microsoft' then
exit(true);

if (not AzureKeyVault.GetAzureKeyVaultSecret(AllowlistedTenantsAkvKeyTok, AllowlistedTenants)) or (AllowlistedTenants.Trim() = '') then
exit(false);

EntraTenantIdAsText := AzureAdTenant.GetAadTenantId();

if (EntraTenantIdAsText = '') or not Evaluate(EntraTenantIdAsGuid, EntraTenantIdAsText) or IsNullGuid(EntraTenantIdAsGuid) then begin
Session.LogMessage('0000MLN', TelemetryEmptyTenantIdErr, Verbosity::Warning, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', GetAzureOpenAICategory());
exit(false);
end;

if not AllowlistedTenants.Contains(EntraTenantIdAsText) then
exit(false);

Session.LogMessage('0000MLE', TelemetryTenantAllowlistedMsg, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', GetAzureOpenAICategory());
exit(true);
end;

procedure GetAzureOpenAICategory(): Code[50]
begin
exit(AzureOpenAiTxt);
Expand Down
Loading