Unlocking AI Potential in Sitecore: Integrating Azure OpenAI using SPE

In today’s fast-paced digital landscape, leveraging AI has become essential for optimizing marketing and content operations. Integrating Azure OpenAI with Sitecore can streamline tasks such as SEO metadata generation, content validation, and more. This blog demonstrates how to integrate the Azure OpenAI, which is securely protected by Azure Role-Based Access Control (RBAC), with Sitecore using the Sitecore PowerShell Extension (SPE).

Here are the steps to set up Azure OpenAI,

  • Create a new Azure OpenAI Service from Azure Portal in your preferred location
  • Launch Azure AI Studio and select the above created OpenAI Service
  • Create a new deployment selecting your preferred GPT model(typically gpt-35-turbo-16k or gpt-4-32k). More details about models can be found here.
  • Register an app in Azure Active Directory(now Entra ID) and obtain Tenant ID, Client ID & Client Secret, as you will need them in the upcoming steps to get the bearer token.
  • Role-based Access Control: Add appropriate role assignments to the above app for Azure OpenAI(Cognitive Services OpenAI Contributor) from it’s IAM section.
  • Use the below script to invoke the Completions API with Bearer Token,

The ‘Get-BearerToken’ function gets the bearer token from the Azure Token endpoint following client credentials flow. This token is then used for authentication to get completions for the supplied prompts by invoking the Azure OpenAI Completions API.

Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *