Skip to content

Contains a Terraform module to provision a cognitive deployment on Azure

Notifications You must be signed in to change notification settings

patkoch/terraform-azure-cognitive-deployment

Repository files navigation

GitHub Action Workflow

Current state of the workflow execution:

Open AI Service

Contains a Terraform configuration to provision a cognitive deployment on Azure

This Terraform configuration is capable of deploying an Azure Open AI Service and a gpt-4 model. After the deployment, it is possible to conduct a chat by using a Python script with the generated API_Key and a public Endpoint.

Prepare the terraform.tfvars file

Create a new file inside the checked out directory of this repository, named "terraform.tfvars". The content of it can be seen in the code snippet below - there are 12 values to assign to predefined variables:

subscription_id = "<add your subscription id here>"
resource_group_name = "open-ai-test-west-europe-rg"
resource_group_location = "West Europe"
cognitive_account_name = "open-ai-test-west-europe-ca"
cognitive_account_kind = "OpenAI"
cognitive_account_sku_name = "S0"
cognitive_deployment_name = "open-ai-test-west-europe-cd"
cognitive_deployment_model_format = "OpenAI"
cognitive_deployment_model_name = "gpt-4"
cognitive_deployment_model_version = "turbo-2024-04-09"
cognitive_deployment_sku_name = "GlobalStandard"
cognitive_deployment_sku_capacity = 45

The only value to determine for your personal deployment is the "subscription_id" of your Azure subscription. You can run the following command to find the "subscription_id":

az account show

Add the subscription id as value in the first line in the "terraform.tfvars" file and save it. The "terraform.tfvars" has to be located side by side to the "main.tf", "terraform.tf" and the "variables.tf" files.

Deploy the resources using Terraform

Start a new terminal, change the directory of the checked out directory of the repository.

After that, conduct the following four Terraform commands:

Terraform init

terraform init

Terraform validate

terraform validate

Terraform plan

terraform plan -out tfplan

Terraform apply

terraform apply tfplan

This finally deploys the Azure AI Service named "open-ai-test-west-europe-ca":

and the "gpt-4" deployment "open-ai-test-west-europe-cd":

You can change the type of the deployment by adapting the following values:

cognitive_deployment_model_format = "OpenAI"
cognitive_deployment_model_name = "gpt-4"
cognitive_deployment_model_version = "turbo-2024-04-09"
cognitive_deployment_sku_name = "GlobalStandard"

Check at Azure OpenAI Service models which model fits for you also regarding your prefered region.

In that case, it's about a "gpt-4" deployment with the model version "turbo-2024-04-09".

Conduct prompts and get a response

Get the endpoint credentials

You need to get the following information of the endpoint to establish a connection to the service:

  • the API Key
  • the Target URI

Explore the Details of the deployment to find that data:

Use a python script to send the requests

Insert the mentioned information in the lines 5, respectively 6 in the file "/scripts/send_requests.py":

Afte that, call the file using Python like:

Destroy the resources

If there is no need any more, then destroy the resources using:

terraform destroy

References

The code of this example was partially created with the GitHub Copilot, respectively I used also the following examples and documentation of HashiCorp and Microsoft:

Terraform Registry - azurerm_cognitive_account

Azure OpenAI Service models

About

Contains a Terraform module to provision a cognitive deployment on Azure

Topics

Resources

Stars

Watchers

Forks