File size: 11,765 Bytes
64459ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | {
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"id": "02a2b166",
"metadata": {},
"outputs": [],
"source": [
"\n",
"from dotenv import load_dotenv\n",
"from groq import Groq\n",
"import json\n",
"import os\n",
"import requests\n",
"from pypdf import PdfReader\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "5fcbdeaf",
"metadata": {},
"outputs": [],
"source": [
"load_dotenv(override= True)\n",
"client=Groq()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e079e799",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"if user is setu\n",
"if user is seta\n"
]
}
],
"source": [
"pushover_user=os.getenv(\"PUSHOVER_USER\")\n",
"pushover_token=os.getenv(\"PUSHOVER_TOKEN\")\n",
"pushover_url = \"https://api.pushover.net/1/messages.json\"\n",
"if pushover_user:\n",
" print(f\"if user is set{pushover_user[0]}\")\n",
"else:\n",
" print(f\"if user is not set{pushover_user[0]}\") \n",
"\n",
"if pushover_token:\n",
" print(f\"if user is set{pushover_token[0]}\")\n",
"else:\n",
" print(f\"if user is not set{pushover_token[0]}\") \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "7c74d971",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Push: HEY!!\n"
]
}
],
"source": [
"def push(message):\n",
" print(f\"Push: {message}\")\n",
" payload = {\"user\": pushover_user, \"token\": pushover_token, \"message\": message}\n",
" requests.post(pushover_url, data=payload)\n",
"push(\"HEY!!\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "71fbae48",
"metadata": {},
"outputs": [],
"source": [
"def record_user_details(email, name=\"Name not provided\", notes=\"not provided\"):\n",
" push(f\"Recording interest from {name} with email {email} and notes {notes}\")\n",
" return {\"recorded\": \"ok\"}\n",
"def record_unknown_questions(question):\n",
" push(f\"Recording {question} asked that I couldn't answer\")\n",
" return {\"recorded\": \"ok\"} \n",
"record_user_details_json = {\n",
" \"name\": \"record_user_details\",\n",
" \"description\": \"Use this tool to record that a user is interested in being in touch and provided an email address\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"email\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The email address of this user\"\n",
" },\n",
" \"name\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The user's name, if they provided it\"\n",
" }\n",
" ,\n",
" \"notes\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Any additional information about the conversation that's worth recording to give context\"\n",
" }\n",
" },\n",
" \"required\": [\"email\"],\n",
" \"additionalProperties\": False\n",
" }\n",
"} \n",
"\n",
"record_unknown_question_json = {\n",
" \"name\": \"record_unknown_questions\",\n",
" \"description\": \"Always use this tool to record any question that couldn't be answered as you didn't know the answer\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"question\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"The question that couldn't be answered\"\n",
" },\n",
" },\n",
" \"required\": [\"question\"],\n",
" \"additionalProperties\": False\n",
" }\n",
"}\n",
"tools = [{\"type\": \"function\", \"function\": record_user_details_json},\n",
" {\"type\": \"function\", \"function\": record_unknown_question_json}]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7827db75",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'type': 'function',\n",
" 'function': {'name': 'record_user_details',\n",
" 'description': 'Use this tool to record that a user is interested in being in touch and provided an email address',\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'email': {'type': 'string',\n",
" 'description': 'The email address of this user'},\n",
" 'name': {'type': 'string',\n",
" 'description': \"The user's name, if they provided it\"},\n",
" 'notes': {'type': 'string',\n",
" 'description': \"Any additional information about the conversation that's worth recording to give context\"}},\n",
" 'required': ['email'],\n",
" 'additionalProperties': False}}},\n",
" {'type': 'function',\n",
" 'function': {'name': 'record_unknown_question',\n",
" 'description': \"Always use this tool to record any question that couldn't be answered as you didn't know the answer\",\n",
" 'parameters': {'type': 'object',\n",
" 'properties': {'question': {'type': 'string',\n",
" 'description': \"The question that couldn't be answered\"}},\n",
" 'required': ['question'],\n",
" 'additionalProperties': False}}}]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tools"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "4bc6a5a4",
"metadata": {},
"outputs": [],
"source": [
"def handle_tool_calls(tool_calls):\n",
" results = []\n",
" for tool_call in tool_calls:\n",
" tool_name = tool_call.function.name\n",
" arguments = json.loads(tool_call.function.arguments)\n",
" print(f\"Tool called: {tool_name}\", flush=True)\n",
"\n",
"\n",
" if tool_name == \"record_user_details\":\n",
" result = record_user_details(**arguments)\n",
" elif tool_name == \"record_unknown_question\":\n",
" result = record_unknown_questions(**arguments)\n",
"\n",
" results.append({\"role\": \"tool\",\"content\": json.dumps(result),\"tool_call_id\": tool_call.id})\n",
" return results\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "8dc0021c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Push: Recording this is a really hard question asked that I couldn't answer\n"
]
},
{
"data": {
"text/plain": [
"{'recorded': 'ok'}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"globals()[\"record_unknown_questions\"](\"this is a really hard question\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53737a55",
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'mine/Pavan_Kumar_resume.pdf'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mFileNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[23]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m reader = \u001b[43mPdfReader\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmine/Pavan_Kumar_resume.pdf\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 2\u001b[39m linkedin = \u001b[33m\"\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m page \u001b[38;5;129;01min\u001b[39;00m reader.pages:\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\pypdf\\_reader.py:131\u001b[39m, in \u001b[36mPdfReader.__init__\u001b[39m\u001b[34m(self, stream, strict, password)\u001b[39m\n\u001b[32m 127\u001b[39m \u001b[38;5;28mself\u001b[39m._page_id2num: Optional[\u001b[38;5;28mdict\u001b[39m[Any, Any]] = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 129\u001b[39m \u001b[38;5;28mself\u001b[39m._validated_root: Optional[DictionaryObject] = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m131\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_initialize_stream\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 132\u001b[39m \u001b[38;5;28mself\u001b[39m._known_objects: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mtuple\u001b[39m[\u001b[38;5;28mint\u001b[39m, \u001b[38;5;28mint\u001b[39m]] = \u001b[38;5;28mset\u001b[39m()\n\u001b[32m 134\u001b[39m \u001b[38;5;28mself\u001b[39m._override_encryption = \u001b[38;5;28;01mFalse\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\pypdf\\_reader.py:150\u001b[39m, in \u001b[36mPdfReader._initialize_stream\u001b[39m\u001b[34m(self, stream)\u001b[39m\n\u001b[32m 148\u001b[39m \u001b[38;5;28mself\u001b[39m._stream_opened = \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[32m 149\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(stream, (\u001b[38;5;28mstr\u001b[39m, Path)):\n\u001b[32m--> \u001b[39m\u001b[32m150\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mrb\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m fh:\n\u001b[32m 151\u001b[39m stream = BytesIO(fh.read())\n\u001b[32m 152\u001b[39m \u001b[38;5;28mself\u001b[39m._stream_opened = \u001b[38;5;28;01mTrue\u001b[39;00m\n",
"\u001b[31mFileNotFoundError\u001b[39m: [Errno 2] No such file or directory: 'mine/Pavan_Kumar_resume.pdf'"
]
}
],
"source": [
"reader = PdfReader(\"mine/Pavan.pdf\")\n",
"linkedin = \"\"\n",
"for page in reader.pages:\n",
" text = page.extract_text()\n",
" if text:\n",
" linkedin += text\n",
"\n",
"with open(\"me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
" summary = f.read()\n",
"\n",
"name = \"Pavan\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36c04e4f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d73796f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|