Skip to content

Commit 0b9e11d

Browse files
committed
Adds LangServe as an alternative backendAPI
1 parent 5e3edd3 commit 0b9e11d

32 files changed

+3051
-669
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ data/
1212
credentials.env
1313
.azure/
1414
.vscode/
15-
infra/target/
15+
infra/target/
16+
**/__pycache__/

03-Quering-AOpenAI.ipynb

+95-127
Large diffs are not rendered by default.

08-SQLDB_QA.ipynb

+46-54
Large diffs are not rendered by default.

11-Smart_Agent.ipynb

+183-181
Large diffs are not rendered by default.

12-Building-Apps.ipynb

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "1ccf7ea5-1abe-4401-a8c7-64bbfc057425",
66
"metadata": {},
77
"source": [
8-
"# Building the Backend and Frontend Applications"
8+
"# Building the Bot Service Backend and Frontend Applications"
99
]
1010
},
1111
{
@@ -15,11 +15,12 @@
1515
"source": [
1616
"In the previous notebook, we assembled all the functions and code required to create a robust Agent/Bot. Depending on the user's question, this Agent/Bot searches for answers in the available sources and tools.\n",
1717
"\n",
18-
"However, the question arises: **\"How can we integrate this code into a Bot application capable of supporting multiple channel deployments?\"** Our ideal scenario involves building the bot once and deploying it across various channels such as MS Teams, Web Chat, Slack, Alexa, Outlook, WhatsApp, Line, Facebook, and more.\n",
18+
"However, the question arises: **\"How can we integrate this code into a Bot backend application capable of supporting multiple channel deployments?\"** Our ideal scenario involves building the bot once and deploying it across various channels such as MS Teams, Web Chat, Slack, Alexa, Outlook, WhatsApp, Line, Facebook, and more.\n",
19+
"\n",
1920
"\n",
2021
"To achieve this, we need a service that not only aids in building the bot as an API but also facilitates the exposure of this API to multiple channels. This service is known as <u>Azure Bot Framework</u>.\n",
2122
"\n",
22-
"In this notebook, you will learn how to deploy the code you have developed so far as a Bot API using the Bot Framework API and Service."
23+
"In this notebook, you will learn how to deploy the code you have developed so far as a Bot API using the Bot Framework API and Service.<br>"
2324
]
2425
},
2526
{
@@ -91,19 +92,19 @@
9192
"All the functions and prompts used in the prior notebook to create our brain Agent are located in `utils.py` and `prompts.py` respectively.\n",
9293
"So, what needs to be done is, basically, to do the same we did in the prior notebook but within the Bot Framework Python SDK classes.\n",
9394
"\n",
94-
"Within the `apps/backend/` folder, you will find three files: `app.py`, `bot.py` and `config.py`.\n",
95+
"Within the `apps/backend/botservice/` folder, you will find three files: `app.py`, `bot.py` and `config.py`.\n",
9596
"- `app.py`: is the entrance main point to the application.\n",
9697
"- `bot.py`: is where our OpenAI-related code resides \n",
9798
"- `config.py`: declares the PORT the API will listen from and the App Service Principal var names\n",
9899
"\n",
99100
"We would only need to deal with `bot.py`, here is where all the logic code related to your Azure OpenAI application lives.\n",
100101
"\n",
101-
"in `apps/backend/README.md` you will find all the instructions on how to:\n",
102+
"in `apps/backend/botservice/README.md` you will find all the instructions on how to:\n",
102103
"1) Deploy the Azure web services: Azure Web App and Azure Bot Service\n",
103104
"2) Zip the code and uploaded to the Azure Web App\n",
104105
"3) Test your Bot API using the Bot Service in the Azure portal\n",
105106
"\n",
106-
"GO AHEAD NOW AND FOLLOW THE INSTRUCTIONS in `apps/backend/README.md`"
107+
"GO AHEAD NOW AND FOLLOW THE INSTRUCTIONS in `apps/backend/botservice/README.md`"
107108
]
108109
},
109110
{

13-Using-BotServiceAPI.ipynb 13-BotService-API.ipynb

+11-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": 64,
25+
"execution_count": 1,
2626
"id": "e6404ca7-5a5f-4b66-b341-211a394810ed",
2727
"metadata": {},
2828
"outputs": [],
@@ -68,39 +68,31 @@
6868
},
6969
{
7070
"cell_type": "code",
71-
"execution_count": 66,
71+
"execution_count": null,
7272
"id": "9c1c82bb-206e-4023-be95-d79b7ccfb71b",
7373
"metadata": {},
74-
"outputs": [
75-
{
76-
"name": "stdout",
77-
"output_type": "stream",
78-
"text": [
79-
"Converstion id: KN7Fy9TZ00q8eFj41WsE5Q-au\n",
80-
"CPU times: user 118 ms, sys: 799 µs, total: 119 ms\n",
81-
"Wall time: 21.6 s\n"
82-
]
83-
}
84-
],
74+
"outputs": [],
8575
"source": [
8676
"%%time\n",
8777
"\n",
8878
"# Simple workflow\n",
8979
"start_conversation_url = f\"{base_url}/conversations\"\n",
90-
"get_activities_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
9180
"\n",
9281
"# 1- Start a conversation\n",
9382
"headers = {\"Authorization\": f\"Bearer {direct_line_secret}\"}\n",
9483
"response = requests.post(start_conversation_url, headers=headers)\n",
9584
"conversation_id = response.json()[\"conversationId\"]\n",
9685
"print('Converstion id:', conversation_id)\n",
9786
"\n",
87+
"get_activities_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
88+
"\n",
89+
"\n",
9890
"# 2 - Send a message to the bot\n",
9991
"send_message_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
10092
"message = {\n",
10193
" \"type\": \"message\",\n",
10294
" \"from\": {\"id\": \"user\"},\n",
103-
" \"text\": \"what CLP?\"\n",
95+
" \"text\": \"what is CLP?\"\n",
10496
"}\n",
10597
"\n",
10698
"response = requests.post(send_message_url, headers=headers, json=message)\n",
@@ -258,7 +250,7 @@
258250
"\n",
259251
"\n",
260252
"# Main function to send a question to the bot and print responses.\n",
261-
"async def check_activities_and_send_question(base_url, bot_id, conversation_id, headers, question, timeout=30):\n",
253+
"async def send_question_and_check_activities(base_url, bot_id, conversation_id, headers, question, timeout=30):\n",
262254
" # Send the initial question to the bot.\n",
263255
" await send_message(base_url, conversation_id, headers, question)\n",
264256
" \n",
@@ -392,7 +384,7 @@
392384
}
393385
],
394386
"source": [
395-
"await check_activities_and_send_question(base_url, bot_id, conversation_id, headers, QUESTION, timeout=timeout)"
387+
"await send_question_and_check_activities(base_url, bot_id, conversation_id, headers, QUESTION, timeout=timeout)"
396388
]
397389
},
398390
{
@@ -462,7 +454,7 @@
462454
}
463455
],
464456
"source": [
465-
"await check_activities_and_send_question(base_url, bot_id, conversation_id, headers, FOLLOWUP_QUESTION, timeout=timeout)"
457+
"await send_question_and_check_activities(base_url, bot_id, conversation_id, headers, FOLLOWUP_QUESTION, timeout=timeout)"
466458
]
467459
},
468460
{
@@ -500,7 +492,7 @@
500492
"source": [
501493
"# NEXT\n",
502494
"\n",
503-
"(Coming Soon) - In our next notebook, we will venture into creating a different type of Backend API, this time utilizing FastAPI and LangServe. This approach will also enable us to incorporate streaming capabilities."
495+
"In the next notebook, we will venture into creating a different type of Backend API, this time utilizing FastAPI and LangServe. This approach will also enable us to incorporate streaming capabilities."
504496
]
505497
},
506498
{

0 commit comments

Comments
 (0)