-
Notifications
You must be signed in to change notification settings - Fork 169
/
create-azure-openai-resources.sh
executable file
·196 lines (173 loc) · 6.92 KB
/
create-azure-openai-resources.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash -e
# Display help
help() {
echo "This script creates the Azure OpenAI resources"
echo "It assumes you have the the following utilities installed on your machine:"
echo " 1) The Azure CLI (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)"
echo " 2) jq (https://stedolan.github.io/jq)"
echo
echo "Additionally, it assumes you are already logged into your Azure environment via the Azure CLI."
echo
echo "Syntax: create-azure-openai-resources.sh [options]"
echo "options:"
echo " -c <cognitive_service_name> Name of the Azure Cognitive service"
echo " Default: 'cs-super-heroes'"
echo " -d <cognitive_service_deployment_name> Name of the Azure Cognitive service deployment for the chat model"
echo " Default: 'csdeploy-super-heroes'"
echo " -g <resource_group_name> Name of the Azure resource group to use to deploy resources"
echo " Default: 'rg-super-heroes'"
echo " -h Prints this help message"
echo " -i <image_model> The image model to use"
echo " Default: dall-e-3"
echo " -l <location> The location (region) to deploy resources into"
echo " Default: 'eastus'"
echo " -m <model> The model to use"
echo " Default: 'gpt-35-turbo'"
echo " -t <tag> The tag to use when creating resources"
echo " Default: 'super-heroes'"
echo " -u <unique_identifier> A unique identifier to append to some resources. Some Azure services require unique names within a region (across users)."
echo " Default is to use the output of the 'whoami' command."
echo " -v <chat_model_version> The chat model version to use"
echo " Default: '0613'"
}
exit_abnormal() {
echo
help
exit 1
}
# Define defaults
COGNITIVE_SERVICE="cs-super-heroes"
COGNITIVE_DEPLOYMENT="csdeploy-super-heroes"
RESOURCE_GROUP="rg-super-heroes"
LOCATION="eastus"
TAG="super-heroes"
CHAT_MODEL="gpt-35-turbo"
CHAT_MODEL_VERSION="0613"
IMAGE_MODEL="dall-e-3"
IMAGE_MODEL_VERSION="3.0"
UNIQUE_IDENTIFIER=$(whoami)
# Process the input options
while getopts "c:d:g:hi:m:l:t:u:v:" option; do
case $option in
c) COGNITIVE_SERVICE=$OPTARG
;;
d) COGNITIVE_DEPLOYMENT=$OPTARG
;;
g) RESOURCE_GROUP=$OPTARG
;;
h) help
exit
;;
i) IMAGE_MODEL=$OPTARG
;;
l) LOCATION=$OPTARG
;;
m) CHAT_MODEL=$OPTARG
;;
v) CHAT_MODEL_VERSION=$OPTARG
;;
t) TAG=$OPTARG
;;
u) UNIQUE_IDENTIFIER=$OPTARG
;;
*) exit_abnormal
;;
esac
done
# Now run the script
echo "Creating Azure OpenAI Resources with the following configuration:"
echo " Cognitive Service Name: $COGNITIVE_SERVICE"
echo " Cognitive Service Deployment: $COGNITIVE_DEPLOYMENT"
echo " Image Model: $IMAGE_MODEL"
echo " Resource Group: $RESOURCE_GROUP"
echo " Location: $LOCATION"
echo " Chat Model: $CHAT_MODEL"
echo " Chat Model Version: $CHAT_MODEL_VERSION"
echo " Tag: $TAG"
echo " Unique Identifier: $UNIQUE_IDENTIFIER"
echo
echo "Please be patient. This may take several minutes."
COGNITIVE_SERVICE="${COGNITIVE_SERVICE}-${UNIQUE_IDENTIFIER}"
COGNITIVE_DEPLOYMENT="${COGNITIVE_DEPLOYMENT}-${UNIQUE_IDENTIFIER}"
IMAGE_MODEL_DEPLOYMENT="${IMAGE_MODEL}-${UNIQUE_IDENTIFIER}"
# Create resource group
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $RESOURCE_GROUP resource group in the $LOCATION location"
echo "-----------------------------------------"
az group create \
--name "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG"
echo
# Create cognitive service
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $COGNITIVE_SERVICE cognitive service"
echo "-----------------------------------------"
az cognitiveservices account create \
--name "$COGNITIVE_SERVICE" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--custom-domain "$COGNITIVE_SERVICE" \
--tags system="$TAG" \
--kind OpenAI \
--sku S0 \
--yes
# Deploy the models
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Deploying the $COGNITIVE_DEPLOYMENT model"
echo "-----------------------------------------"
az cognitiveservices account deployment create \
--name "$COGNITIVE_SERVICE" \
--resource-group "$RESOURCE_GROUP" \
--deployment-name "$COGNITIVE_DEPLOYMENT" \
--model-name "$CHAT_MODEL" \
--model-version "$CHAT_MODEL_VERSION" \
--model-format OpenAI \
--sku-name Standard \
--sku-capacity 1
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Deploying the $IMAGE_MODEL_DEPLOYMENT model"
echo "-----------------------------------------"
az cognitiveservices account deployment create \
--name "$COGNITIVE_SERVICE" \
--resource-group "$RESOURCE_GROUP" \
--deployment-name "$IMAGE_MODEL_DEPLOYMENT" \
--model-name "$IMAGE_MODEL" \
--model-version "$IMAGE_MODEL_VERSION" \
--model-format OpenAI \
--sku-name Standard \
--sku-capacity 1
# Get keys
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Getting keys"
echo "-----------------------------------------"
AZURE_OPENAI_KEY=$(
az cognitiveservices account keys list \
--name "$COGNITIVE_SERVICE" \
--resource-group "$RESOURCE_GROUP" \
| jq -r .key1
)
echo
echo "Azure OpenAI deployment took $SECONDS seconds to complete."
echo
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: All services have been deployed"
echo "-----------------------------------------"
echo "Here are some key values you may need to use in your application's configuration:"
echo
echo "API key: $AZURE_OPENAI_KEY"
echo "Resource Name: $COGNITIVE_SERVICE"
echo "Deployment Name/Id: $COGNITIVE_DEPLOYMENT"
echo "Image Model Deployment Name/Id: $IMAGE_MODEL_DEPLOYMENT"
echo
echo "As environment variables:"
echo "QUARKUS_LANGCHAIN4J_AZURE_OPENAI_API_KEY=$AZURE_OPENAI_KEY"
echo "QUARKUS_LANGCHAIN4J_AZURE_OPENAI_RESOURCE_NAME=$COGNITIVE_SERVICE"
echo "QUARKUS_LANGCHAIN4J_AZURE_OPENAI_DEPLOYMENT_NAME=$COGNITIVE_DEPLOYMENT"
echo "QUARKUS_LANGCHAIN4J_AZURE_OPENAI_DALLE3_DEPLOYMENT_NAME=$IMAGE_MODEL_DEPLOYMENT"
echo
echo "As JVM parameters:"
echo "-Dquarkus.langchain4j.azure-openai.api-key=$AZURE_OPENAI_KEY"
echo "-Dquarkus.langchain4j.azure-openai.resource-name=$COGNITIVE_SERVICE"
echo "-Dquarkus.langchain4j.azure-openai.deployment-name=$COGNITIVE_DEPLOYMENT"
echo "-Dquarkus.langchain4j.azure-openai.dalle3.deployment-name=$IMAGE_MODEL_DEPLOYMENT"