Skip to content

Commit 099a2d2

Browse files
authored
Merge branch 'main' into zavaproductsignite
2 parents 0be4d34 + de6b1ae commit 099a2d2

File tree

10 files changed

+1135
-1105
lines changed

10 files changed

+1135
-1105
lines changed

.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
AZURE_OPENAI_SERVICE="SERVICE-NAME"
2+
AZURE_OPENAI_DEPLOYMENT_NAME=DEPLOYMENT-NAME
3+
AZURE_OPENAI_ADA_DEPLOYMENT=ADA-DEPLOYMENT
4+
AZURE_SEARCH_SERVICE=SEARCH-SERVICE-NAME
5+
AZURE_VISION_ENDPOINT=https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com
6+
AZURE_TENANT_ID=TENANT-ID

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ This repository contains many notebooks that explain how Azure AI Search works,
66

77
1. Run `azd up` on [azure-search-openai-demo](https://github.com/Azure-Samples/azure-search-openai-demo/) with multimodal feature enabled. This will create the necessary resources for the Azure OpenAI, Azure AI Search services, and the Azure AI Vision service.
88

9-
2. Create a .env with these variables, and the values taken from `.azure/ENV-NAME/.env`
9+
2. Create a .env with these variables, with the values taken from `.azure/ENV-NAME/.env` in the azure-search-openai-demo repository.
1010

1111
```shell
1212
AZURE_OPENAI_SERVICE=YOUR-SERVICE-NAME
1313
AZURE_OPENAI_DEPLOYMENT_NAME=YOUR-OPENAI-DEPLOYMENT-NAME
1414
AZURE_OPENAI_EMBEDDING_DEPLOYMENT=YOUR-EMBED-DEPLOYMENT-NAME
1515
AZURE_SEARCH_SERVICE=YOUR-SEARCH-SERVICE-NAME
1616
AZURE_COMPUTERVISION_SERVICE=YOUR-COMPUTERVISION-SERVICE-NAME
17+
AZURE_TENANT_ID=YOUR-TENANT-ID
1718
```
1819

19-
3. Login to your Azure account using either the Azure CLI or the Azure Developer CLI:
20+
3. Login to your Azure account using the Azure CLI. Specify `--tenant-id` if you deployed that repo to a non-default tenant.
2021

2122
```shell
2223
azd auth login
2324
```
2425

25-
4. If you deployed your resource group to a tenant other than your home tenant, set the tenant ID:
26+
4. Create a Python virtual environment or open the project in a container.
2627

2728
```shell
2829
AZURE_TENANT_ID=YOUR-TENANT-ID

azure_ai_search.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": 3,
19+
"execution_count": 1,
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
@@ -26,13 +26,13 @@
2626
"import dotenv\n",
2727
"from azure.search.documents.indexes import SearchIndexClient\n",
2828
"\n",
29-
"dotenv.load_dotenv()\n",
29+
"dotenv.load_dotenv(override=True)\n",
3030
"\n",
3131
"AZURE_SEARCH_SERVICE = os.getenv(\"AZURE_SEARCH_SERVICE\")\n",
3232
"AZURE_SEARCH_ENDPOINT = f\"https://{AZURE_SEARCH_SERVICE}.search.windows.net\"\n",
3333
"\n",
34-
"azure_credential = azure.identity.DefaultAzureCredential()\n",
35-
"index_client = SearchIndexClient(endpoint=AZURE_SEARCH_ENDPOINT, credential=azure_credential)"
34+
"azure_credential = azure.identity.AzureDeveloperCliCredential(tenant_id=os.getenv(\"AZURE_TENANT_ID\"))\n",
35+
"index_client = SearchIndexClient(endpoint=AZURE_SEARCH_ENDPOINT, credential=azure_credential)\n"
3636
]
3737
},
3838
{
@@ -46,16 +46,16 @@
4646
},
4747
{
4848
"cell_type": "code",
49-
"execution_count": 5,
49+
"execution_count": null,
5050
"metadata": {},
5151
"outputs": [
5252
{
5353
"data": {
5454
"text/plain": [
55-
"<azure.search.documents.indexes.models._index.SearchIndex at 0x114201090>"
55+
"<azure.search.documents.indexes.models._index.SearchIndex at 0x138703b90>"
5656
]
5757
},
58-
"execution_count": 5,
58+
"execution_count": 2,
5959
"metadata": {},
6060
"output_type": "execute_result"
6161
}

image_search.ipynb

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 4,
12+
"execution_count": null,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
1616
"import os\n",
1717
"\n",
1818
"import dotenv\n",
19-
"from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n",
19+
"from azure.identity import AzureDeveloperCliCredential, get_bearer_token_provider\n",
2020
"from azure.search.documents import SearchClient\n",
2121
"from azure.search.documents.indexes import SearchIndexClient\n",
2222
"from azure.search.documents.indexes.models import (\n",
@@ -36,8 +36,8 @@
3636
"\n",
3737
"AZURE_SEARCH_SERVICE = os.getenv(\"AZURE_SEARCH_SERVICE\")\n",
3838
"AZURE_SEARCH_ENDPOINT = f\"https://{AZURE_SEARCH_SERVICE}.search.windows.net\"\n",
39-
"AZURE_SEARCH_IMAGES_INDEX = \"images-index\"\n",
40-
"azure_credential = DefaultAzureCredential()\n",
39+
"AZURE_SEARCH_IMAGES_INDEX = \"images-index4\"\n",
40+
"azure_credential = AzureDeveloperCliCredential(tenant_id=os.getenv(\"AZURE_TENANT_ID\"))\n",
4141
"search_client = SearchClient(AZURE_SEARCH_ENDPOINT, AZURE_SEARCH_IMAGES_INDEX, credential=azure_credential)"
4242
]
4343
},
@@ -50,16 +50,16 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 5,
53+
"execution_count": 11,
5454
"metadata": {},
5555
"outputs": [
5656
{
5757
"data": {
5858
"text/plain": [
59-
"<azure.search.documents.indexes.models._index.SearchIndex at 0x120d3efd0>"
59+
"<azure.search.documents.indexes.models._index.SearchIndex at 0x12c3ba910>"
6060
]
6161
},
62-
"execution_count": 5,
62+
"execution_count": 11,
6363
"metadata": {},
6464
"output_type": "execute_result"
6565
}
@@ -94,12 +94,12 @@
9494
"cell_type": "markdown",
9595
"metadata": {},
9696
"source": [
97-
"### Configure Azure Computer Vision multi-modal embeddings API "
97+
"### Configure Azure AI Vision multi-modal embeddings API "
9898
]
9999
},
100100
{
101101
"cell_type": "code",
102-
"execution_count": 6,
102+
"execution_count": 13,
103103
"metadata": {},
104104
"outputs": [],
105105
"source": [
@@ -110,28 +110,27 @@
110110
"from PIL import Image\n",
111111
"\n",
112112
"token_provider = get_bearer_token_provider(azure_credential, \"https://cognitiveservices.azure.com/.default\")\n",
113-
"AZURE_COMPUTERVISION_SERVICE = os.getenv(\"AZURE_COMPUTERVISION_SERVICE\")\n",
114-
"AZURE_COMPUTER_VISION_URL = f\"https://{AZURE_COMPUTERVISION_SERVICE}.cognitiveservices.azure.com/computervision/retrieval\"\n",
113+
"AZURE_VISION_ENDPOINT = os.getenv(\"AZURE_VISION_ENDPOINT\")\n",
114+
"AZURE_AIVISION_URL = f\"{AZURE_VISION_ENDPOINT}/computervision/retrieval\"\n",
115115
"\n",
116116
"def get_model_params():\n",
117-
" return {\"api-version\": \"2023-02-01-preview\", \"modelVersion\": \"latest\"}\n",
117+
" return {\"api-version\": \"2024-02-01\", \"model-version\": \"2023-04-15\"}\n",
118118
"\n",
119119
"def get_auth_headers():\n",
120120
" return {\"Authorization\": \"Bearer \" + token_provider()}\n",
121121
"\n",
122122
"def get_image_embedding(image_file):\n",
123123
" mimetype = mimetypes.guess_type(image_file)[0]\n",
124-
" url = f\"{AZURE_COMPUTER_VISION_URL}:vectorizeImage\"\n",
124+
" url = f\"{AZURE_AIVISION_URL}:vectorizeImage\"\n",
125125
" headers = get_auth_headers()\n",
126126
" headers[\"Content-Type\"] = mimetype\n",
127-
" # add error checking\n",
128127
" response = requests.post(url, headers=headers, params=get_model_params(), data=open(image_file, \"rb\"))\n",
129128
" if response.status_code != 200:\n",
130129
" print(image_file, response.status_code, response.json())\n",
131130
" return response.json()[\"vector\"]\n",
132131
"\n",
133132
"def get_text_embedding(text):\n",
134-
" url = f\"{AZURE_COMPUTER_VISION_URL}:vectorizeText\"\n",
133+
" url = f\"{AZURE_AIVISION_URL}:vectorizeText\"\n",
135134
" return requests.post(url, headers=get_auth_headers(), params=get_model_params(),\n",
136135
" json={\"text\": text}).json()[\"vector\"]"
137136
]
@@ -145,7 +144,7 @@
145144
},
146145
{
147146
"cell_type": "code",
148-
"execution_count": 7,
147+
"execution_count": 14,
149148
"metadata": {},
150149
"outputs": [],
151150
"source": [
@@ -166,7 +165,7 @@
166165
},
167166
{
168167
"cell_type": "code",
169-
"execution_count": 8,
168+
"execution_count": 15,
170169
"metadata": {},
171170
"outputs": [
172171
{
@@ -177,7 +176,7 @@
177176
"<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=640x451>"
178177
]
179178
},
180-
"execution_count": 8,
179+
"execution_count": 15,
181180
"metadata": {},
182181
"output_type": "execute_result"
183182
}
@@ -189,7 +188,7 @@
189188
},
190189
{
191190
"cell_type": "code",
192-
"execution_count": 9,
191+
"execution_count": 16,
193192
"metadata": {},
194193
"outputs": [
195194
{
@@ -213,7 +212,7 @@
213212
},
214213
{
215214
"cell_type": "code",
216-
"execution_count": 10,
215+
"execution_count": 17,
217216
"metadata": {},
218217
"outputs": [
219218
{
@@ -224,7 +223,7 @@
224223
"<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=640x433>"
225224
]
226225
},
227-
"execution_count": 10,
226+
"execution_count": 17,
228227
"metadata": {},
229228
"output_type": "execute_result"
230229
}
@@ -235,7 +234,7 @@
235234
},
236235
{
237236
"cell_type": "code",
238-
"execution_count": 11,
237+
"execution_count": null,
239238
"metadata": {},
240239
"outputs": [
241240
{
@@ -259,7 +258,7 @@
259258
},
260259
{
261260
"cell_type": "code",
262-
"execution_count": 12,
261+
"execution_count": 19,
263262
"metadata": {},
264263
"outputs": [
265264
{
@@ -270,7 +269,7 @@
270269
"<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=640x404>"
271270
]
272271
},
273-
"execution_count": 12,
272+
"execution_count": 19,
274273
"metadata": {},
275274
"output_type": "execute_result"
276275
}

0 commit comments

Comments
 (0)