diff --git a/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al index 91c3b41abb..6e94049e7d 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al @@ -236,7 +236,7 @@ codeunit 7772 "Azure OpenAI Impl" SendTokenCountTelemetry(AOAIToken.GetGPT4TokenCount(Metaprompt), AOAIToken.GetGPT4TokenCount(Prompt), CustomDimensions); - if not SendRequest(Enum::"AOAI Model Type"::"Text Completions", TextCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse) then begin + if not SendRequest(Enum::"AOAI Model Type"::"Text Completions", TextCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin FeatureTelemetry.LogError('0000KVD', CopilotCapabilityImpl.GetAzureOpenAICategory(), TelemetryGenerateTextCompletionLbl, CompletionsFailedWithCodeErr, '', CustomDimensions); exit; end; @@ -263,7 +263,7 @@ codeunit 7772 "Azure OpenAI Impl" AddTelemetryCustomDimensions(CustomDimensions, CallerModuleInfo); SendTokenCountTelemetry(0, AOAIToken.GetAdaTokenCount(Input), CustomDimensions); - if not SendRequest(Enum::"AOAI Model Type"::Embeddings, EmbeddingsAOAIAuthorization, PayloadText, AOAIOperationResponse) then begin + if not SendRequest(Enum::"AOAI Model Type"::Embeddings, EmbeddingsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin FeatureTelemetry.LogError('0000KVE', CopilotCapabilityImpl.GetAzureOpenAICategory(), TelemetryGenerateEmbeddingLbl, EmbeddingsFailedWithCodeErr, '', CustomDimensions); exit; end; @@ -334,7 +334,7 @@ codeunit 7772 "Azure OpenAI Impl" Payload.WriteTo(PayloadText); SendTokenCountTelemetry(MetapromptTokenCount, PromptTokenCount, CustomDimensions); - if not SendRequest(Enum::"AOAI Model Type"::"Chat Completions", ChatCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse) then begin + if not SendRequest(Enum::"AOAI Model Type"::"Chat Completions", ChatCompletionsAOAIAuthorization, PayloadText, AOAIOperationResponse, CallerModuleInfo) then begin FeatureTelemetry.LogError('0000KVF', CopilotCapabilityImpl.GetAzureOpenAICategory(), TelemetryGenerateChatCompletionLbl, ChatCompletionsFailedWithCodeErr, '', CustomDimensions); exit; end; @@ -370,22 +370,25 @@ codeunit 7772 "Azure OpenAI Impl" [TryFunction] [NonDebuggable] - local procedure SendRequest(ModelType: Enum "AOAI Model Type"; AOAIAuthorization: Codeunit "AOAI Authorization"; Payload: Text; var AOAIOperationResponse: Codeunit "AOAI Operation Response") + local procedure SendRequest(ModelType: Enum "AOAI Model Type"; AOAIAuthorization: Codeunit "AOAI Authorization"; Payload: Text; var AOAIOperationResponse: Codeunit "AOAI Operation Response"; CallerModuleInfo: ModuleInfo) var ALCopilotAuthorization: DotNet ALCopilotAuthorization; + ALCopilotCapability: DotNet ALCopilotCapability; ALCopilotFunctions: DotNet ALCopilotFunctions; ALCopilotOperationResponse: DotNet ALCopilotOperationResponse; begin ClearLastError(); ALCopilotAuthorization := ALCopilotAuthorization.Create(AOAIAuthorization.GetEndpoint(), AOAIAuthorization.GetDeployment(), AOAIAuthorization.GetApiKey()); + ALCopilotCapability := ALCopilotCapability.ALCopilotCapability(CallerModuleInfo.Publisher(), CallerModuleInfo.Id(), Format(CallerModuleInfo.AppVersion()), GetCapabilityName()); + case ModelType of Enum::"AOAI Model Type"::"Text Completions": - ALCopilotOperationResponse := ALCopilotFunctions.GenerateTextCompletion(Payload, ALCopilotAuthorization); + ALCopilotOperationResponse := ALCopilotFunctions.GenerateTextCompletion(Payload, ALCopilotAuthorization, ALCopilotCapability); Enum::"AOAI Model Type"::Embeddings: - ALCopilotOperationResponse := ALCopilotFunctions.GenerateEmbedding(Payload, ALCopilotAuthorization); + ALCopilotOperationResponse := ALCopilotFunctions.GenerateEmbedding(Payload, ALCopilotAuthorization, ALCopilotCapability); Enum::"AOAI Model Type"::"Chat Completions": - ALCopilotOperationResponse := ALCopilotFunctions.GenerateChatCompletion(Payload, ALCopilotAuthorization); + ALCopilotOperationResponse := ALCopilotFunctions.GenerateChatCompletion(Payload, ALCopilotAuthorization, ALCopilotCapability); else Error(InvalidModelTypeErr) end; @@ -396,6 +399,22 @@ codeunit 7772 "Azure OpenAI Impl" Error(GenerateRequestFailedErr); end; + local procedure GetCapabilityName(): Text + var + CapabilityIndex: Integer; + CapabilityName: Text; + begin + CheckCapabilitySet(); + + CapabilityIndex := CopilotSettings.Capability.Ordinals.IndexOf(CopilotSettings.Capability.AsInteger()); + CapabilityName := CopilotSettings.Capability.Names.Get(CapabilityIndex); + + if CapabilityName.Trim() = '' then + exit(Format(CopilotSettings.Capability, 0, 9)); + + exit(CapabilityName); + end; + [NonDebuggable] local procedure SendTokenCountTelemetry(Metaprompt: Integer; Prompt: Integer; CustomDimensions: Dictionary of [Text, Text]) begin diff --git a/src/System Application/App/DotNet Aliases/src/dotnet.al b/src/System Application/App/DotNet Aliases/src/dotnet.al index 0cf990dad7..e0a6fb6112 100644 --- a/src/System Application/App/DotNet Aliases/src/dotnet.al +++ b/src/System Application/App/DotNet Aliases/src/dotnet.al @@ -2161,6 +2161,10 @@ dotnet type("Microsoft.Dynamics.Nav.Service.CopilotApi.AL.ALCopilotOperationResponse"; ALCopilotOperationResponse) { } + + type("Microsoft.Dynamics.Nav.Service.CopilotApi.AL.ALCopilotCapability"; ALCopilotCapability) + { + } } assembly("Microsoft.Dynamics.Nav.DataSearch") {