Codeunit "Azure OpenAI"

ID 7771
Namespace: System.AI

Provides functionality for using the Azure OpenAI API.

Properties

Name Value
Access Public
InherentEntitlements X
InherentPermissions X

Methods

IsEnabled

Checks if the Azure OpenAI API is enabled for the environment and if the capability is active on the environment.

procedure IsEnabled(CopilotCapability: Enum "Copilot Capability"): Boolean

Parameters

Name Type Description
CopilotCapability System.AI."Copilot Capability"

The copilot capability to check.

Returns

Type Description
Boolean

True if API and capability is enabled for environment.

IsEnabled

Checks if the Azure OpenAI API is enabled for the environment and if the capability is active on the environment.

procedure IsEnabled(CopilotCapability: Enum "Copilot Capability", Silent: Boolean): Boolean

Parameters

Name Type Description
CopilotCapability System.AI."Copilot Capability"

The copilot capability to check.

Silent Boolean

If true, no error message will be shown if API is not enabled.

Returns

Type Description
Boolean

True if API and capability is enabled for environment.

IsAuthorizationConfigured

Checks if the Azure OpenAI API authorization is configured for the environment.

procedure IsAuthorizationConfigured(ModelType: Enum "AOAI Model Type"): Boolean

Parameters

Name Type Description
ModelType System.AI."AOAI Model Type"

The model type to check authorization for.

Returns

Type Description
Boolean

True if API is authorized for environment.

IsInitialized

Checks if the Azure OpenAI API is enabled for the environment and authorization is configured for the modeltype.

procedure IsInitialized(CopilotCapability: Enum "Copilot Capability", ModelType: Enum "AOAI Model Type"): Boolean

Parameters

Name Type Description
CopilotCapability System.AI."Copilot Capability"

The copilot capability to check.

ModelType System.AI."AOAI Model Type"

The model type to check authorization for.

Returns

Type Description
Boolean

True if the API is enabled and model authorization has been configured.

SetManagedResourceAuthorization

Sets the managed Azure OpenAI API authorization to use for a specific model type. This will send the Azure OpenAI call to the deployment specified in ManagedResourceDeployment, and will use the other parameters to verify that you have access to Azure OpenAI.

[NonDebuggable]
procedure SetManagedResourceAuthorization(ModelType: Enum "AOAI Model Type", Endpoint: Text, Deployment: Text, ApiKey: SecretText, ManagedResourceDeployment: Text)

Parameters

Name Type Description
ModelType System.AI."AOAI Model Type"

The model type to set authorization for.

Endpoint Text

The endpoint to use to verify access to Azure OpenAI. This is used only for verification, not for actual Azure OpenAI calls.

Deployment Text

The deployment to use to verify access to Azure OpenAI. This is used only for verification, not for actual Azure OpenAI calls.

ApiKey SecretText

The API key to use to verify access to Azure OpenAI. This is used only for verification, not for actual Azure OpenAI calls.

ManagedResourceDeployment Text

The managed deployment to use for the model type.

Remarks

function is currently only available to selected partners. Endpoint would look like: https://resource-name.openai.azure.com/ Deployment would look like: gpt-35-turbo-16k

SetAuthorization

Sets the Azure OpenAI API authorization to use for a specific model type and endpoint.

[NonDebuggable]
procedure SetAuthorization(ModelType: Enum "AOAI Model Type", Endpoint: Text, Deployment: Text, ApiKey: SecretText)

Parameters

Name Type Description
ModelType System.AI."AOAI Model Type"

The model type to set authorization for.

Endpoint Text

The endpoint to use for the model type.

Deployment Text

The deployment to use for the endpoint.

ApiKey SecretText

The API key to use for the endpoint.

Remarks

Endpoint would look like: https://resource-name.openai.azure.com/ Deployment would look like: gpt-35-turbo-16k

SetAuthorization

Sets the Azure OpenAI API authorization to use for a specific model type.

[NonDebuggable]
procedure SetAuthorization(ModelType: Enum "AOAI Model Type", Deployment: Text)

Parameters

Name Type Description
ModelType System.AI."AOAI Model Type"

The model type to set authorization for.

Deployment Text

The deployment name to use for the model type.

Remarks

Deployment would look like: gpt-35-turbo-16k

GenerateTextCompletion

Generates a text completion given a prompt.

[NonDebuggable]
procedure GenerateTextCompletion(Prompt: SecretText, var AOAIOperationResponse: Codeunit "AOAI Operation Response"): Text

Parameters

Name Type Description
Prompt SecretText

The prompt to generate completion for.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

Returns

Type Description
Text

The generated completion.

GenerateTextCompletion

Generates a completion given a prompt and completion parameters.

[NonDebuggable]
procedure GenerateTextCompletion(Prompt: SecretText, AOAICompletionParams: Codeunit "AOAI Text Completion Params", var AOAIOperationResponse: Codeunit "AOAI Operation Response"): Text

Parameters

Name Type Description
Prompt SecretText

The prompt to generate completion for.

AOAICompletionParams System.AI."AOAI Text Completion Params"

The optional completion parameters to use.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

Returns

Type Description
Text

The generated completion.

GenerateTextCompletion

Generates a text completion given a prompt.

[NonDebuggable]
procedure GenerateTextCompletion(Metaprompt: SecretText, Prompt: SecretText, var AOAIOperationResponse: Codeunit "AOAI Operation Response"): Text

Parameters

Name Type Description
Metaprompt SecretText

The metaprompt to be appended with the prompt.

Prompt SecretText

The prompt to generate completion for.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

Returns

Type Description
Text

The generated completion.

GenerateTextCompletion

Generates a completion given a prompt and completion parameters.

[NonDebuggable]
procedure GenerateTextCompletion(Metaprompt: SecretText, Prompt: SecretText, AOAICompletionParams: Codeunit "AOAI Text Completion Params", var AOAIOperationResponse: Codeunit "AOAI Operation Response"): Text

Parameters

Name Type Description
Metaprompt SecretText

The metaprompt to be appended with the prompt.

Prompt SecretText

The prompt to generate completion for.

AOAICompletionParams System.AI."AOAI Text Completion Params"

The optional completion parameters to use.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

Returns

Type Description
Text

The generated completion.

GenerateEmbeddings

Generates embeddings given an input.

[NonDebuggable]
procedure GenerateEmbeddings(Input: SecretText, var AOAIOperationResponse: Codeunit "AOAI Operation Response"): List of [Decimal]

Parameters

Name Type Description
Input SecretText

The input to generate embedding for.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

Returns

Type Description
List of [Decimal]

The generated list of embeddings.

GenerateChatCompletion

Generates a chat completion given a list of chat messages.

[NonDebuggable]
procedure GenerateChatCompletion(var AOAIChatMessages: Codeunit "AOAI Chat Messages", var AOAIOperationResponse: Codeunit "AOAI Operation Response")

Parameters

Name Type Description
AOAIChatMessages System.AI."AOAI Chat Messages"

The chat messages to generate completion for.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

GenerateChatCompletion

Generates a chat completion given a list of chat messages and completion parameters.

[NonDebuggable]
procedure GenerateChatCompletion(var AOAIChatMessages: Codeunit "AOAI Chat Messages", AOAIChatCompletionParams: Codeunit "AOAI Chat Completion Params", var AOAIOperationResponse: Codeunit "AOAI Operation Response")

Parameters

Name Type Description
AOAIChatMessages System.AI."AOAI Chat Messages"

The chat messages to generate completion for.

AOAIChatCompletionParams System.AI."AOAI Chat Completion Params"

The optional chat completion parameters to use.

AOAIOperationResponse System.AI."AOAI Operation Response"

The response of the operation upon successful or failure execution.

SetCopilotCapability

Sets the copilot capability that the API is running for.

[NonDebuggable]
procedure SetCopilotCapability(CopilotCapability: Enum "Copilot Capability")

Parameters

Name Type Description
CopilotCapability System.AI."Copilot Capability"

The copilot capability to set.

ApproximateTokenCount

Obsolete

This element will become obsolete from version 24.0. Use the AOAI Token codeunit.

Gets the approximate token count for the input.

[NonDebuggable]
[Obsolete(Use the AOAI Token codeunit.,24.0)]
procedure ApproximateTokenCount(Input: Text): Integer

Parameters

Name Type Description
Input Text

The input to get the approximate token count for.

Returns

Type Description
Integer

The approximate token count.

See also