Skip to content

Commit

Permalink
Adds LangServe as an alternative backendAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomarin committed Apr 5, 2024
1 parent 5e3edd3 commit 0b9e11d
Show file tree
Hide file tree
Showing 32 changed files with 3,051 additions and 669 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data/
credentials.env
.azure/
.vscode/
infra/target/
infra/target/
**/__pycache__/
222 changes: 95 additions & 127 deletions 03-Quering-AOpenAI.ipynb

Large diffs are not rendered by default.

100 changes: 46 additions & 54 deletions 08-SQLDB_QA.ipynb

Large diffs are not rendered by default.

364 changes: 183 additions & 181 deletions 11-Smart_Agent.ipynb

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions 12-Building-Apps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "1ccf7ea5-1abe-4401-a8c7-64bbfc057425",
"metadata": {},
"source": [
"# Building the Backend and Frontend Applications"
"# Building the Bot Service Backend and Frontend Applications"
]
},
{
Expand All @@ -15,11 +15,12 @@
"source": [
"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",
"\n",
"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",
"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",
"\n",
"\n",
"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",
"\n",
"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."
"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>"
]
},
{
Expand Down Expand Up @@ -91,19 +92,19 @@
"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",
"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",
"\n",
"Within the `apps/backend/` folder, you will find three files: `app.py`, `bot.py` and `config.py`.\n",
"Within the `apps/backend/botservice/` folder, you will find three files: `app.py`, `bot.py` and `config.py`.\n",
"- `app.py`: is the entrance main point to the application.\n",
"- `bot.py`: is where our OpenAI-related code resides \n",
"- `config.py`: declares the PORT the API will listen from and the App Service Principal var names\n",
"\n",
"We would only need to deal with `bot.py`, here is where all the logic code related to your Azure OpenAI application lives.\n",
"\n",
"in `apps/backend/README.md` you will find all the instructions on how to:\n",
"in `apps/backend/botservice/README.md` you will find all the instructions on how to:\n",
"1) Deploy the Azure web services: Azure Web App and Azure Bot Service\n",
"2) Zip the code and uploaded to the Azure Web App\n",
"3) Test your Bot API using the Bot Service in the Azure portal\n",
"\n",
"GO AHEAD NOW AND FOLLOW THE INSTRUCTIONS in `apps/backend/README.md`"
"GO AHEAD NOW AND FOLLOW THE INSTRUCTIONS in `apps/backend/botservice/README.md`"
]
},
{
Expand Down
30 changes: 11 additions & 19 deletions 13-Using-BotServiceAPI.ipynb → 13-BotService-API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 1,
"id": "e6404ca7-5a5f-4b66-b341-211a394810ed",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -68,39 +68,31 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": null,
"id": "9c1c82bb-206e-4023-be95-d79b7ccfb71b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Converstion id: KN7Fy9TZ00q8eFj41WsE5Q-au\n",
"CPU times: user 118 ms, sys: 799 µs, total: 119 ms\n",
"Wall time: 21.6 s\n"
]
}
],
"outputs": [],
"source": [
"%%time\n",
"\n",
"# Simple workflow\n",
"start_conversation_url = f\"{base_url}/conversations\"\n",
"get_activities_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
"\n",
"# 1- Start a conversation\n",
"headers = {\"Authorization\": f\"Bearer {direct_line_secret}\"}\n",
"response = requests.post(start_conversation_url, headers=headers)\n",
"conversation_id = response.json()[\"conversationId\"]\n",
"print('Converstion id:', conversation_id)\n",
"\n",
"get_activities_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
"\n",
"\n",
"# 2 - Send a message to the bot\n",
"send_message_url = f\"{base_url}/conversations/{conversation_id}/activities\"\n",
"message = {\n",
" \"type\": \"message\",\n",
" \"from\": {\"id\": \"user\"},\n",
" \"text\": \"what CLP?\"\n",
" \"text\": \"what is CLP?\"\n",
"}\n",
"\n",
"response = requests.post(send_message_url, headers=headers, json=message)\n",
Expand Down Expand Up @@ -258,7 +250,7 @@
"\n",
"\n",
"# Main function to send a question to the bot and print responses.\n",
"async def check_activities_and_send_question(base_url, bot_id, conversation_id, headers, question, timeout=30):\n",
"async def send_question_and_check_activities(base_url, bot_id, conversation_id, headers, question, timeout=30):\n",
" # Send the initial question to the bot.\n",
" await send_message(base_url, conversation_id, headers, question)\n",
" \n",
Expand Down Expand Up @@ -392,7 +384,7 @@
}
],
"source": [
"await check_activities_and_send_question(base_url, bot_id, conversation_id, headers, QUESTION, timeout=timeout)"
"await send_question_and_check_activities(base_url, bot_id, conversation_id, headers, QUESTION, timeout=timeout)"
]
},
{
Expand Down Expand Up @@ -462,7 +454,7 @@
}
],
"source": [
"await check_activities_and_send_question(base_url, bot_id, conversation_id, headers, FOLLOWUP_QUESTION, timeout=timeout)"
"await send_question_and_check_activities(base_url, bot_id, conversation_id, headers, FOLLOWUP_QUESTION, timeout=timeout)"
]
},
{
Expand Down Expand Up @@ -500,7 +492,7 @@
"source": [
"# NEXT\n",
"\n",
"(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."
"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."
]
},
{
Expand Down
Loading

0 comments on commit 0b9e11d

Please sign in to comment.