Skip to content

Commit d1e1c50

Browse files
committed
CI fix
1 parent 20cf640 commit d1e1c50

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

python-recipes/semantic-cache/03_context_enabled_semantic_caching.ipynb

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
},
226226
{
227227
"cell_type": "code",
228-
"execution_count": 14,
228+
"execution_count": null,
229229
"metadata": {
230230
"id": "ZnqjGneBDFol"
231231
},
@@ -242,6 +242,17 @@
242242
"💡 Make sure 'gpt-4o' and 'gpt-4o-mini' models are deployed in your Azure Foundry.\n",
243243
"\n"
244244
]
245+
},
246+
{
247+
"ename": "",
248+
"evalue": "",
249+
"output_type": "error",
250+
"traceback": [
251+
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
252+
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
253+
"\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
254+
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
255+
]
245256
}
246257
],
247258
"source": [
@@ -261,36 +272,41 @@
261272
" pass\n",
262273
" return os.getenv(secret_name)\n",
263274
"\n",
264-
"# 🔐 Determine whether to use Azure OpenAI from environment variables.\n",
265-
"# Set USE_AZURE=true in your .env file to use Azure. Defaults to OpenAI if not set or false.\n",
266-
"use_azure = input(\"Use Azure OpenAI? (y/n): \").strip().lower() == \"y\"\n",
275+
"# 🔐 Determine whether to use Azure OpenAI (non-interactive friendly)\n",
276+
"# Precedence order:\n",
277+
"# 1. Explicit USE_AZURE env var\n",
278+
"# 2. If Azure endpoint + key present, infer Azure\n",
279+
"# 3. Fallback to OpenAI\n",
280+
"use_azure_env = os.getenv(\"USE_AZURE\")\n",
281+
"if use_azure_env is not None:\n",
282+
" use_azure = use_azure_env.strip().lower() in [\"1\", \"true\", \"t\", \"y\", \"yes\"]\n",
283+
"else:\n",
284+
" inferred = os.getenv(\"AZURE_OPENAI_ENDPOINT\") and os.getenv(\"AZURE_OPENAI_API_KEY\")\n",
285+
" use_azure = bool(inferred)\n",
267286
"\n",
268287
"if use_azure:\n",
269-
" print(\"🔒 Azure OpenAI selected (based on USE_AZURE environment variable).\")\n",
270-
" print(\"📌 Please ensure the following secrets are added via the 🔐 Colab > Secrets menu or as environment variables:\")\n",
288+
" print(\"🔒 Azure OpenAI selected (env-based or inferred).\")\n",
289+
" print(\"📌 Expecting:\")\n",
271290
" print(\"- AZURE_OPENAI_API_KEY\")\n",
272291
" print(\"- AZURE_OPENAI_ENDPOINT (e.g. https://your-resource.openai.azure.com)\")\n",
273-
" print(\"- AZURE_OPENAI_API_VERSION (e.g. 2024-05-01-preview)\")\n",
274-
" print(\"💡 Make sure 'gpt-4o' and 'gpt-4o-mini' models are deployed in your Azure Foundry.\\n\")\n",
292+
" print(\"- AZURE_OPENAI_API_VERSION (e.g. 2024-05-01-preview)\\n\")\n",
275293
"\n",
276-
" os.environ[\"AZURE_OPENAI_API_KEY\"] = get_secret(\"AZURE_OPENAI_API_KEY\")\n",
277-
" os.environ[\"AZURE_OPENAI_ENDPOINT\"] = get_secret(\"AZURE_OPENAI_ENDPOINT\")\n",
278-
" os.environ[\"AZURE_OPENAI_API_VERSION\"] = get_secret(\"AZURE_OPENAI_API_VERSION\")\n",
294+
" os.environ[\"AZURE_OPENAI_API_KEY\"] = get_secret(\"AZURE_OPENAI_API_KEY\") or \"\"\n",
295+
" os.environ[\"AZURE_OPENAI_ENDPOINT\"] = get_secret(\"AZURE_OPENAI_ENDPOINT\") or \"\"\n",
296+
" os.environ[\"AZURE_OPENAI_API_VERSION\"] = get_secret(\"AZURE_OPENAI_API_VERSION\") or \"2024-05-01-preview\"\n",
279297
"\n",
280298
" # Optional model deployment names\n",
281299
" os.environ.setdefault(\"AZURE_OPENAI_MODEL_GPT4\", \"gpt-4o\")\n",
282300
" os.environ.setdefault(\"AZURE_OPENAI_MODEL_GPT4_MINI\", \"gpt-4o-mini\")\n",
283-
"\n",
284301
"else:\n",
285-
" print(\"🔒 OpenAI selected (default or USE_AZURE is not 'true').\")\n",
286-
" print(\"📌 Please ensure the following secret is added via the 🔐 Colab > Secrets menu or as an environment variable:\")\n",
287-
" print(\"- OPENAI_API_KEY\\n\")\n",
302+
" print(\"🔒 OpenAI selected (default). Set USE_AZURE=true or provide Azure env vars to switch.\")\n",
303+
" print(\"📌 Expecting: OPENAI_API_KEY\\n\")\n",
288304
"\n",
289-
" os.environ[\"OPENAI_API_KEY\"] = get_secret(\"OPENAI_API_KEY\")\n",
305+
" os.environ[\"OPENAI_API_KEY\"] = get_secret(\"OPENAI_API_KEY\") or \"\"\n",
290306
"\n",
291307
" # Optional model names (if using gpt-4o via OpenAI)\n",
292308
" os.environ.setdefault(\"OPENAI_MODEL_GPT4\", \"gpt-4o\")\n",
293-
" os.environ.setdefault(\"OPENAI_MODEL_GPT4_MINI\", \"gpt-4o-mini\")"
309+
" os.environ.setdefault(\"OPENAI_MODEL_GPT4_MINI\", \"gpt-4o-mini\")\n"
294310
]
295311
},
296312
{

0 commit comments

Comments
 (0)