|
@@ -53,14 +53,14 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 1,
|
|
|
+ "execution_count": 7,
|
|
|
"id": "bb085f6c-f069-48ef-8085-32f8a301b090",
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"data": {
|
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
|
- "model_id": "230f48fcefd4442b898f06b1346046ce",
|
|
|
+ "model_id": "efc10dfe3b754f5eb17271d10da9e9d1",
|
|
|
"version_major": 2,
|
|
|
"version_minor": 0
|
|
|
},
|
|
@@ -89,12 +89,18 @@
|
|
|
"id": "53427131-4311-4637-bac8-3f65073dbe23",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "## Define functions to access People and Google Calendar API\n",
|
|
|
+ "## Define functions to access People (`google_contact`) and Google Calendar (`google_calendar`) API\n",
|
|
|
"\n",
|
|
|
"**Note!!!!**\n",
|
|
|
- "In order to execute Google APIs, you need to store your credentials in `credentials.json` Please refer to the [instructions](https://developers.google.com/workspace/guides/create-credentials) here to get the credentials\n",
|
|
|
+ "Accessing Google APIs require you to first get credentials (This is a one time process) \n",
|
|
|
+ "\n",
|
|
|
+ "Store your credentials in `credentials.json` Please refer to the [instructions](https://developers.google.com/workspace/guides/create-credentials) here to get the credentials.\n",
|
|
|
+ "\n",
|
|
|
+ "I followed the the steps in [service account](https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount) to get my credentials.\n",
|
|
|
+ "\n",
|
|
|
+ "Accessing Google APIs also require you to get **authentication token** in addition to the credentials. The functions defined below `google_contact` and `google_calendar` also include the logic to generate & refresh the authentication token.\n",
|
|
|
"\n",
|
|
|
- "To get the access tokens for using the People & Google Calendar API, we need a runnable browser available on the machine where you execute these functions for the **FIRST TIME** only. You will need to authenticate using your browser for the first time. Executing these functions will generate a `token_contacts.json` & `token_calendar.json`\n",
|
|
|
+ "To get the authentication token for using the People & Google Calendar API, we need a runnable browser available on the machine where you execute these functions for the **FIRST TIME** only. You will need to authenticate using your browser for the first time. Executing these functions will generate a `token_contacts.json` & `token_calendar.json`\n",
|
|
|
"\n",
|
|
|
"For subsequent calls, you don't need a runnable browser"
|
|
|
]
|
|
@@ -109,46 +115,17 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 1,
|
|
|
- "id": "76f9ee3c-bdf5-461e-a9b9-b59d012ca532",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "cd102901-40bc-4d3c-8726-1dd64164086c",
|
|
|
"metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "name": "stdout",
|
|
|
- "output_type": "stream",
|
|
|
- "text": [
|
|
|
- "Requirement already satisfied: google-api-python-client in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (2.165.0)\n",
|
|
|
- "Requirement already satisfied: google-auth-oauthlib in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (1.2.1)\n",
|
|
|
- "Requirement already satisfied: httplib2<1.0.0,>=0.19.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-python-client) (0.22.0)\n",
|
|
|
- "Requirement already satisfied: google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-python-client) (2.38.0)\n",
|
|
|
- "Requirement already satisfied: google-auth-httplib2<1.0.0,>=0.2.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-python-client) (0.2.0)\n",
|
|
|
- "Requirement already satisfied: google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-python-client) (2.24.1)\n",
|
|
|
- "Requirement already satisfied: uritemplate<5,>=3.0.1 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-python-client) (4.1.1)\n",
|
|
|
- "Requirement already satisfied: requests-oauthlib>=0.7.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-auth-oauthlib) (2.0.0)\n",
|
|
|
- "Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (1.67.0)\n",
|
|
|
- "Requirement already satisfied: protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0.dev0,>=3.19.5 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (4.25.6)\n",
|
|
|
- "Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (1.26.0)\n",
|
|
|
- "Requirement already satisfied: requests<3.0.0.dev0,>=2.18.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (2.32.3)\n",
|
|
|
- "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (5.5.1)\n",
|
|
|
- "Requirement already satisfied: pyasn1-modules>=0.2.1 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (0.4.1)\n",
|
|
|
- "Requirement already satisfied: rsa<5,>=3.1.4 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (4.9)\n",
|
|
|
- "Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from httplib2<1.0.0,>=0.19.0->google-api-python-client) (3.2.1)\n",
|
|
|
- "Requirement already satisfied: oauthlib>=3.0.0 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib) (3.2.2)\n",
|
|
|
- "Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from pyasn1-modules>=0.2.1->google-auth!=2.24.0,!=2.25.0,<3.0.0,>=1.32.0->google-api-python-client) (0.6.1)\n",
|
|
|
- "Requirement already satisfied: charset-normalizer<4,>=2 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (3.4.1)\n",
|
|
|
- "Requirement already satisfied: idna<4,>=2.5 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (3.10)\n",
|
|
|
- "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (2.3.0)\n",
|
|
|
- "Requirement already satisfied: certifi>=2017.4.17 in /home/agunapal/anaconda3/envs/llama-cookbook/lib/python3.10/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0,>=1.31.5->google-api-python-client) (2025.1.31)\n"
|
|
|
- ]
|
|
|
- }
|
|
|
- ],
|
|
|
+ "outputs": [],
|
|
|
"source": [
|
|
|
"! pip install google-api-python-client google-auth-oauthlib"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 28,
|
|
|
+ "execution_count": 1,
|
|
|
"id": "0e212a74-4c9f-424c-a39b-9c5dc7fd45d5",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
@@ -298,7 +275,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 34,
|
|
|
+ "execution_count": 2,
|
|
|
"id": "5df96557-8beb-43b9-ac99-c1218a686676",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
@@ -356,7 +333,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 49,
|
|
|
+ "execution_count": 3,
|
|
|
"id": "a75b7fac-7553-40e5-aedd-67ebdc98cce7",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
@@ -485,7 +462,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 50,
|
|
|
+ "execution_count": 4,
|
|
|
"id": "48a57e28-82cf-4f8f-b9ac-2b357f7aea7e",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
@@ -495,7 +472,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 51,
|
|
|
+ "execution_count": 5,
|
|
|
"id": "f3c35189-4152-45a8-81ab-386466d6284c",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
@@ -521,7 +498,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 52,
|
|
|
+ "execution_count": 8,
|
|
|
"id": "58801f79-08eb-49f2-bb35-aff1e026e41c",
|
|
|
"metadata": {},
|
|
|
"outputs": [
|
|
@@ -558,7 +535,8 @@
|
|
|
"Question: Tell me about Paris \n",
|
|
|
"\n",
|
|
|
" Answer:\n",
|
|
|
- " general\n",
|
|
|
+ " general \n",
|
|
|
+ "\n",
|
|
|
"\n",
|
|
|
"\n",
|
|
|
"-----------------------------------------------------\n",
|
|
@@ -572,7 +550,109 @@
|
|
|
"Question: Tell me about Paris \n",
|
|
|
"\n",
|
|
|
" Answer:\n",
|
|
|
- " Paris, the City of Light, is the capital of France. Known for its stunning architecture, art museums, and romantic atmosphere, Paris is a popular tourist destination. The city is famous for its iconic landmarks such as the Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum, which houses the Mona Lisa. Paris is also renowned for its fashion, cuisine, and wine. The city's charming streets and historic neighborhoods, like Montmartre and Le Marais, offer a glimpse\n"
|
|
|
+ "Paris, the City of Light, is the capital of France, known for its stunning architecture, art, fashion, and romance. The city is home to iconic landmarks like the Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum, which houses the Mona Lisa. The city's charming streets, cafes, and gardens offer a unique blend of history, culture, and beauty. Visitors can stroll along the Seine River, explore the Latin Quarter, and indulge in French cuisine, wine\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "\n",
|
|
|
+ "result = \"\\n-----------------------------------------------------\\n\"\n",
|
|
|
+ "result += \"FIRST PASS\"\n",
|
|
|
+ "result += \"\\n-----------------------------------------------------\\n\"\n",
|
|
|
+ "\n",
|
|
|
+ "input_ids = tokenizer(prompt, return_tensors=\"pt\").to(\"cuda\")\n",
|
|
|
+ "\n",
|
|
|
+ "output = model.generate(**input_ids, max_new_tokens=2)\n",
|
|
|
+ "\n",
|
|
|
+ "llama_output = tokenizer.decode(output[0], skip_special_tokens=True)\n",
|
|
|
+ "\n",
|
|
|
+ "result += llama_output\n",
|
|
|
+ "result += \"\\n\"\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "classification = llama_output[input_prompt_length:].strip()\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "if \"meeting\" in classification:\n",
|
|
|
+ " result = setup_meeting(prompt, result)\n",
|
|
|
+ "elif \"general\" in classification:\n",
|
|
|
+ " result = general_query(user_prompt, result)\n",
|
|
|
+ "print(result)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 9,
|
|
|
+ "id": "93a74c4b-a918-43a2-8099-a4f0efb8902f",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "user_prompt = \"Can you describe how an internal combustion engine works \"\n",
|
|
|
+ "\n",
|
|
|
+ "prompt = SYSTEM_PROMPT + f\"\\n\\nQuestion: {user_prompt} \\n\" + \"\\n Answer:\\n\"\n",
|
|
|
+ "\n",
|
|
|
+ "input_prompt_length = len(prompt)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 10,
|
|
|
+ "id": "b87f590d-d697-4f8f-af8d-5099c59019f0",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stderr",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n",
|
|
|
+ "Setting `pad_token_id` to `eos_token_id`:128001 for open-end generation.\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "\n",
|
|
|
+ "-----------------------------------------------------\n",
|
|
|
+ "FIRST PASS\n",
|
|
|
+ "-----------------------------------------------------\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ " Classify the given prompt\n",
|
|
|
+ " A message can be classified as one of the following categories: meeting, general.\n",
|
|
|
+ "\n",
|
|
|
+ " Examples:\n",
|
|
|
+ " - meeting: \"Can you schedule a meeting with Ankith on Dec 1 at 1 pm.\"\n",
|
|
|
+ " - general: \"Tell me about San Francisco\"\n",
|
|
|
+ "\n",
|
|
|
+ " Reminder:\n",
|
|
|
+ " - ONLY return the classification label and NOTHING else\n",
|
|
|
+ " - DO NOT give any explanation or examples\n",
|
|
|
+ " \n",
|
|
|
+ "\n",
|
|
|
+ "Question: Can you describe how an internal combustion engine works \n",
|
|
|
+ "\n",
|
|
|
+ " Answer:\n",
|
|
|
+ "general\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "-----------------------------------------------------\n",
|
|
|
+ "SECOND PASS\n",
|
|
|
+ "-----------------------------------------------------\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ " You are a helpful assistant. Answer the query in 100 words\n",
|
|
|
+ " \n",
|
|
|
+ "\n",
|
|
|
+ "Question: Can you describe how an internal combustion engine works \n",
|
|
|
+ "\n",
|
|
|
+ " Answer:\n",
|
|
|
+ "An internal combustion engine is a type of heat engine that generates power by burning fuel, typically gasoline or diesel, inside a combustion chamber within the engine. The engine consists of several major components, including cylinders, pistons, crankshafts, and valves. Here's a simplified overview of the process:\n",
|
|
|
+ "\n",
|
|
|
+ "1. Air and fuel are drawn into the cylinders through the intake valves.\n",
|
|
|
+ "2. The mixture is compressed by the pistons, creating a high-pressure mixture.\n",
|
|
|
+ "3. The spark plug ignites the\n"
|
|
|
]
|
|
|
}
|
|
|
],
|