Skip to content

Commit e31e1cf

Browse files
committed
- Use the mock server only when using OpenAI
1 parent 140ac70 commit e31e1cf

File tree

1 file changed

+77
-60
lines changed

1 file changed

+77
-60
lines changed

03_application_deployment.ipynb

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@
103103
"source": [
104104
"warnings.filterwarnings(\"ignore\", category=DeprecationWarning, module=\"pkg_resources\")\n",
105105
"\n",
106-
"if not os.environ.get(\"OPENAI_API_KEY\"):\n",
106+
"openai_available = os.environ.get(\"OPENAI_API_KEY\")\n",
107+
"\n",
108+
"if not openai_available:\n",
107109
" embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-mpnet-base-v2\")\n",
108110
"else:\n",
109111
" embeddings = OpenAIEmbeddings(model=\"text-embedding-3-small\")\n",
@@ -299,7 +301,7 @@
299301
"# Add the BankingAgent LLM using HF or OpenAI (if OPENAI credentials)\n",
300302
"MRS_banking_agent = ModelRunnerStep(name=\"banking-agent\")\n",
301303
"\n",
302-
"if not os.environ.get(\"OPENAI_API_KEY\"):\n",
304+
"if not openai_available:\n",
303305
" MRS_banking_agent.add_model(\n",
304306
" model_class=\"BankingAgentHuggingFace\",\n",
305307
" endpoint_name=\"BankingAgentHuggingFace\",\n",
@@ -346,11 +348,20 @@
346348
"outputs": [],
347349
"execution_count": null
348350
},
351+
{
352+
"metadata": {},
353+
"cell_type": "markdown",
354+
"source": "### Since running the LLM model is very resource demanding some systems can't run it locally so we will use the mock server only with OpenAI",
355+
"id": "294bec722b745a15"
356+
},
349357
{
350358
"cell_type": "code",
351359
"id": "a7b33baa-d143-49a9-8007-6bade49b6813",
352360
"metadata": {},
353-
"source": "mock = agent_graph.to_mock_server()",
361+
"source": [
362+
"if openai_available:\n",
363+
" mock = agent_graph.to_mock_server()"
364+
],
354365
"outputs": [],
355366
"execution_count": null
356367
},
@@ -389,15 +400,16 @@
389400
"id": "a8f936c3-2776-4b4c-b18e-184a94fc4c8d",
390401
"metadata": {},
391402
"source": [
392-
"resp = mock.test(\n",
393-
" path=\"/\",\n",
394-
" body={\n",
395-
" \"name\": \"John\",\n",
396-
" \"inputs\": [_format_question(\"What is a mortgage, from the bank?\")],\n",
397-
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
398-
" },\n",
399-
")\n",
400-
"print(resp[\"outputs\"][0])"
403+
"if openai_available:\n",
404+
" resp = mock.test(\n",
405+
" path=\"/\",\n",
406+
" body={\n",
407+
" \"name\": \"John\",\n",
408+
" \"inputs\": [_format_question(\"What is a mortgage, from the bank?\")],\n",
409+
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
410+
" },\n",
411+
" )\n",
412+
" print(resp[\"outputs\"][0])"
401413
],
402414
"outputs": [],
403415
"execution_count": null
@@ -415,15 +427,16 @@
415427
"id": "6406eeea-1849-4aab-b6f0-a7e1d1f18138",
416428
"metadata": {},
417429
"source": [
418-
"resp = mock.test(\n",
419-
" path=\"/\",\n",
420-
" body={\n",
421-
" \"name\": \"John\",\n",
422-
" \"inputs\": [_format_question(\"i hate you\")],\n",
423-
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
424-
" },\n",
425-
")\n",
426-
"print(resp[\"outputs\"][0])"
430+
"if openai_available:\n",
431+
" resp = mock.test(\n",
432+
" path=\"/\",\n",
433+
" body={\n",
434+
" \"name\": \"John\",\n",
435+
" \"inputs\": [_format_question(\"i hate you\")],\n",
436+
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
437+
" },\n",
438+
" )\n",
439+
" print(resp[\"outputs\"][0])"
427440
],
428441
"outputs": [],
429442
"execution_count": null
@@ -449,15 +462,16 @@
449462
"id": "93faf1a7-48d4-46c5-8571-03b90d2ce7b9",
450463
"metadata": {},
451464
"source": [
452-
"resp = mock.test(\n",
453-
" path=\"/\",\n",
454-
" body={\n",
455-
" \"name\": \"John\",\n",
456-
" \"inputs\": [_format_question(\"how to apply for checking account?\")],\n",
457-
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
458-
" },\n",
459-
")\n",
460-
"print(resp[\"outputs\"][0])"
465+
"if openai_available:\n",
466+
" resp = mock.test(\n",
467+
" path=\"/\",\n",
468+
" body={\n",
469+
" \"name\": \"John\",\n",
470+
" \"inputs\": [_format_question(\"how to apply for checking account?\")],\n",
471+
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
472+
" },\n",
473+
" )\n",
474+
" print(resp[\"outputs\"][0])"
461475
],
462476
"outputs": [],
463477
"execution_count": null
@@ -475,19 +489,20 @@
475489
"id": "91d0ebe4-9c8c-4463-857e-1cd61ea42a1e",
476490
"metadata": {},
477491
"source": [
478-
"resp = mock.test(\n",
479-
" path=\"/\",\n",
480-
" body={\n",
481-
" \"name\": \"John\",\n",
482-
" \"inputs\": [\n",
483-
" _format_question(\n",
484-
" \"how to apply for checking account? I keep trying but I'm really frustrated\"\n",
485-
" )\n",
486-
" ],\n",
487-
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
488-
" },\n",
489-
")\n",
490-
"print(resp[\"outputs\"][0])"
492+
"if openai_available:\n",
493+
" resp = mock.test(\n",
494+
" path=\"/\",\n",
495+
" body={\n",
496+
" \"name\": \"John\",\n",
497+
" \"inputs\": [\n",
498+
" _format_question(\n",
499+
" \"how to apply for checking account? I keep trying but I'm really frustrated\"\n",
500+
" )\n",
501+
" ],\n",
502+
" \"user_id\": LOW_PROPENSITY_CHURN_USER_ID,\n",
503+
" },\n",
504+
" )\n",
505+
" print(resp[\"outputs\"][0])"
491506
],
492507
"outputs": [],
493508
"execution_count": null
@@ -513,22 +528,23 @@
513528
"id": "79d62a7c-02d7-41cc-8b23-a8a418284db3",
514529
"metadata": {},
515530
"source": [
516-
"resp = mock.test(\n",
517-
" path=\"/\",\n",
518-
" body={\n",
519-
" \"name\": \"Alice\",\n",
520-
" \"inputs\": [\n",
521-
" {\"role\": \"user\", \"content\": \"Hi—how do I open a checking account?\"},\n",
522-
" {\n",
523-
" \"role\": \"assistant\",\n",
524-
" \"content\": \"To open a checking account, you need two forms of ID and a minimum deposit of $25.\",\n",
525-
" },\n",
526-
" {\"role\": \"user\", \"content\": \"Is it possible to get cashback rewards?\"},\n",
527-
" ],\n",
528-
" \"user_id\": HIGH_PROPENSITY_CHURN_USER_ID, # <-- High churn propensity user\n",
529-
" },\n",
530-
")\n",
531-
"print(resp[\"outputs\"][0])"
531+
"if openai_available:\n",
532+
" resp = mock.test(\n",
533+
" path=\"/\",\n",
534+
" body={\n",
535+
" \"name\": \"Alice\",\n",
536+
" \"inputs\": [\n",
537+
" {\"role\": \"user\", \"content\": \"Hi—how do I open a checking account?\"},\n",
538+
" {\n",
539+
" \"role\": \"assistant\",\n",
540+
" \"content\": \"To open a checking account, you need two forms of ID and a minimum deposit of $25.\",\n",
541+
" },\n",
542+
" {\"role\": \"user\", \"content\": \"Is it possible to get cashback rewards?\"},\n",
543+
" ],\n",
544+
" \"user_id\": HIGH_PROPENSITY_CHURN_USER_ID, # <-- High churn propensity user\n",
545+
" },\n",
546+
" )\n",
547+
" print(resp[\"outputs\"][0])"
532548
],
533549
"outputs": [],
534550
"execution_count": null
@@ -548,7 +564,8 @@
548564
"id": "24825160-fb6a-4852-b357-accd6106c033",
549565
"metadata": {},
550566
"source": [
551-
"resp"
567+
"if openai_available:\n",
568+
" resp"
552569
],
553570
"outputs": [],
554571
"execution_count": null

0 commit comments

Comments
 (0)