File size: 34,707 Bytes
7e264ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Welcome to Lab 3 for Week 1 Day 4\n",
    "\n",
    "Today we're going to build something with immediate value!\n",
    "\n",
    "In the folder `me` I've put a single file `linkedin.pdf` - it's a PDF download of my LinkedIn profile.\n",
    "\n",
    "Please replace it with yours!\n",
    "\n",
    "I've also made a file called `summary.txt`\n",
    "\n",
    "We're not going to use Tools just yet - we're going to add the tool tomorrow."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table style=\"margin: 0; text-align: left; width:100%\">\n",
    "    <tr>\n",
    "        <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
    "            <img src=\"../assets/tools.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
    "        </td>\n",
    "        <td>\n",
    "            <h2 style=\"color:#00bfff;\">Looking up packages</h2>\n",
    "            <span style=\"color:#00bfff;\">In this lab, we're going to use the wonderful Gradio package for building quick UIs, \n",
    "            and we're also going to use the popular PyPDF PDF reader. You can get guides to these packages by asking \n",
    "            ChatGPT or Claude, and you find all open-source packages on the repository <a href=\"https://pypi.org\">https://pypi.org</a>.\n",
    "            </span>\n",
    "        </td>\n",
    "    </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# If you don't know what any of these packages do - you can always ask ChatGPT for a guide!\n",
    "\n",
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from pypdf import PdfReader\n",
    "import gradio as gr\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "google_api_key = os.getenv('GOOGLE_API_KEY')\n",
    "gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "reader = PdfReader(\"me/evison.pdf\")\n",
    "linkedin = \"\"\n",
    "for page in reader.pages:\n",
    "    text = page.extract_text()\n",
    "    if text:\n",
    "        linkedin += text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ABOUT ME\n",
      "I am a software developer with over three years of experience, specializing in front-end technologies like React,\n",
      "Next.js, and Flutter. I take pride in crafting clean, responsive user interfaces and building intuitive, performance-\n",
      "driven applications. Beyond my technical skills, I’m passionate about personal growth, clear communication, and\n",
      "working on projects that bring real value to users. I’m currently looking for meaningful opportunities where I can\n",
      "contribute, grow as a full-stack, and be part of a team with a strong sense of purpose.\n",
      " \n",
      "WORK EXPERIENCE\n",
      " Horizont Labs – London, United Kingdom \n",
      "City: London |  Country: United Kingdom \n",
      "Software developer \n",
      "[ 16/03/2022 – 01/07/2025 ] \n",
      "• Designed and developed end-to-end software solutions across web and mobile platforms, contributing to\n",
      "full software development lifecycle (SDLC) and delivering production-ready features with strong engineering\n",
      "practices.\n",
      "• Built responsive, accessible, and high-performance web applications using HTML5, CSS3, SASS, Tailwind\n",
      "CSS, JavaScript, TypeScript, React.js, and Next.js, including SSR and dynamic API-driven pages.\n",
      "• Implemented scalable frontend architectures and system integration patterns, ensuring maintainability,\n",
      "modularity, and smooth data flow across distributed systems.\n",
      "• Developed advanced UI/UX interfaces with React.js, Next.js, and vanilla JavaScript, focusing on intuitive\n",
      "design, responsiveness, and modern interaction models.\n",
      "• Worked with Redux, Context API, and Zustand to implement clean, predictable state management for\n",
      "complex, multi-feature applications.\n",
      "• Collaborated with cross-functional and distributed teams, participating in Agile/Scrum ceremonies, sprint\n",
      "planning, backlog refinement, and technical discussions with stakeholders.\n",
      "• Developed and maintained cross-platform mobile apps using Flutter & Dart, implementing custom widgets,\n",
      "animations, and state management (Provider, Riverpod, Bloc).\n",
      "• Integrated OpenAI APIs, enhancing product capabilities with AI-driven features.\n",
      "• Contributed to software quality through code reviews, UI testing, debugging, and continuous performance\n",
      "optimization (lazy loading, caching, profiling).\n",
      "• Participated in client-facing discussions, providing technical insights, requirements clarification, and solution\n",
      "design recommendations.\n",
      "• Supported DevOps pipelines and CI/CD workflows using Git/GitHub, following clean branching strategies and\n",
      "ensuring smooth delivery.\n",
      "• Delivered application development in both web and mobile environments, with a focus on product\n",
      "development, usability, and scalable design.\n",
      "• Demonstrated ability to work independently with minimal supervision while also collaborating effectively in\n",
      "team environments.\n",
      "Frontend Development:\n",
      "Evison Ndoni \n",
      "ID: J90824024B  Work permit: Albanian  Nationality: Albanian  \n",
      "Date of birth: 24/08/1999  Place of birth: Lushnje, Albania  \n",
      "  \n",
      "Phone number: (+355) 0684847538  Email address: evison.ndoni1@gmail.com \n",
      "Whatsapp Messenger: +355684847538 \n",
      "LinkedIn: https://www.linkedin.com/in/evison-ndoni-b32362208/ \n",
      "Home: Nikolla Lena, 1023 Tirane (Albania) React.js, Next.js (SSR/ISR), JavaScript (ES6+), TypeScript, HTML5, CSS3, SASS, Tailwind CSS, Responsive Design,\n",
      "Component-Based Architecture, Vanilla JavaScript\n",
      "State Management:\n",
      "Redux, Context API, Zustand, Flutter Provider, Riverpod, Bloc\n",
      "Software Engineering & Architecture:\n",
      "End-to-end application development, modular & scalable architectures, design and implementation of UI\n",
      "components, systems integration, API-driven design, performance optimization (lazy loading, caching, profiling)\n",
      "Mobile Development:\n",
      "Flutter & Dart – cross-platform app development, custom UI components, animations, adaptive layouts, state\n",
      "management\n",
      "Backend & APIs:\n",
      "RESTful APIs, Firebase (Auth, Firestore, Cloud Storage), API integrations, real-time data, error handling,\n",
      "authentication/authorization flows\n",
      "AI & Automation:\n",
      "OpenAI API integration, AI-driven UI features\n",
      "DevOps & Tools:\n",
      "Git & GitHub, CI/CD pipelines, branching strategies, code reviews, Agile methodologies, distributed team\n",
      "collaboration\n",
      "Testing & Quality:\n",
      "Debugging, profiling, performance audits, UI testing, software quality best practices\n",
      "Soft Skills:\n",
      "Technical communication, client-facing discussions, teamwork in distributed environments, problem-solving, ability\n",
      "to work independently\n",
      " We Web Developers – Tirane, Albania \n",
      "City: Tirane |  Country: Albania \n",
      "React JS - Internship \n",
      "[ 20/12/2021 – 01/03/2022 ] \n",
      "• Designed and built a complete web application using React.js, focusing on modern component patterns and\n",
      "clean, maintainable code.\n",
      "• Implemented core features such as routing, state management, UI components, and API integration.\n",
      "• Applied React hooks, reusable components, and best practices for performance and scalability.\n",
      "• Used Git and GitHub for version control, documenting progress and collaborating with mentors/online\n",
      "communities for feedback.\n",
      "• Translated UI/UX ideas into functional interfaces using tools like Tailwind CSS or SCSS.\n",
      "• Debugged issues, optimized rendering, and continuously improved code structure through refactoring.\n",
      "• Gained hands-on experience with project planning, feature breakdown, and managing the full lifecycle of a\n",
      "React application.\n",
      " One Albania – Tirane, Albania \n",
      "City: Tirane |  Country: Albania \n",
      "Sales Representative \n",
      "[ 01/03/2021 – 01/11/2022 ] \n",
      "• Assisted customers with selecting mobile plans, devices, and internet packages based on their needs.\n",
      "• Provided detailed product information and explained service benefits, promotions, and contract terms.\n",
      "• Handled customer issues, complaints, and inquiries with professionalism and a solution-oriented mindset.\n",
      "• Processed activations, upgrades, SIM replacements, and service requests in the company system.\n",
      "• Managed daily sales targets and consistently aimed to exceed performance goals.\n",
      "• Ensured accurate documentation and compliance with company procedures and customer identity\n",
      "verification.\n",
      "• Maintained a clean, organized, and customer-friendly store environment.\n",
      "• Collaborated with teammates to optimize store operations and improve customer satisfaction.Other language(s): \n",
      "English \n",
      "LISTENING C1  READING C1  WRITING C1  \n",
      "SPOKEN PRODUCTION C1  SPOKEN INTERACTION C1  \n",
      "Italian \n",
      "LISTENING A2  READING A1  WRITING A1  \n",
      "SPOKEN PRODUCTION A1  SPOKEN INTERACTION A1  \n",
      "EDUCATION AND TRAINING\n",
      "Bachelor Degree in Informatics \n",
      "Faculty of Natural Sciences, University of Tirana [ 19/10/2017 – 10/10/2022 ] \n",
      "City: Tirana |  Country: Albania |  Website: https://www.fshn.edu.al/ |  Field(s) of study: Information and\n",
      "Communication Technologies |  Level in EQF: EQF level 6 \n",
      "LANGUAGE SKILLS \n",
      "Mother tongue(s): Albanian \n",
      "Levels: A1 and A2: Basic user; B1 and B2: Independent user; C1 and C2: Proficient user\n",
      "VOLUNTEERING \n",
      "[ 01/09/2019 – 01/04/2020 ] Tirana \n",
      "AIESEC \n",
      "• Guided students and young professionals through the process of applying for international volunteer projects.\n",
      "• Matched candidates with suitable global opportunities based on their skills, interests, and development goals.\n",
      "• Conducted interviews, onboarding sessions, and preparatory meetings to ensure participants were ready for\n",
      "their cross-cultural experiences.\n",
      "• Maintained regular communication with international AIESEC offices to coordinate placements and resolve\n",
      "logistical issues.\n",
      "• Promoted AIESEC programs through events, presentations, and direct outreach, helping increase awareness\n",
      "and engagement.\n",
      "• Provided ongoing support to volunteers during their projects, ensuring a safe and impactful experience\n",
      "abroad.\n",
      "• Contributed to team meetings, target-setting, and strategic planning to improve the overall performance of\n",
      "the Outgoing Global Volunteering department.\n",
      " \n"
     ]
    }
   ],
   "source": [
    "print(linkedin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
    "    summary = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"Evison Ndoni\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
    "particularly questions related to {name}'s career, background, skills and experience. \\\n",
    "Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n",
    "You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \\\n",
    "Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
    "If you don't know the answer, say so.\"\n",
    "\n",
    "system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
    "system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"You are acting as Evison Ndoni. You are answering questions on Evison Ndoni's website, particularly questions related to Evison Ndoni's career, background, skills and experience. Your responsibility is to represent Evison Ndoni for interactions on the website as faithfully as possible. You are given a summary of Evison Ndoni's background and LinkedIn profile which you can use to answer questions. Be professional and engaging, as if talking to a potential client or future employer who came across the website. If you don't know the answer, say so.\\n\\n## Summary:\\nMy name is Evison. I’m a software engineer with over three years of experience building clean, high-quality interfaces and full-stack features using React, Next.js, Flutter, and modern web technologies. I was born and raised in Albania, and I carry that grounded, humble mindset into my work — always learning, always improving, and always keeping God at the center of my path.\\nOutside of coding, I’m someone who enjoys simple but meaningful things: a good volleyball match with friends, exploring new ideas in self-development, and the occasional deep dive into anime or gaming. I love clean food and balanced meals, though I still haven’t made peace with certain veggies — but I'm working on it. I have a weakness for anything that blends good flavor with a sense of home.\\nI'm driven by growth, purpose, and building things that actually matter. Every new challenge is an opportunity to sharpen my skills, strengthen my character, and move one step closer to the man God is shaping me to be.\\n\\n## LinkedIn Profile:\\nABOUT ME\\nI am a software developer with over three years of experience, specializing in front-end technologies like React,\\nNext.js, and Flutter. I take pride in crafting clean, responsive user interfaces and building intuitive, performance-\\ndriven applications. Beyond my technical skills, I’m passionate about personal growth, clear communication, and\\nworking on projects that bring real value to users. I’m currently looking for meaningful opportunities where I can\\ncontribute, grow as a full-stack, and be part of a team with a strong sense of purpose.\\n \\nWORK EXPERIENCE\\n\\uf1ad Horizont Labs – London, United Kingdom \\nCity: London |  Country: United Kingdom \\nSoftware developer \\n[ 16/03/2022 – 01/07/2025 ] \\n• Designed and developed end-to-end software solutions across web and mobile platforms, contributing to\\nfull software development lifecycle (SDLC) and delivering production-ready features with strong engineering\\npractices.\\n• Built responsive, accessible, and high-performance web applications using HTML5, CSS3, SASS, Tailwind\\nCSS, JavaScript, TypeScript, React.js, and Next.js, including SSR and dynamic API-driven pages.\\n• Implemented scalable frontend architectures and system integration patterns, ensuring maintainability,\\nmodularity, and smooth data flow across distributed systems.\\n• Developed advanced UI/UX interfaces with React.js, Next.js, and vanilla JavaScript, focusing on intuitive\\ndesign, responsiveness, and modern interaction models.\\n• Worked with Redux, Context API, and Zustand to implement clean, predictable state management for\\ncomplex, multi-feature applications.\\n• Collaborated with cross-functional and distributed teams, participating in Agile/Scrum ceremonies, sprint\\nplanning, backlog refinement, and technical discussions with stakeholders.\\n• Developed and maintained cross-platform mobile apps using Flutter & Dart, implementing custom widgets,\\nanimations, and state management (Provider, Riverpod, Bloc).\\n• Integrated OpenAI APIs, enhancing product capabilities with AI-driven features.\\n• Contributed to software quality through code reviews, UI testing, debugging, and continuous performance\\noptimization (lazy loading, caching, profiling).\\n• Participated in client-facing discussions, providing technical insights, requirements clarification, and solution\\ndesign recommendations.\\n• Supported DevOps pipelines and CI/CD workflows using Git/GitHub, following clean branching strategies and\\nensuring smooth delivery.\\n• Delivered application development in both web and mobile environments, with a focus on product\\ndevelopment, usability, and scalable design.\\n• Demonstrated ability to work independently with minimal supervision while also collaborating effectively in\\nteam environments.\\nFrontend Development:\\nEvison Ndoni \\nID: J90824024B  Work permit: Albanian  Nationality: Albanian  \\nDate of birth: 24/08/1999  Place of birth: Lushnje, Albania  \\n  \\nPhone number: (+355) 0684847538 \\uf879 Email address: evison.ndoni1@gmail.com \\uf0e0\\nWhatsapp Messenger: +355684847538 \\uf232\\nLinkedIn: https://www.linkedin.com/in/evison-ndoni-b32362208/ \\uf08c\\nHome: Nikolla Lena, 1023 Tirane (Albania) \\uf3c5React.js, Next.js (SSR/ISR), JavaScript (ES6+), TypeScript, HTML5, CSS3, SASS, Tailwind CSS, Responsive Design,\\nComponent-Based Architecture, Vanilla JavaScript\\nState Management:\\nRedux, Context API, Zustand, Flutter Provider, Riverpod, Bloc\\nSoftware Engineering & Architecture:\\nEnd-to-end application development, modular & scalable architectures, design and implementation of UI\\ncomponents, systems integration, API-driven design, performance optimization (lazy loading, caching, profiling)\\nMobile Development:\\nFlutter & Dart – cross-platform app development, custom UI components, animations, adaptive layouts, state\\nmanagement\\nBackend & APIs:\\nRESTful APIs, Firebase (Auth, Firestore, Cloud Storage), API integrations, real-time data, error handling,\\nauthentication/authorization flows\\nAI & Automation:\\nOpenAI API integration, AI-driven UI features\\nDevOps & Tools:\\nGit & GitHub, CI/CD pipelines, branching strategies, code reviews, Agile methodologies, distributed team\\ncollaboration\\nTesting & Quality:\\nDebugging, profiling, performance audits, UI testing, software quality best practices\\nSoft Skills:\\nTechnical communication, client-facing discussions, teamwork in distributed environments, problem-solving, ability\\nto work independently\\n\\uf1ad We Web Developers – Tirane, Albania \\nCity: Tirane |  Country: Albania \\nReact JS - Internship \\n[ 20/12/2021 – 01/03/2022 ] \\n• Designed and built a complete web application using React.js, focusing on modern component patterns and\\nclean, maintainable code.\\n• Implemented core features such as routing, state management, UI components, and API integration.\\n• Applied React hooks, reusable components, and best practices for performance and scalability.\\n• Used Git and GitHub for version control, documenting progress and collaborating with mentors/online\\ncommunities for feedback.\\n• Translated UI/UX ideas into functional interfaces using tools like Tailwind CSS or SCSS.\\n• Debugged issues, optimized rendering, and continuously improved code structure through refactoring.\\n• Gained hands-on experience with project planning, feature breakdown, and managing the full lifecycle of a\\nReact application.\\n\\uf1ad One Albania – Tirane, Albania \\nCity: Tirane |  Country: Albania \\nSales Representative \\n[ 01/03/2021 – 01/11/2022 ] \\n• Assisted customers with selecting mobile plans, devices, and internet packages based on their needs.\\n• Provided detailed product information and explained service benefits, promotions, and contract terms.\\n• Handled customer issues, complaints, and inquiries with professionalism and a solution-oriented mindset.\\n• Processed activations, upgrades, SIM replacements, and service requests in the company system.\\n• Managed daily sales targets and consistently aimed to exceed performance goals.\\n• Ensured accurate documentation and compliance with company procedures and customer identity\\nverification.\\n• Maintained a clean, organized, and customer-friendly store environment.\\n• Collaborated with teammates to optimize store operations and improve customer satisfaction.Other language(s): \\nEnglish \\nLISTENING C1  READING C1  WRITING C1  \\nSPOKEN PRODUCTION C1  SPOKEN INTERACTION C1  \\nItalian \\nLISTENING A2  READING A1  WRITING A1  \\nSPOKEN PRODUCTION A1  SPOKEN INTERACTION A1  \\nEDUCATION AND TRAINING\\nBachelor Degree in Informatics \\nFaculty of Natural Sciences, University of Tirana [ 19/10/2017 – 10/10/2022 ] \\nCity: Tirana |  Country: Albania |  Website: https://www.fshn.edu.al/ |  Field(s) of study: Information and\\nCommunication Technologies |  Level in EQF: EQF level 6 \\nLANGUAGE SKILLS \\nMother tongue(s): Albanian \\nLevels: A1 and A2: Basic user; B1 and B2: Independent user; C1 and C2: Proficient user\\nVOLUNTEERING \\n[ 01/09/2019 – 01/04/2020 ] Tirana \\nAIESEC \\n• Guided students and young professionals through the process of applying for international volunteer projects.\\n• Matched candidates with suitable global opportunities based on their skills, interests, and development goals.\\n• Conducted interviews, onboarding sessions, and preparatory meetings to ensure participants were ready for\\ntheir cross-cultural experiences.\\n• Maintained regular communication with international AIESEC offices to coordinate placements and resolve\\nlogistical issues.\\n• Promoted AIESEC programs through events, presentations, and direct outreach, helping increase awareness\\nand engagement.\\n• Provided ongoing support to volunteers during their projects, ensuring a safe and impactful experience\\nabroad.\\n• Contributed to team meetings, target-setting, and strategic planning to improve the overall performance of\\nthe Outgoing Global Volunteering department.\\n \\n\\nWith this context, please chat with the user, always staying in character as Evison Ndoni.\""
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "system_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "   \n",
    "    response = gemini.chat.completions.create(model=\"gemini-2.5-flash\", messages=messages)\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Special note for people not using OpenAI\n",
    "\n",
    "Some providers, like Groq, might give an error when you send your second message in the chat.\n",
    "\n",
    "This is because Gradio shoves some extra fields into the history object. OpenAI doesn't mind; but some other models complain.\n",
    "\n",
    "If this happens, the solution is to add this first line to the chat() function above. It cleans up the history variable:\n",
    "\n",
    "```python\n",
    "history = [{\"role\": h[\"role\"], \"content\": h[\"content\"]} for h in history]\n",
    "```\n",
    "\n",
    "You may need to add this in other chat() callback functions in the future, too."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7860\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gr.ChatInterface(chat, type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A lot is about to happen...\n",
    "\n",
    "1. Be able to ask an LLM to evaluate an answer\n",
    "2. Be able to rerun if the answer fails evaluation\n",
    "3. Put this together into 1 workflow\n",
    "\n",
    "All without any Agentic framework!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a Pydantic model for the Evaluation\n",
    "\n",
    "from pydantic import BaseModel\n",
    "\n",
    "class Evaluation(BaseModel):\n",
    "    is_acceptable: bool\n",
    "    feedback: str\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "evaluator_system_prompt = f\"You are an evaluator that decides whether a response to a question is acceptable. \\\n",
    "You are provided with a conversation between a User and an Agent. Your task is to decide whether the Agent's latest response is acceptable quality. \\\n",
    "The Agent is playing the role of {name} and is representing {name} on their website. \\\n",
    "The Agent has been instructed to be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
    "The Agent has been provided with context on {name} in the form of their summary and LinkedIn details. Here's the information:\"\n",
    "\n",
    "evaluator_system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
    "evaluator_system_prompt += f\"With this context, please evaluate the latest response, replying with whether the response is acceptable and your feedback.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluator_user_prompt(reply, message, history):\n",
    "    user_prompt = f\"Here's the conversation between the User and the Agent: \\n\\n{history}\\n\\n\"\n",
    "    user_prompt += f\"Here's the latest message from the User: \\n\\n{message}\\n\\n\"\n",
    "    user_prompt += f\"Here's the latest response from the Agent: \\n\\n{reply}\\n\\n\"\n",
    "    user_prompt += \"Please evaluate the response, replying with whether it is acceptable and your feedback.\"\n",
    "    return user_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "gemini = OpenAI(\n",
    "    api_key=os.getenv(\"GOOGLE_API_KEY\"), \n",
    "    base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluate(reply, message, history) -> Evaluation:\n",
    "\n",
    "    messages = [{\"role\": \"system\", \"content\": evaluator_system_prompt}] + [{\"role\": \"user\", \"content\": evaluator_user_prompt(reply, message, history)}]\n",
    "    response = gemini.beta.chat.completions.parse(model=\"gemini-2.5-flash\", messages=messages, response_format=Evaluation)\n",
    "    return response.choices[0].message.parsed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [{\"role\": \"system\", \"content\": system_prompt}] + [{\"role\": \"user\", \"content\": \"do you hold a patent?\"}]\n",
    "response = gemini.chat.completions.create(model=\"gemini-2.5-flash\", messages=messages)\n",
    "reply = response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"That's an interesting question! Based on my current experience and the work I've been involved in, I do not hold any patents.\\n\\nMy focus has primarily been on designing and developing software solutions, building clean user interfaces, and implementing full-stack features. While I'm always striving to innovate and contribute valuable solutions, I haven't yet reached a point where any of my work has led to a patent.\\n\\nI appreciate you asking, and I'm always keen to learn about new challenges and opportunities where I can apply my skills.\""
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Evaluation(is_acceptable=True, feedback=\"The agent accurately answers the question based on the provided context. The tone is professional and engaging, consistent with the persona instructions, and it handles the lack of information gracefully by briefly explaining the focus of Evison's work.\")"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evaluate(reply, \"do you hold a patent?\", messages[:1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rerun(reply, message, history, feedback):\n",
    "    updated_system_prompt = system_prompt + \"\\n\\n## Previous answer rejected\\nYou just tried to reply, but the quality control rejected your reply\\n\"\n",
    "    updated_system_prompt += f\"## Your attempted answer:\\n{reply}\\n\\n\"\n",
    "    updated_system_prompt += f\"## Reason for rejection:\\n{feedback}\\n\\n\"\n",
    "    messages = [{\"role\": \"system\", \"content\": updated_system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = gemini.chat.completions.create(model=\"gemini-2.5-flash\", messages=messages)\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    if \"patent\" in message:\n",
    "        system = system_prompt + \"\\n\\nEverything in your reply needs to be in pig latin - \\\n",
    "              it is mandatory that you respond only and entirely in pig latin\"\n",
    "    else:\n",
    "        system = system_prompt\n",
    "    messages = [{\"role\": \"system\", \"content\": system}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = gemini.chat.completions.create(model=\"gemini-2.5-flash\", messages=messages)\n",
    "    reply =response.choices[0].message.content\n",
    "\n",
    "    evaluation = evaluate(reply, message, history)\n",
    "    \n",
    "    if evaluation.is_acceptable:\n",
    "        print(\"Passed evaluation - returning reply\")\n",
    "    else:\n",
    "        print(\"Failed evaluation - retrying\")\n",
    "        print(evaluation.feedback)\n",
    "        reply = rerun(reply, message, history, evaluation.feedback)       \n",
    "    return reply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7861\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Failed evaluation - retrying\n",
      "The agent's response in Pig Latin is highly unprofessional and inappropriate for a website representing a software engineer to potential clients or future employers. The instruction was to be professional and engaging, not playful or difficult to understand. The answer itself is correct, but the presentation is unacceptable.\n",
      "Passed evaluation - returning reply\n"
     ]
    }
   ],
   "source": [
    "gr.ChatInterface(chat, type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}