Skip to content

[releases/25.x] [Copilot] Reduce KV checks for embed ISVs #2762

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

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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 @@ -98,11 +98,16 @@ codeunit 7772 "Azure OpenAI Impl"
EnvironmentInformation: Codeunit "Environment Information";
AzureKeyVault: Codeunit "Azure Key Vault";
AzureAdTenant: Codeunit "Azure AD Tenant";
ModuleInfo: ModuleInfo;
BlockList: Text;
begin
if not EnvironmentInformation.IsSaaSInfrastructure() then
exit(true);

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

if (not AzureKeyVault.GetAzureKeyVaultSecret(EnabledKeyTok, BlockList)) or (BlockList.Trim() = '') then begin
FeatureTelemetry.LogError('0000KYC', CopilotCapabilityImpl.GetAzureOpenAICategory(), TelemetryIsEnabledLbl, TelemetryUnableToCheckEnvironmentKVTxt);
exit(false);
Expand Down Expand Up @@ -662,25 +667,26 @@ codeunit 7772 "Azure OpenAI Impl"
var
AzureKeyVault: Codeunit "Azure Key Vault";
EnvironmentInformation: Codeunit "Environment Information";
ModuleInfo: ModuleInfo;
KVSecret: SecretText;
begin
if not EnvironmentInformation.IsSaaSInfrastructure() then
exit;

if not AzureKeyVault.GetAzureKeyVaultSecret('AOAI-Metaprompt-Text', KVSecret) then begin
Telemetry.LogMessage('0000LX3', TelemetryMetapromptRetrievalErr, Verbosity::Error, DataClassification::SystemMetadata);
Error(MetapromptLoadingErr);
NavApp.GetCurrentModuleInfo(ModuleInfo);
if ModuleInfo.Publisher = 'Microsoft' then
Error(MetapromptLoadingErr);
end;
Metaprompt := KVSecret;
end;

[NonDebuggable]
local procedure CheckTextCompletionMetaprompt(Metaprompt: SecretText; CustomDimensions: Dictionary of [Text, Text])
begin
if Metaprompt.Unwrap().Trim() = '' then begin
if Metaprompt.Unwrap().Trim() = '' then
FeatureTelemetry.LogError('0000LO8', CopilotCapabilityImpl.GetAzureOpenAICategory(), TelemetryGenerateTextCompletionLbl, EmptyMetapromptErr, '', Enum::"AL Telemetry Scope"::All, CustomDimensions);
Error(EmptyMetapromptErr);
end;
end;
#if not CLEAN24
[NonDebuggable]
Expand Down Expand Up @@ -714,10 +720,15 @@ codeunit 7772 "Azure OpenAI Impl"
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,10 @@ codeunit 7764 "AOAI Chat Messages Impl"
Preprompt: Text;
Postprompt: Text;
begin
if not AzureKeyVault.GetAzureKeyVaultSecret('AOAI-Preprompt-Chat', Preprompt) then begin
if not AzureKeyVault.GetAzureKeyVaultSecret('AOAI-Preprompt-Chat', Preprompt) then
Telemetry.LogMessage('0000LX4', TelemetryPrepromptRetrievalErr, Verbosity::Error, DataClassification::SystemMetadata);
Error(MetapromptLoadingErr);
end;
if not AzureKeyVault.GetAzureKeyVaultSecret('AOAI-Postprompt-Chat', Postprompt) then begin
if not AzureKeyVault.GetAzureKeyVaultSecret('AOAI-Postprompt-Chat', Postprompt) then
Telemetry.LogMessage('0000LX5', TelemetryPostpromptRetrievalErr, Verbosity::Error, DataClassification::SystemMetadata);
Error(MetapromptLoadingErr);
end;

exit(Preprompt + Message + Postprompt);
end;
Expand All @@ -326,6 +322,7 @@ codeunit 7764 "AOAI Chat Messages Impl"
var
AzureKeyVault: Codeunit "Azure Key Vault";
EnvironmentInformation: Codeunit "Environment Information";
ModuleInfo: ModuleInfo;
KVSecret: Text;
begin
if not EnvironmentInformation.IsSaaSInfrastructure() then
Expand All @@ -335,7 +332,9 @@ codeunit 7764 "AOAI Chat Messages Impl"
UsingMicrosoftMetaprompt := true
else begin
Telemetry.LogMessage('0000LX6', TelemetryMetapromptRetrievalErr, Verbosity::Error, DataClassification::SystemMetadata);
Error(MetapromptLoadingErr);
NavApp.GetCurrentModuleInfo(ModuleInfo);
if ModuleInfo.Publisher = 'Microsoft' then
Error(MetapromptLoadingErr);
end;
Metaprompt := KVSecret;
end;
Expand Down
Loading