@@ -22,7 +22,6 @@ codeunit 7772 "Azure OpenAI Impl"
22
22
var
23
23
CopilotSettings: Record "Copilot Settings";
24
24
CopilotCapabilityCU: Codeunit "Copilot Capability";
25
- CopilotCapabilityImpl: Codeunit "Copilot Capability Impl";
26
25
ChatCompletionsAOAIAuthorization: Codeunit "AOAI Authorization";
27
26
TextCompletionsAOAIAuthorization: Codeunit "AOAI Authorization";
28
27
EmbeddingsAOAIAuthorization: Codeunit "AOAI Authorization";
@@ -39,8 +38,6 @@ codeunit 7772 "Azure OpenAI Impl"
39
38
CopilotCapabilityNotSetErr: Label ' Copilot capability has not been set.' ;
40
39
CapabilityBackgroundErr: Label ' Microsoft Copilot Capabilities are not allowed in the background.' ;
41
40
CopilotDisabledForTenantErr: Label ' Copilot is not enabled for the tenant. Please contact your system administrator.' ;
42
- CapabilityNotRegisteredErr: Label ' Copilot capability '' %1'' has not been registered by the module.' , Comment = ' %1 is the name of the Copilot Capability' ;
43
- CapabilityNotEnabledErr: Label ' Copilot capability '' %1'' has not been enabled. Please contact your system administrator.' , Comment = ' %1 is the name of the Copilot Capability' ;
44
41
MessagesMustContainJsonWordWhenResponseFormatIsJsonErr: Label ' The messages must contain the word '' json'' in some form, to use '' response format'' of type '' json_object'' .' ;
45
42
EmptyMetapromptErr: Label ' The metaprompt has not been set, please provide a metaprompt.' ;
46
43
MetapromptLoadingErr: Label ' Metaprompt not found.' ;
@@ -52,8 +49,6 @@ codeunit 7772 "Azure OpenAI Impl"
52
49
TelemetryGenerateChatCompletionLbl: Label ' Chat Completion generated.' , Locked = true;
53
50
TelemetryChatCompletionToolCallLbl: Label ' Tools called by chat completion.' , Locked = true;
54
51
TelemetryChatCompletionToolUsedLbl: Label ' Tools added to chat completion.' , Locked = true;
55
- TelemetrySetCapabilityLbl: Label ' Set Capability' , Locked = true;
56
- TelemetryCopilotCapabilityNotRegisteredLbl: Label ' Copilot capability not registered.' , Locked = true;
57
52
TelemetryIsEnabledLbl: Label ' Is Enabled' , Locked = true;
58
53
TelemetryUnableToCheckEnvironmentKVTxt: Label ' Unable to check if environment is allowed to run AOAI.' , Locked = true;
59
54
TelemetryEnvironmentNotAllowedtoRunCopilotTxt: Label ' Copilot is not allowed on this environment.' , Locked = true;
@@ -63,6 +58,7 @@ codeunit 7772 "Azure OpenAI Impl"
63
58
TelemetryFunctionCallingFailedErr: Label ' Function calling failed for function: %1' , Comment = ' %1 is the name of the function' , Locked = true;
64
59
TelemetryEmptyTenantIdErr: Label ' Empty or malformed tenant ID.' , Locked = true;
65
60
TelemetryTenantAllowlistedMsg: Label ' Current tenant allowlisted for first party auth.' , Locked = true;
61
+ AzureOpenAiTxt: Label ' Azure OpenAI' , Locked = true;
66
62
67
63
procedure IsEnabled( Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo ) : Boolean
68
64
begin
@@ -109,12 +105,12 @@ codeunit 7772 "Azure OpenAI Impl"
109
105
exit ( true) ;
110
106
111
107
if ( not AzureKeyVault. GetAzureKeyVaultSecret( EnabledKeyTok, BlockList)) or ( BlockList. Trim() = ' ' ) then begin
112
- FeatureTelemetry. LogError( ' 0000KYC' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryIsEnabledLbl, TelemetryUnableToCheckEnvironmentKVTxt) ;
108
+ FeatureTelemetry. LogError( ' 0000KYC' , GetAzureOpenAICategory() , TelemetryIsEnabledLbl, TelemetryUnableToCheckEnvironmentKVTxt) ;
113
109
exit ( false) ;
114
110
end ;
115
111
116
112
if BlockList. Contains( AzureAdTenant. GetAadTenantId()) then begin
117
- FeatureTelemetry. LogError( ' 0000LFP' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryIsEnabledLbl, TelemetryEnvironmentNotAllowedtoRunCopilotTxt) ;
113
+ FeatureTelemetry. LogError( ' 0000LFP' , GetAzureOpenAICategory() , TelemetryIsEnabledLbl, TelemetryEnvironmentNotAllowedtoRunCopilotTxt) ;
118
114
exit ( false) ;
119
115
end ;
120
116
@@ -126,7 +122,7 @@ codeunit 7772 "Azure OpenAI Impl"
126
122
PrivacyNotice: Codeunit "Privacy Notice";
127
123
CopilotNotAvailable: Page "Copilot Not Available";
128
124
begin
129
- case PrivacyNotice. GetPrivacyNoticeApprovalState( CopilotCapabilityImpl . GetAzureOpenAICategory() , false) of
125
+ case PrivacyNotice. GetPrivacyNoticeApprovalState( GetAzureOpenAICategory() , false) of
130
126
Enum ::"Privacy Notice Approval State"::Agreed:
131
127
exit ( true) ;
132
128
Enum ::"Privacy Notice Approval State"::Disagreed:
@@ -256,11 +252,11 @@ codeunit 7772 "Azure OpenAI Impl"
256
252
SendTokenCountTelemetry( AOAIToken. GetGPT4TokenCount( Metaprompt) , AOAIToken. GetGPT4TokenCount( Prompt) , CustomDimensions) ;
257
253
258
254
if not SendRequest( Enum ::"AOAI Model Type"::"Text Completions", TextCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin
259
- FeatureTelemetry. LogError( ' 0000KVD' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, CompletionsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
255
+ FeatureTelemetry. LogError( ' 0000KVD' , GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, CompletionsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
260
256
exit ;
261
257
end ;
262
258
263
- FeatureTelemetry. LogUsage( ' 0000KVL' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
259
+ FeatureTelemetry. LogUsage( ' 0000KVL' , GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
264
260
Result := AOAIOperationResponse. GetResult() ;
265
261
end ;
266
262
@@ -283,11 +279,11 @@ codeunit 7772 "Azure OpenAI Impl"
283
279
AddTelemetryCustomDimensions( CustomDimensions, CallerModuleInfo) ;
284
280
SendTokenCountTelemetry( 0 , AOAIToken. GetAdaTokenCount( Input) , CustomDimensions) ;
285
281
if not SendRequest( Enum ::"AOAI Model Type"::Embeddings, EmbeddingsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin
286
- FeatureTelemetry. LogError( ' 0000KVE' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateEmbeddingLbl, EmbeddingsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
282
+ FeatureTelemetry. LogError( ' 0000KVE' , GetAzureOpenAICategory() , TelemetryGenerateEmbeddingLbl, EmbeddingsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
287
283
exit ;
288
284
end ;
289
285
290
- FeatureTelemetry. LogUsage( ' 0000KVM' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateEmbeddingLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
286
+ FeatureTelemetry. LogUsage( ' 0000KVM' , GetAzureOpenAICategory() , TelemetryGenerateEmbeddingLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
291
287
exit ( ProcessEmbeddingResponse( AOAIOperationResponse)) ;
292
288
end ;
293
289
@@ -356,13 +352,13 @@ codeunit 7772 "Azure OpenAI Impl"
356
352
357
353
SendTokenCountTelemetry( MetapromptTokenCount, PromptTokenCount, CustomDimensions) ;
358
354
if not SendRequest( Enum ::"AOAI Model Type"::"Chat Completions", ChatCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin
359
- FeatureTelemetry. LogError( ' 0000KVF' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateChatCompletionLbl, ChatCompletionsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
355
+ FeatureTelemetry. LogError( ' 0000KVF' , GetAzureOpenAICategory() , TelemetryGenerateChatCompletionLbl, ChatCompletionsFailedWithCodeErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
360
356
exit ;
361
357
end ;
362
358
363
359
ProcessChatCompletionResponse( ChatMessages, AOAIOperationResponse, CallerModuleInfo) ;
364
360
365
- FeatureTelemetry. LogUsage( ' 0000KVN' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateChatCompletionLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
361
+ FeatureTelemetry. LogUsage( ' 0000KVN' , GetAzureOpenAICategory() , TelemetryGenerateChatCompletionLbl, Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
366
362
367
363
if ( AOAIOperationResponse. GetFunctionResponses(). Count () > 0 ) and ( ChatMessages. GetToolInvokePreference() = Enum ::"AOAI Tool Invoke Preference"::Automatic) then
368
364
GenerateChatCompletion( ChatMessages, AOAIChatCompletionParams, AOAIOperationResponse, CallerModuleInfo) ;
@@ -421,7 +417,7 @@ codeunit 7772 "Azure OpenAI Impl"
421
417
AddTelemetryCustomDimensions( CustomDimensions, CallerModuleInfo) ;
422
418
foreach AOAIFunctionResponse in AOAIOperationResponse. GetFunctionResponses() do
423
419
if not AOAIFunctionResponse. IsSuccess() then
424
- FeatureTelemetry. LogError( ' 0000MTB' , CopilotCapabilityImpl . GetAzureOpenAICategory() , StrSubstNo( TelemetryFunctionCallingFailedErr, AOAIFunctionResponse. GetFunctionName()) , AOAIFunctionResponse. GetError() , AOAIFunctionResponse. GetErrorCallstack() , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
420
+ FeatureTelemetry. LogError( ' 0000MTB' , GetAzureOpenAICategory() , StrSubstNo( TelemetryFunctionCallingFailedErr, AOAIFunctionResponse. GetFunctionName()) , AOAIFunctionResponse. GetError() , AOAIFunctionResponse. GetErrorCallstack() , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
425
421
426
422
if ChatMessages. GetToolInvokePreference() in [Enum ::"AOAI Tool Invoke Preference"::"Invoke Tools Only", Enum ::"AOAI Tool Invoke Preference"::Automatic] then
427
423
AOAIOperationResponse. AppendFunctionResponsesToChatMessages( ChatMessages) ;
@@ -600,36 +596,6 @@ codeunit 7772 "Azure OpenAI Impl"
600
596
GlobalLanguage( SavedGlobalLanguageId) ;
601
597
end ;
602
598
603
- procedure SetCopilotCapability( Capability: Enum "Copilot Capability"; CallerModuleInfo: ModuleInfo )
604
- var
605
- CopilotTelemetry: Codeunit "Copilot Telemetry";
606
- Language: Codeunit Language;
607
- SavedGlobalLanguageId: Integer ;
608
- CustomDimensions: Dictionary of [Text , Text ];
609
- ErrorMessage: Text ;
610
- begin
611
- if not CopilotCapabilityCU. IsCapabilityRegistered( Capability, CallerModuleInfo. Id()) then begin
612
- SavedGlobalLanguageId := GlobalLanguage() ;
613
- GlobalLanguage( Language. GetDefaultApplicationLanguageId()) ;
614
- CustomDimensions. Add ( ' Capability' , Format( Capability)) ;
615
- CustomDimensions. Add ( ' AppId' , Format( CallerModuleInfo. Id())) ;
616
- GlobalLanguage( SavedGlobalLanguageId) ;
617
-
618
- FeatureTelemetry. LogError( ' 0000LFN' , CopilotCapabilityImpl. GetAzureOpenAICategory() , TelemetrySetCapabilityLbl, TelemetryCopilotCapabilityNotRegisteredLbl, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
619
- ErrorMessage := StrSubstNo( CapabilityNotRegisteredErr, Capability) ;
620
- Error( ErrorMessage) ;
621
- end ;
622
-
623
- CopilotSettings. ReadIsolation( IsolationLevel ::ReadCommitted) ;
624
- CopilotSettings. SetLoadFields( Status) ;
625
- CopilotSettings. Get( Capability, CallerModuleInfo. Id()) ;
626
- if CopilotSettings. Status = Enum ::"Copilot Status"::Inactive then begin
627
- ErrorMessage := StrSubstNo( CapabilityNotEnabledErr, Capability) ;
628
- Error( ErrorMessage) ;
629
- end ;
630
- CopilotTelemetry. SetCopilotCapability( Capability, CallerModuleInfo. Id()) ;
631
- end ;
632
-
633
599
local procedure CheckEnabled( CallerModuleInfo: ModuleInfo )
634
600
begin
635
601
if not IsEnabled( CopilotSettings. Capability, true, CallerModuleInfo) then
@@ -688,7 +654,7 @@ codeunit 7772 "Azure OpenAI Impl"
688
654
ModuleInfo : ModuleInfo ;
689
655
begin
690
656
if Metaprompt. Unwrap(). Trim() = ' ' then begin
691
- FeatureTelemetry. LogError( ' 0000LO8' , CopilotCapabilityImpl . GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, EmptyMetapromptErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
657
+ FeatureTelemetry. LogError( ' 0000LO8' , GetAzureOpenAICategory() , TelemetryGenerateTextCompletionLbl, EmptyMetapromptErr, ' ' , Enum ::"AL Telemetry Scope"::All, CustomDimensions) ;
692
658
693
659
NavApp. GetCurrentModuleInfo( ModuleInfo ) ;
694
660
if ModuleInfo . Publisher = ' Microsoft' then
@@ -747,15 +713,29 @@ codeunit 7772 "Azure OpenAI Impl"
747
713
EntraTenantIdAsText := AzureAdTenant. GetAadTenantId() ;
748
714
749
715
if ( EntraTenantIdAsText = ' ' ) or not Evaluate( EntraTenantIdAsGuid, EntraTenantIdAsText) or IsNullGuid( EntraTenantIdAsGuid) then begin
750
- Session. LogMessage( ' 0000MLN' , TelemetryEmptyTenantIdErr, Verbosity ::Warning, DataClassification ::SystemMetadata, TelemetryScope::ExtensionPublisher, ' Category' , CopilotCapabilityImpl . GetAzureOpenAICategory()) ;
716
+ Session. LogMessage( ' 0000MLN' , TelemetryEmptyTenantIdErr, Verbosity ::Warning, DataClassification ::SystemMetadata, TelemetryScope::ExtensionPublisher, ' Category' , GetAzureOpenAICategory()) ;
751
717
exit ( false) ;
752
718
end ;
753
719
754
720
if not AllowlistedTenants. Contains( EntraTenantIdAsText) then
755
721
exit ( false) ;
756
722
757
- Session. LogMessage( ' 0000MLE' , TelemetryTenantAllowlistedMsg, Verbosity ::Normal, DataClassification ::SystemMetadata, TelemetryScope::ExtensionPublisher, ' Category' , CopilotCapabilityImpl . GetAzureOpenAICategory()) ;
723
+ Session. LogMessage( ' 0000MLE' , TelemetryTenantAllowlistedMsg, Verbosity ::Normal, DataClassification ::SystemMetadata, TelemetryScope::ExtensionPublisher, ' Category' , GetAzureOpenAICategory()) ;
758
724
exit ( true) ;
759
725
end ;
760
726
727
+ procedure GetAzureOpenAICategory() : Code [50 ]
728
+ begin
729
+ exit ( AzureOpenAiTxt) ;
730
+ end ;
731
+
732
+ [EventSubscriber( ObjectType ::Codeunit , Codeunit ::"Privacy Notice", ' OnRegisterPrivacyNotices' , ' ' , false, false) ]
733
+ local procedure CreatePrivacyNoticeRegistrations( var TempPrivacyNotice: Record "Privacy Notice" temporary )
734
+ begin
735
+ TempPrivacyNotice. Init() ;
736
+ TempPrivacyNotice. ID := AzureOpenAiTxt;
737
+ TempPrivacyNotice. "Integration Service Name" := AzureOpenAiTxt;
738
+ if not TempPrivacyNotice. Insert() then ;
739
+ end ;
740
+
761
741
}
0 commit comments