Skip to content

Commit 478d24c

Browse files
authored
Add article about deploying OpenAI using Bicep (#287)
* Add article about deploying OpenAI using Bicep * fix description * fix typos * use interactive code fence labels * Acrolinx edits
1 parent f2fcf42 commit 478d24c

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
---
2+
title: Deploy the Azure OpenAI Service using Bicep
3+
description: This article provides the step-by-step instructions to deploy and instance of the Azure OpenAI Service using Bicep.
4+
ms.date: 01/15/2025
5+
ms.topic: concept-article
6+
---
7+
# Deploy the Azure OpenAI Service using Bicep
8+
9+
In AIShell, the **openai-gpt** agent can be used with a public OpenAI instance or an Azure OpenAI
10+
deployment. We recommend using the Azure OpenAI Service because it has additional features and
11+
provides better manageability. This article provides the step-by-step instructions to deploy and
12+
instance of the Azure OpenAI Service using Bicep.
13+
14+
To use AIShell with the Azure OpenAI Service, you need the following Azure resources:
15+
16+
- An Azure OpenAI Service account - a resource that contains multiple different model deployments.
17+
- An Azure OpenAI Deployment - a model deployment that can be called using an API to generate
18+
responses.
19+
20+
## Prerequisites
21+
22+
Before you begin, ensure you have the following prerequisites:
23+
24+
- An active Azure subscription
25+
- [Azure CLI][04] or [Azure PowerShell][05] installed locally or access to Azure Cloud Shell
26+
- Proper permissions to create resources in your Azure subscription
27+
28+
## Steps to Deploy
29+
30+
These steps walk you through the following tasks:
31+
32+
1. Download and modify the Bicep file
33+
1. Deploy the Azure OpenAI Service
34+
1. Configure the agent to use the deployment
35+
36+
### 1. Download and modify the Bicep file
37+
38+
Download the [main.bicep][07] file from the AIShell repository.
39+
40+
You must modify the parameters at the top of the `./main.bicep` file to include your own values.
41+
Replace the placeholders in angle brackets (`< >`) with your own values.
42+
43+
```bicep
44+
@description('This is the name of your AI Service Account')
45+
param aiserviceaccountname string = '<Insert own account name>'
46+
47+
@description('Custom domain name for the endpoint')
48+
param customDomainName string = '<Insert own unique domain name>'
49+
50+
@description('Name of the deployment')
51+
param modeldeploymentname string = '<Insert own deployment name>'
52+
53+
@description('The model being deployed')
54+
param model string = 'gpt-4'
55+
56+
@description('Version of the model being deployed')
57+
param modelversion string = 'turbo-2024-04-09'
58+
59+
@description('Capacity for specific model used')
60+
param capacity int = 80
61+
62+
@description('Location for all resources.')
63+
param location string = resourceGroup().location
64+
65+
@allowed([
66+
'S0'
67+
])
68+
param sku string = 'S0'
69+
```
70+
71+
For this deployment, the Bicep file uses the following defaults:
72+
73+
- The location of the Azure OpenAI account is set to the location of the resource group
74+
- The AI model is `gpt-4` version `turbo-2024-04-09`
75+
76+
You can change these settings for your particular needs. For more information on available models,
77+
see [Azure OpenAI Service models][01]. You might need to modify the capacity of the deployment based
78+
the model you use. For more information about setting the capacity, see
79+
[Azure OpenAI Service quotas and limits][02].
80+
81+
### 2. Deploy the Azure OpenAI Service
82+
83+
After you modified the Bicep file parameters, you're ready to deploy your own Azure OpenAI
84+
instance. You can use Azure CLI or Azure PowerShell to deploy the Bicep files.
85+
86+
#### Deploy using Azure CLI
87+
88+
Use the following Azure CLI commands to deploy the Azure OpenAI Service. The following commands are
89+
intended to be run in a Bash session. Replace the placeholders in angle brackets (`< >`) with your
90+
own values.
91+
92+
You can run the commands locally or in Azure Cloud Shell. If you run them locally, you must sign in
93+
to your Azure account using `az login` and set the subscription using
94+
`az account set --subscription <subscription name>`.
95+
96+
```azurecli-interactive
97+
az deployment group create \
98+
--resource-group '<resource group name>' \
99+
--template-file ./main.bicep
100+
101+
# Get the endpoint and key of the deployment
102+
az cognitiveservices account show \
103+
--name '<account name>'
104+
--resource-group '<resource group name>' | jq -r .properties.endpoint
105+
106+
az cognitiveservices account keys list \
107+
--name '<account name>' \
108+
--resource-group '<resource group name>' | jq -r .key1
109+
```
110+
111+
#### Deploy using Azure PowerShell
112+
113+
Use the following Azure PowerShell commands to deploy the Azure OpenAI Service. Replace the
114+
placeholders in angle brackets (`< >`) with your own values.
115+
116+
You can run the commands locally or in Azure Cloud Shell. If you run them locally, you must sign in
117+
to your Azure account using `Connect-AzAccount` and set the subscription using
118+
`Set-AzContext -SubscriptionId <subscription id>`.
119+
120+
```azurepowershell-interactive
121+
$AzResourceGroupDeploymentSplat = @{
122+
ResourceGroupName = '<resource group name>'
123+
TemplateFile = './main.bicep'
124+
}
125+
New-AzResourceGroupDeployment @AzResourceGroupDeploymentSplat
126+
127+
# Get the endpoint and key of the deployment
128+
$AzCognitiveServicesAccountSplat = @{
129+
ResourceGroupName = '<resource group name>'
130+
Name = '<account name>'
131+
}
132+
Get-AzCognitiveServicesAccount @AzCognitiveServicesAccountSplat |
133+
Select-Object -Property Endpoint
134+
135+
Get-AzCognitiveServicesAccountKey @AzCognitiveServicesAccountSplat |
136+
Select-Object -Property Key1
137+
```
138+
139+
### 3. Configure the agent to use the deployment
140+
141+
Now that you have the endpoint and key for the deployment, you need to configure the **openai-gpt**
142+
agent. The configuration is stored in a JSON file.
143+
144+
Use the following steps to edit the JSON configuration.
145+
146+
1. Start AIShell and select the `openai-gpt` agent from the list of agents.
147+
1. At the AIShell command prompt, run the `/agent config` command. This command opens the JSON
148+
configuration file.
149+
1. Replace the placeholder values in angle brackets (`< >`) in the JSON file with the endpoint and
150+
key values you obtained from the Azure OpenAI deployment. The following JSON shows an example of
151+
the configuration settings you want to update.
152+
153+
```json
154+
{
155+
// Declare GPT instances.
156+
"GPTs": [
157+
{
158+
"Name": "ps-az-gpt4",
159+
"Description": "<insert description here>",
160+
"Endpoint": "<insert endpoint here>",
161+
"Deployment": "<insert deployment name here>",
162+
"ModelName": "gpt-4",
163+
"Key": "<insert key here>",
164+
"SystemPrompt": "1. You are a helpful and friendly assistant with expertise in PowerShell scripting and command line.\n2. Assume user is using the operating system `osx` unless otherwise specified.\n3. Use the `code block` syntax in markdown to encapsulate any part in responses that is code, YAML, JSON or XML, but not table.\n4. When encapsulating command line code, use '```powershell' if it's PowerShell command; use '```sh' if it's non-PowerShell CLI command.\n5. When generating CLI commands, never ever break a command into multiple lines. Instead, always list all parameters and arguments of the command on the same line.\n6. Please keep the response concise but to the point. Do not overexplain."
165+
}
166+
],
167+
// Specify the default GPT instance to use for user query.
168+
// For example: "ps-az-gpt4"
169+
"Active": "ps-az-gpt4"
170+
}
171+
```
172+
173+
1. Save the JSON file and close the editor.
174+
175+
## Conclusion
176+
177+
You successfully deployed the Azure OpenAI Service and configured your `openai-gpt` agent to
178+
communicate with your deployment. For more information about model training, filters, and settings
179+
for Azure OpenAI deployments, see [Azure OpenAI Service documentation][03].
180+
181+
> [!NOTE]
182+
> We would like to thank Sebastian Jensen for his guidance on how to deploy the Azure OpenAI Service
183+
> using Bicep files. This article was inspired by his blog post on Medium and used with permission.
184+
> Take a moment to read his original post:
185+
> [Deploy an Azure OpenAI service with LLM deployments via Bicep][06].
186+
187+
<!-- link references -->
188+
[01]: /azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-
189+
[02]: /azure/ai-services/openai/quotas-limits
190+
[03]: /azure/cognitive-services/openai/
191+
[04]: /cli/azure/install-azure-cli
192+
[05]: /powershell/azure/install-azure-powershell
193+
[06]: https://medium.com/medialesson/deploy-an-azure-openai-service-with-llm-deployments-via-bicep-244411472d40
194+
[07]: https://raw.githubusercontent.com/PowerShell/AIShell/refs/heads/main/docs/development/AzureOAIDeployment/main.bicep

reference/docs-conceptual/AIShell/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ items:
3131
href: developer/create-ollama-agent.md
3232
- name: Ollama agent README
3333
href: developer/ollama-agent-readme.md
34+
- name: Deploy the Azure OpenAI Service using Bicep
35+
href: developer/deploy-azure-openai.md

0 commit comments

Comments
 (0)