Skip to content

Commit

Permalink
Improvements in Notebook 13
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomarin committed Mar 21, 2024
1 parent fd041c4 commit 5e3edd3
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
127 changes: 126 additions & 1 deletion 13-Using-BotServiceAPI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 64,
"id": "e6404ca7-5a5f-4b66-b341-211a394810ed",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -50,6 +50,131 @@
"timeout = 25"
]
},
{
"cell_type": "markdown",
"id": "ab42e7b7-3412-49b7-a090-8b52b5d6851a",
"metadata": {},
"source": [
"Regarding the Bot Service Direct Line channel, there are two primary endpoints of interest:\n",
"\n",
"- `{base_url}/conversations`: Initiates the conversation and provides the conversation ID.\n",
"- `{base_url}/conversations/{conversation_id}/activities`: Asynchronously returns every activity occurring within the bot.\n",
"\n",
"The fundamental workflow involves:\n",
"1) Initiating a new conversation by utilizing the `/conversations` endpoint.\n",
"2) Sending messages through the `/conversations/{conversation_id}/activities` endpoint.\n",
"3) Periodically polling the `/conversations/{conversation_id}/activities` endpoint to retrieve responses, errors, and other relevant activities.\n"
]
},
{
"cell_type": "code",
"execution_count": 66,
"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"
]
}
],
"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",
"# 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",
"}\n",
"\n",
"response = requests.post(send_message_url, headers=headers, json=message)\n",
"\n",
"# 3 - Wait a bit and Get Activities\n",
"time.sleep(5)\n",
"response = requests.get(get_activities_url, headers=headers)\n",
"activities = response.json()[\"activities\"]"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "1ebc13c0-10b1-42c0-9280-89b237634825",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'message',\n",
" 'id': 'K91YF9vkrciAukcn2dkrGr-au|0000000',\n",
" 'timestamp': '2024-03-21T16:03:10.8426002Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-zf4fwhz3gdn64', 'name': 'BotId-zf4fwhz3gdn64'},\n",
" 'conversation': {'id': 'K91YF9vkrciAukcn2dkrGr-au'},\n",
" 'text': '\\nHello and welcome! 👋\\n\\nMy name is Jarvis, a smart virtual assistant designed to assist you.\\nHere\\'s how you can interact with me:\\n\\nI have various plugins and tools at my disposal to answer your questions effectively. Here are the available options:\\n\\n1. 🌐 **bing**: This tool allows me to access the internet and provide current information from the web.\\n\\n2. 💡 **chatgpt**: With this tool, I can draw upon my own knowledge based on the data I was trained on. Please note that my training data goes up until 2021.\\n\\n3. 🔍 **docsearch**: This tool allows me to search a specialized search engine index. It includes 10,000 ArXiv computer science documents from 2020-2021 and 90,000 Covid research articles from the same years.\\n\\n4. 📖 **booksearch**: This tool allows me to search on 5 specific books: Rich Dad Poor Dad, Made to Stick, Azure Cognitive Search Documentation, Fundamentals of Physics and Boundaries.\\n\\n5. 📊 **sqlsearch**: By utilizing this tool, I can access a SQL database containing information about Covid cases, deaths, and hospitalizations in 2020-2021.\\n\\nFrom all of my sources, I will provide the necessary information and also mention the sources I used to derive the answer. This way, you can have transparency about the origins of the information and understand how I arrived at the response.\\n\\nTo make the most of my capabilities, please mention the specific tool you\\'d like me to use when asking your question. Here\\'s an example:\\n\\n```\\nbing, who is the daughter of the President of India?\\nchatgpt, how can I read a remote file from a URL using pandas?\\ndocsearch, Does chloroquine really works against covid?\\nbooksearch, tell me the legend of the stolen kidney in the book \"Made To Stick\"\\nsqlsearch, how many people died on the West Coast in 2020?\\n```\\n\\nFeel free to ask any question and specify the tool you\\'d like me to utilize. I\\'m here to assist you!\\n\\n---\\n',\n",
" 'inputHint': 'acceptingInput',\n",
" 'replyToId': 'tYDStwcSru'},\n",
" {'type': 'message',\n",
" 'id': 'K91YF9vkrciAukcn2dkrGr-au|0000001',\n",
" 'timestamp': '2024-03-21T16:03:09.7523014Z',\n",
" 'serviceUrl': 'https://directline.botframework.com/',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'user'},\n",
" 'conversation': {'id': 'K91YF9vkrciAukcn2dkrGr-au'},\n",
" 'text': 'what CLP?'},\n",
" {'type': 'message',\n",
" 'id': 'K91YF9vkrciAukcn2dkrGr-au|0000002',\n",
" 'timestamp': '2024-03-21T16:03:13.0263341Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-zf4fwhz3gdn64', 'name': 'BotId-zf4fwhz3gdn64'},\n",
" 'conversation': {'id': 'K91YF9vkrciAukcn2dkrGr-au'},\n",
" 'text': 'Tool: docsearch',\n",
" 'inputHint': 'acceptingInput',\n",
" 'replyToId': 'K91YF9vkrciAukcn2dkrGr-au|0000001'},\n",
" {'type': 'message',\n",
" 'id': 'K91YF9vkrciAukcn2dkrGr-au|0000003',\n",
" 'timestamp': '2024-03-21T16:03:14.8443844Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-zf4fwhz3gdn64', 'name': 'BotId-zf4fwhz3gdn64'},\n",
" 'conversation': {'id': 'K91YF9vkrciAukcn2dkrGr-au'},\n",
" 'text': \"\\nInvoking: `docsearch` with `{'query': 'CLP'}`\\n\\n\\n ...\",\n",
" 'inputHint': 'acceptingInput',\n",
" 'replyToId': 'K91YF9vkrciAukcn2dkrGr-au|0000001'},\n",
" {'type': 'message',\n",
" 'id': 'K91YF9vkrciAukcn2dkrGr-au|0000004',\n",
" 'timestamp': '2024-03-21T16:03:38.7045557Z',\n",
" 'channelId': 'directline',\n",
" 'from': {'id': 'BotId-zf4fwhz3gdn64', 'name': 'BotId-zf4fwhz3gdn64'},\n",
" 'conversation': {'id': 'K91YF9vkrciAukcn2dkrGr-au'},\n",
" 'text': 'I have found multiple meanings and applications for the term \"CLP\" in different contexts. Here are some of the contexts in which \"CLP\" is mentioned:\\n\\n1. **Constraint Logic Programming (CLP):** This refers to a powerful extension of conventional logic programming that incorporates constraint languages and constraint solving methods into logic programming languages. It involves the parametrization of a logic programming language with respect to a constraint language and a domain of computation, yielding soundness and completeness results for an operational semantics relying on a constraint solver for the employed constraint language<sup><a href=\"https://datasetsgptsmartsearch.blob.core.windows.net/arxivcs/pdf/0008/0008036v1.pdf?sv=2022-11-02&ss=b&srt=sco&sp=rl&se=2026-01-03T02:11:44Z&st=2024-01-02T18:11:44Z&spr=https&sig=ngrEqvqBVaxyuSYqgPVeF%2B9c0fXLs94v3ASgwg7LDBs%3D\" target=\"_blank\">[1]</a></sup>.\\n\\n2. **Constraint Logic Programming (CLP(FD)):** This is an extension of logic programming where logical variables are assigned a domain, and relations between variables are described with constraints. A solution to a CLP(FD) program is a valuation of every variable in its own domain such that no constraint is falsified. Solutions are found using propagation and enumeration mechanisms. The translation of an imperative program into constraint logic programming on finite domains (CLP(FD)) involves generating a CLP(FD) constraint between the input and output variables of an imperative program<sup><a href=\"https://datasetsgptsmartsearch.blob.core.windows.net/arxivcs/pdf/0506/0506005v1.pdf?sv=2022-11-02&ss=b&srt=sco&sp=rl&se=2026-01-03T02:11:44Z&st=2024-01-02T18:11:44Z&spr=https&sig=ngrEqvqBVaxyuSYqgPVeF%2B9c0fXLs94v3ASgwg7LDBs%3D\" target=\"_blank\">[2]</a></sup>.\\n\\n3. **Recombinant Baculovirus-Generated Bluetongue Virus (BTV) Core-Like Particles (CLP):** This refers to the use of immunosorbent electron microscopy to quantify recombinant baculovirus-generated bluetongue virus (BTV) core-like particles (CLP) in purified preparations or lysates of recombinant baculovirus-infected cells. The CLP concentration in purified preparations and lysates of recombinant baculovirus-infected cells was determined using this method<sup><a href=\"https://www.ncbi.nlm.nih.gov/pubmed/10403670/?sv=2022-11-02&ss=b&srt=sco&sp=rl&se=2026-01-03T02:11:44Z&st=2024-01-02T18:11:44Z&spr=https&sig=ngrEqvqBVaxyuSYqgPVeF%2B9c0fXLs94v3ASgwg7LDBs%3D\" target=\"_blank\">[3]</a></sup>.\\n\\n4. **Recurrence with Affine Level Mappings in P-Time Decidable for CLP(R):** This context refers to a technical note discussing the decidability of termination for Constraint Logic Programming over the real numbers (CLP(R))<sup><a href=\"https://datasetsgptsmartsearch.blob.core.windows.net/arxivcs/pdf/0701/0701082v1.pdf?sv=2022-11-02&ss=b&srt=sco&sp=rl&se=2026-01-03T02:11:44Z&st=2024-01-02T18:11:44Z&spr=https&sig=ngrEqvqBVaxyuSYqgPVeF%2B9c0fXLs94v3ASgwg7LDBs%3D\" target=\"_blank\">[4]</a></sup>.\\n\\nGiven these different contexts, it\\'s important to specify the specific context in which \"CLP\" is being referred to in order to provide a more precise and relevant explanation.',\n",
" 'inputHint': 'acceptingInput',\n",
" 'replyToId': 'K91YF9vkrciAukcn2dkrGr-au|0000001'}]"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"activities"
]
},
{
"cell_type": "markdown",
"id": "2b677916-67f8-4259-b086-66e5f3d2c357",
Expand Down
1 change: 1 addition & 0 deletions credentials.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ AZURE_COSMOSDB_CONTAINER_NAME="ENTER YOUR VALUE"
AZURE_COMOSDB_CONNECTION_STRING="ENTER YOUR VALUE" # Find this in the Keys section
BOT_ID="ENTER YOUR VALUE" # This is the name of your bot service created in Notebook 12
BOT_SERVICE_DIRECT_LINE_SECRET="ENTER YOUR VALUE" # Find this in Azure Bot Service -> Channels -> Direct Line

0 comments on commit 5e3edd3

Please sign in to comment.