Using OpenAI REST Endpoints with Azure SQL Database
Using OpenAI REST Endpoints with Azure SQL Database
In this article, the author explores how to use OpenAI REST Endpoints with Azure SQL Database. The author starts by referencing Buck Woody's blog on securing AI using SQL Server Machine Learning with Microsoft Azure OpenAI Services. However, this article focuses on utilizing OpenAI with Azure SQL Database without access to SQL Server Machine Learning Services.
To get started, the author mentions that you can request access to the OpenAI service through a provided form. Once the resource is created, you can navigate to the Model Deployments option in the Azure portal and open OpenAI Studio in the browser.
The author then proceeds to explain how to use the Chat Session area in OpenAI Studio to ask a question. You simply enter your question in the text field and submit it. The author also mentions that there is no need to choose the 16k option for this example.
Moving on, the author explores how to use the OpenAI REST API endpoints within Azure SQL Database. They demonstrate this using T-SQL code. First, you need to declare and prefill some variables, such as the URL or Endpoint you want to use and the API key that grants you access to the endpoint.
The author provides an example of T-SQL code where the payload variable contains the chat prompt text. By running this code against your Azure SQL Database, you can call an OpenAI prompt and receive a response containing the answer.
The article also addresses the issue of passing the api-key in the header parameter, which can potentially lead to security risks. To address this, the author suggests adding the database to the Cognitive Services OpenAI User role using Access control (IAM) in the OpenAI Azure Portal page. This allows you to use a credential parameter instead of the header parameter in the stored procedure call, thus avoiding potential issues related to storing and leaking the api-key.
Overall, this article provides a comprehensive guide on using OpenAI REST Endpoints with Azure SQL Database. The author explains the process step by step and offers solutions to potential security concerns.