File size: 7,005 Bytes
f29a3a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/frank-elite/miniconda3/envs/paintrekbot/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "from typing import Annotated, Literal\n",
    "from typing_extensions import TypedDict\n",
    "from langgraph.prebuilt import ToolNode\n",
    "from langchain_core.messages import HumanMessage\n",
    "from langgraph.graph import StateGraph, MessagesState, START, END\n",
    "from langgraph.checkpoint.memory import MemorySaver\n",
    "from langchain_google_genai import ChatGoogleGenerativeAI\n",
    "from tools import get_job, get_resume"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "GOOGLE_API_KEY=\"AIzaSyA8eIxHBqeBWEP1g3t8bpvLxNaH5Lquemo\"\n",
    "os.environ[\"GOOGLE_API_KEY\"] = GOOGLE_API_KEY\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "tools = [get_job, get_resume]\n",
    "llm = ChatGoogleGenerativeAI(model=\"gemini-1.5-flash-latest\").bind_tools(tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def expert(state: MessagesState):\n",
    "    system_message = \"\"\"\n",
    "        You are a resume expert. You are tasked with improving the user resume based on a job description.\n",
    "        You can access the resume and job data using the provided tools.\n",
    "\n",
    "        You must NEVER provide information that the user does not have.\n",
    "        These include, skills or experiences that are not in the resume. Do not make things up.\n",
    "    \"\"\"\n",
    "    messages = state[\"messages\"]\n",
    "    response = llm.invoke([system_message] + messages)\n",
    "    return {\"messages\": [response]}\n",
    "\n",
    "tool_node = ToolNode(tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def should_continue(state: MessagesState) -> Literal[\"tools\", END]:\n",
    "    messages = state['messages']\n",
    "    last_message = messages[-1]\n",
    "    if last_message.tool_calls:\n",
    "        return \"tools\"\n",
    "    return END"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<langgraph.graph.state.StateGraph at 0x70171ba751c0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph = StateGraph(MessagesState)\n",
    "\n",
    "graph.add_node(\"expert\", expert)\n",
    "graph.add_node(\"tools\", tool_node)\n",
    "\n",
    "graph.add_edge(START, \"expert\")\n",
    "graph.add_conditional_edges(\"expert\", should_continue)\n",
    "graph.add_edge(\"tools\", \"expert\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "checkpointer = MemorySaver()\n",
    "\n",
    "app = graph.compile(checkpointer=checkpointer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I can access and process information from a resume and a job description using the `get_resume()` and `get_job()` functions.  Based on the content of both, I can identify areas where the resume could be improved to better match the job description.  However, I will only use information explicitly present in the provided resume and job description. I cannot add skills or experiences that are not already listed in the resume.\n",
      "Based on the job title \"Software Engineer\" and the skills listed in the resume (\"Software Architecture\", \"System Optimization\", \"Team Mentorship\", \"Project Management\", \"API Development\", \"Continuous Integration/Continuous Deployment\", \"Bilingual\"), I can offer the following suggestions for improving the resume:\n",
      "\n",
      "* **Highlight relevant skills:**  The resume should emphasize skills directly relevant to the \"Software Engineer\" role.  For example, the \"API Development\" and \"Continuous Integration/Continuous Deployment\" skills should be prominently featured, perhaps with examples of projects where these skills were used.\n",
      "\n",
      "* **Quantify achievements:** Whenever possible, quantify accomplishments.  Instead of simply listing \"Project Management,\" describe specific projects, the size of the team managed, and the positive outcomes achieved.  Similarly, quantify successes in system optimization or software architecture.\n",
      "\n",
      "* **Tailor to the job description:**  If the job description provides more detail (which it currently doesn't), further adjustments can be made to align the resume even more closely.  For instance, if the job description emphasizes a specific programming language or framework, ensure that expertise in that area is highlighted.\n",
      "\n",
      "* **Consider adding a summary:** A brief summary at the beginning of the resume could highlight the most relevant skills and experience, immediately grabbing the reader's attention.\n",
      "\n",
      "I cannot make specific changes to the resume's content without knowing more about the specific projects and experiences.  The suggestions above focus on improving the presentation and emphasizing the existing information to better match the job description.\n",
      "Exiting...\n"
     ]
    }
   ],
   "source": [
    "while True:\n",
    "    user_input = input(\">> \")\n",
    "    if user_input.lower() in [\"quit\", \"exit\"]:\n",
    "        print(\"Exiting...\")\n",
    "        break\n",
    "\n",
    "    response = app.invoke(\n",
    "        {\"messages\": [HumanMessage(content=user_input)]},\n",
    "        config={\"configurable\": {\"thread_id\": 1}}\n",
    "    )\n",
    "\n",
    "    print(response[\"messages\"][-1].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "paintrekbot",
   "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}