{ "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 }