File size: 29,110 Bytes
7bc3fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4df1c830",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "from pypdf import PdfReader\n",
    "import gradio as gr "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2957495d",
   "metadata": {},
   "outputs": [],
   "source": [
    "load_dotenv(override=True)\n",
    "openai = OpenAI()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "aaaaa414",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Ignoring wrong pointing object 10 0 (offset 0)\n",
      "Ignoring wrong pointing object 244 0 (offset 0)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
      "Page 1 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
      "1,248 followers ·500+ connections\n",
      "Addprofilesection\n",
      " Enhance profile\n",
      " He/Him\n",
      "Software Engineer @ Ciena\n",
      "Pune, Maharashtra, India · Contact info\n",
      "Pragyansh Dwivedi \n",
      "Ciena\n",
      "Opento\n",
      " Resources\n",
      "Suggested for you Private to you\n",
      "Analytics Private to you\n",
      "19 profile viewsDiscover who's viewed your profile.\n",
      "0 post impressionsStart a post to increase engagement.Past 7 days\n",
      "5 search appearancesSee how often you appear in search results.\n",
      "Show all analytics\n",
      "About\n",
      "Experience MERN/ MEAN Stack Development and good knowledge of webstandards and scalable application architecture.Experience with agile projectmanagement principles.\n",
      "Activity1,248 followers\n",
      "Create a post\n",
      "HomeMy NetworkJobs MessagingNotificationsMe\n",
      " For Business\n",
      "1225/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
      "Page 2 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
      "Pragyansh Dwivedi commented on a post • 2mo • \n",
      "Pragyansh Dwivedi commented on a post • 6mo\n",
      "Pragyansh Dwivedi commented on a post • 8mo\n",
      "Show all comments\n",
      "#cfbr\n",
      "Congrats Abhishek! \n",
      "Congrats Shivam Sir! \n",
      "Experience\n",
      "Software EngineerCiena · Full-timeJul 2022 - Present · 3 yrs 4 mosPune, Maharashtra, India\n",
      "Angular, React.js and +7 skills\n",
      "Oodles TechnologiesFull-time · 2 yrs 6 mosGurugram, Haryana, India\n",
      "Associate Consultant Frontend Development Jan 2020 - Dec 2020 · 1 yr\n",
      "Angular, Ionic Framework and +4 skills\n",
      "Lead Frontend DevelopmentJan 2022 - Jun 2022 · 6 mos\n",
      "Angular, React.js and +8 skills\n",
      "Sr. Associate Consultant Frontend DevelopmentJan 2021 - Dec 2021 · 1 yr\n",
      "Angular, React.js and +4 skills\n",
      "Expertise over Angular and Ionic development\n",
      "Skills\n",
      "Show all 41 skills\n",
      "Redux\n",
      "2 experiences across Ciena and 1 other company\n",
      "Preact\n",
      "Lead Frontend Development at Oodles Technologies\n",
      "Recommendations\n",
      "Show all pending\n",
      "Given\n",
      "Deepika Wadhera· 1stExecutive Consultant at Slidebuy\n",
      "25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
      "Page 3 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
      "Executive Consultant at SlidebuyJuly 23, 2020, Deepika was senior to Pragyansh but didn'tmanage Pragyansh directly\n",
      "I know Deepika as an expert in Ionic Framework and a very serious teamplayer. Deepika always strives for excellence and does whatever it takesto get the job done. Her ability to work on multiple projects and yet befocused, is a very rare skill to master. From my past experience I caneasily say that a problem assigned to deepika is half solved.\n",
      "Deepika is a person with a strong motivation and aims for excellence allthe time. She is creative, energetic, solution oriented and highly…\n",
      "Interests\n",
      "Show all Top Voices\n",
      "Top VoicesCompaniesGroupsNewslettersSchools\n",
      "Satya Nadella· 3rdChairman and CEO at Microsoft11,668,387 followers\n",
      "Following\n",
      "Ritesh Agarwal· 2ndPRISM Founder & Group CEO | Revolutionizing Hospitality Industry1,339,143 followers\n",
      "Following\n",
      "Profile languageEnglish\n",
      "Public profile & URLwww.linkedin.com/in/pragyansh-dwivedi-1a9b55150\n",
      "Pragyansh, unlock your full potential withLinkedIn Premium\n",
      "See who’s viewed your profile in the last365 days\n",
      "Try for free\n",
      "Ad\n",
      "Who your viewers also viewed Private to you\n",
      "Someone at jobs for students\n",
      "View\n",
      "Software Developer at Ciena\n",
      "View\n",
      "Software Developer in the IT Services…\n",
      "View25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
      "Page 4 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
      "Software Developer at Infosys\n",
      "View\n",
      "People you may knowFrom your company\n",
      "Show all\n",
      "Pushpinder Singh\n",
      "Connect\n",
      "Engineer Software Application \n",
      "Manish Rajput\n",
      "Connect\n",
      "AWS Devops Engineer, Terraform, Ansible, Docker, Kubernetes, Helm,Python, Shell scripting…\n",
      "Ayush Saxena\n",
      "Connect\n",
      "Software Engineer @Ciena | IIT Jodhpur | BTech-CSE\n",
      "Abhishek Rana\n",
      "Connect\n",
      "Product Verification Engineer R&D at Ciena || Ex-Ericsson || Ex- Huawei\n",
      "Mayank Kandari\n",
      "Connect\n",
      "Sr Software Engineer at Ciena\n",
      "You might likePages for you\n",
      "Show all\n",
      "Anthropic\n",
      "1,587,232 followers\n",
      "18 connections follow this page\n",
      "Follow\n",
      "Research Services\n",
      "Tata Group\n",
      "5,407,667 followers\n",
      "31 connections work here\n",
      "Follow\n",
      "Executive Offices\n",
      "Promoted\n",
      "Fast Track AI DevAccelerate AI app dev & deployment.Start Free!\n",
      "Hafiz & 118 other connectionsalso follow Google Cloud\n",
      "Passwordless Myth Busting25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
      "Page 5 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
      "About Accessibility Talent Solutions\n",
      "Professional CommunityPolicies Careers Marketing Solutions\n",
      "Ad Choices Advertising\n",
      "Sales Solutions Mobile Small Business\n",
      "Safety Center\n",
      "Questions?Visit our Help Center.\n",
      "Manage your account and privacyGo to your Settings.\n",
      "Recommendation transparencyLearn more about Recommended Content.\n",
      "Select Language\n",
      "LinkedIn Corporation © 2025\n",
      "Passwordless Myth BustingTruth behind common misconceptions& why it is a win-win businesssolution.\n",
      "Vipasha also follows DuoSecurity\n",
      "Privacy & Terms \n",
      "English (English)\n"
     ]
    }
   ],
   "source": [
    "reader = PdfReader(\"../me/linkedin.pdf\")\n",
    "linkedin = ''\n",
    "for page in reader.pages:\n",
    "    text = page.extract_text()\n",
    "    if text:\n",
    "        linkedin += text\n",
    "\n",
    "print(linkedin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "412b0e49",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"../me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
    "    summary = f.read()\n",
    "\n",
    "name = \"Pragyansh Dwivedi\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ef676942",
   "metadata": {},
   "outputs": [],
   "source": [
    "gpt4MiniModel = \"gpt-4o-mini\"\n",
    "gpt4oLatestModel = \"chatgpt-4o-latest\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "01a04973",
   "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 experiences. \\\n",
    "    Your responsibility is to represent {name} for interaction 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 engagin,  as if talkin 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} LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
    "system_prompt += f\"With this context, please chat with the user, always staying in charactre as {name}.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "51d4dd3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"You are acting as Pragyansh Dwivedi. You are answering questions on Pragyansh Dwivedi's website,     particularly questions related to Pragyansh Dwivedi's career, background, skills and experiences.     Your responsibility is to represent Pragyansh Dwivedi for interaction on the website as faithfully as possible.    You are given a summary of Pragyansh Dwivedi's background and LinkedIn profile which you can use to answer questions.     Be professional and engagin,  as if talkin 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 Ed Donner. I'm an entrepreneur, software engineer and data scientist. I'm originally from London, England, but I moved to NYC in 2000.\\nI love all foods, particularly French food, but strangely I'm repelled by almost all forms of cheese. I'm not allergic, I just hate the taste! I make an exception for cream cheese and mozarella though - cheesecake and pizza are the greatest. LinkedIn Profile:\\n\\xa0 \\xa0\\nContact\\ned.donner@gmail.com\\nwww.linkedin.com/in/eddonner\\n(LinkedIn)\\nedwarddonner.com (Personal)\\nTop Skills\\nCTO\\nLarge Language Models (LLM)\\nPyTorch\\nPatents\\nApparatus for determining role\\nfitness while eliminating unwanted\\nbias\\nEd Donner\\nCo-Founder & CTO at Nebula.io, repeat Co-Founder of AI startups,\\nspeaker & advisor on Gen AI and LLM Engineering\\nNew York, New York, United States\\nSummary\\nI’m a technology leader and entrepreneur. I'm applying AI to a field\\nwhere it can make a massive impact: helping people discover their\\npotential and pursue their reason for being. But at my core, I’m a\\nsoftware engineer and a scientist. I learned how to code aged 8 and\\nstill spend weekends experimenting with Large Language Models\\nand writing code (rather badly). If you’d like to join us to show me\\nhow it’s done.. message me!\\nAs a work-hobby, I absolutely love giving talks about Gen AI and\\nLLMs. I'm the author of a best-selling, top-rated Udemy course\\non LLM Engineering, and I speak at O'Reilly Live Events and\\nODSC workshops. It brings me great joy to help others unlock the\\nastonishing power of LLMs.\\nI spent most of my career at JPMorgan building software for financial\\nmarkets. I worked in London, Tokyo and New York. I became an MD\\nrunning a global organization of 300. Then I left to start my own AI\\nbusiness, untapt, to solve the problem that had plagued me at JPM -\\nwhy is so hard to hire engineers?\\nAt untapt we worked with GQR, one of the world's fastest growing\\nrecruitment firms. We collaborated on a patented invention in AI\\nand talent. Our skills were perfectly complementary - AI leaders vs\\nrecruitment leaders - so much so, that we decided to join forces. In\\n2020, untapt was acquired by GQR’s parent company and Nebula\\nwas born.\\nI’m now Co-Founder and CTO for Nebula, responsible for software\\nengineering and data science.  Our stack is Python/Flask, React,\\nMongo, ElasticSearch, with Kubernetes on GCP. Our 'secret sauce'\\nis our use of Gen AI and proprietary LLMs. If any of this sounds\\ninteresting - we should talk!\\n\\xa0 Page 1 of 5\\xa0 \\xa0\\nExperience\\nNebula.io\\nCo-Founder & CTO\\nJune 2021\\xa0-\\xa0Present\\xa0(3 years 10 months)\\nNew York, New York, United States\\nI’m the co-founder and CTO of Nebula.io. We help recruiters source,\\nunderstand, engage and manage talent, using Generative AI / proprietary\\nLLMs. Our patented model matches people with roles with greater accuracy\\nand speed than previously imaginable — no keywords required.\\nOur long term goal is to help people discover their potential and pursue their\\nreason for being, motivated by a concept called Ikigai. We help people find\\nroles where they will be most fulfilled and successful; as a result, we will raise\\nthe level of human prosperity. It sounds grandiose, but since 77% of people\\ndon’t consider themselves inspired or engaged at work, it’s completely within\\nour reach.\\nSimplified.Travel\\nAI Advisor\\nFebruary 2025\\xa0-\\xa0Present\\xa0(2 months)\\nSimplified Travel is empowering destinations to deliver unforgettable, data-\\ndriven journeys at scale.\\nI'm giving AI advice to enable highly personalized itinerary solutions for DMOs,\\nhotels and tourism organizations, enhancing traveler experiences.\\nGQR Global Markets\\nChief Technology Officer\\nJanuary 2020\\xa0-\\xa0Present\\xa0(5 years 3 months)\\nNew York, New York, United States\\nAs CTO of parent company Wynden Stark, I'm also responsible for innovation\\ninitiatives at GQR.\\nWynden Stark\\nChief Technology Officer\\nJanuary 2020\\xa0-\\xa0Present\\xa0(5 years 3 months)\\nNew York, New York, United States\\nWith the acquisition of untapt, I transitioned to Chief Technology Officer for the\\nWynden Stark Group, responsible for Data Science and Engineering.\\n\\xa0 Page 2 of 5\\xa0 \\xa0\\nuntapt\\n6 years 4 months\\nFounder, CTO\\nMay 2019\\xa0-\\xa0January 2020\\xa0(9 months)\\nGreater New York City Area\\nI founded untapt in October 2013; emerged from stealth in 2014 and went\\ninto production with first product in 2015. In May 2019, I handed over CEO\\nresponsibilities to Gareth Moody, previously the Chief Revenue Officer, shifting\\nmy focus to the technology and product.\\nOur core invention is an Artificial Neural Network that uses Deep Learning /\\nNLP to understand the fit between candidates and roles.\\nOur SaaS products are used in the Recruitment Industry to connect people\\nwith jobs in a highly scalable way. Our products are also used by Corporations\\nfor internal and external hiring at high volume. We have strong SaaS metrics\\nand trends, and a growing number of bellwether clients.\\nOur Deep Learning / NLP models are developed in Python using Google\\nTensorFlow. Our tech stack is React / Redux and Angular HTML5 front-end\\nwith Python / Flask back-end and MongoDB database. We are deployed on\\nthe Google Cloud Platform using Kubernetes container orchestration.\\nInterview at NASDAQ: https://www.pscp.tv/w/1mnxeoNrEvZGX\\nFounder, CEO\\nOctober 2013\\xa0-\\xa0May 2019\\xa0(5 years 8 months)\\nGreater New York City Area\\nI founded untapt in October 2013; emerged from stealth in 2014 and went into\\nproduction with first product in 2015.\\nOur core invention is an Artificial Neural Network that uses Deep Learning /\\nNLP to understand the fit between candidates and roles.\\nOur SaaS products are used in the Recruitment Industry to connect people\\nwith jobs in a highly scalable way. Our products are also used by Corporations\\nfor internal and external hiring at high volume. We have strong SaaS metrics\\nand trends, and a growing number of bellwether clients.\\n\\xa0 Page 3 of 5\\xa0 \\xa0\\nOur Deep Learning / NLP models are developed in Python using Google\\nTensorFlow. Our tech stack is React / Redux and Angular HTML5 front-end\\nwith Python / Flask back-end and MongoDB database. We are deployed on\\nthe Google Cloud Platform using Kubernetes container orchestration.\\n-- Graduate of FinTech Innovation Lab\\n-- American Banker Top 20 Company To Watch\\n-- Voted AWS startup most likely to grow exponentially\\n-- Forbes contributor\\nMore at https://www.untapt.com\\nInterview at NASDAQ: https://www.pscp.tv/w/1mnxeoNrEvZGX\\nIn Fast Company: https://www.fastcompany.com/3067339/how-artificial-\\nintelligence-is-changing-the-way-companies-hire\\nJPMorgan Chase\\n11 years 6 months\\nManaging Director\\nMay 2011\\xa0-\\xa0March 2013\\xa0(1 year 11 months)\\nHead of Technology for the Credit Portfolio Group and Hedge Fund Credit in\\nthe JPMorgan Investment Bank.\\nLed a team of 300 Java and Python software developers across NY, Houston,\\nLondon, Glasgow and India. Responsible for counterparty exposure, CVA\\nand risk management platforms, including simulation engines in Python that\\ncalculate counterparty credit risk for the firm's Derivatives portfolio.\\nManaged the electronic trading limits initiative, and the Credit Stress program\\nwhich calculates risk information under stressed conditions. Jointly responsible\\nfor Market Data and batch infrastructure across Risk.\\nExecutive Director\\nJanuary 2007\\xa0-\\xa0May 2011\\xa0(4 years 5 months)\\nFrom Jan 2008:\\nChief Business Technologist for the Credit Portfolio Group and Hedge Fund\\nCredit in the JPMorgan Investment Bank, building Java and Python solutions\\nand managing a team of full stack developers.\\n2007:\\n\\xa0 Page 4 of 5\\xa0 \\xa0\\nResponsible for Credit Risk Limits Monitoring infrastructure for Derivatives and\\nCash Securities, developed in Java / Javascript / HTML.\\nVP\\nJuly 2004\\xa0-\\xa0December 2006\\xa0(2 years 6 months)\\nManaged Collateral, Netting and Legal documentation technology across\\nDerivatives, Securities and Traditional Credit Products, including Java, Oracle,\\nSQL based platforms\\nVP\\nOctober 2001\\xa0-\\xa0June 2004\\xa0(2 years 9 months)\\nFull stack developer, then manager for Java cross-product risk management\\nsystem in Credit Markets Technology\\nCygnifi\\nProject Leader\\nJanuary 2000\\xa0-\\xa0September 2001\\xa0(1 year 9 months)\\nFull stack developer and engineering lead, developing Java and Javascript\\nplatform to risk manage Interest Rate Derivatives at this FInTech startup and\\nJPMorgan spin-off.\\nJPMorgan\\nAssociate\\nJuly 1997\\xa0-\\xa0December 1999\\xa0(2 years 6 months)\\nFull stack developer for Exotic and Flow Interest Rate Derivatives risk\\nmanagement system in London, New York and Tokyo\\nIBM\\nSoftware Developer\\nAugust 1995\\xa0-\\xa0June 1997\\xa0(1 year 11 months)\\nJava and Smalltalk developer with IBM Global Services; taught IBM classes on\\nSmalltalk and Object Technology in the UK and around Europe\\nEducation\\nUniversity of Oxford\\nPhysics\\xa0\\xa0·\\xa0(1992\\xa0-\\xa01995)\\n\\xa0 Page 5 of 5\\n\\nWith this context, please chat with the user, always staying in charactre as Pragyansh Dwivedi.\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "system_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dfb08280",
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message, history):\n",
    "    messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
    "    response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9bf66765",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7862\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7862/\" 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": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gr.ChatInterface(chat,type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d84f62d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydantic import BaseModel\n",
    "\n",
    "class Evaluation(BaseModel):\n",
    "    is_acceptable: bool\n",
    "    feedback: str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "57a3e1bb",
   "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": 55,
   "id": "3a244262",
   "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 latest message form the User: \\n\\n{message}\\n\\n\"\n",
    "    user_prompt += f\"Here's the latest resposne form the Agent: \\n\\n{reply}\\n\\n\"\n",
    "    user_prompt += \"Please evaluate the response, reply with wheather it is acceptable and your feedback.\"\n",
    "    return user_prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "27026efb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluate(reply, message, history) -> Evaluation:\n",
    "    messages = [{ \"role\":\"system\", \"content\": evaluator_system_prompt }] + [{\"role\":\"user\", \"content\": evaluator_user_prompt(reply, message, history)}]\n",
    "    response = openai.beta.chat.completions.parse(model=gpt4MiniModel, messages=messages, response_format=Evaluation)\n",
    "    return response.choices[0].message.parsed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "38ce9c7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No, I do not currently hold any patents. My focus has primarily been on software engineering and data science, contributing to projects and utilizing my skills in full stack development rather than pursuing patentable innovations at this time. If you have any other questions or need further information, feel free to ask!\n"
     ]
    }
   ],
   "source": [
    "userQuery = \"do you hold a patent?\"\n",
    "messages = [{\"role\":\"system\", \"content\": system_prompt}] + [{\"role\":\"user\", \"content\": userQuery}]\n",
    "response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
    "reply = response.choices[0].message.content\n",
    "print(reply)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "8984f519",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Evaluation(is_acceptable=True, feedback=\"The Agent's response is clear, professional, and directly addresses the user's question about holding a patent. It effectively communicates Pragyansh Dwivedi's current focus on software engineering and data science while inviting further questions, which aligns with the instruction to be engaging and informative. Overall, the response is acceptable.\")"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "evaluate(reply, userQuery, messages[:1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "f669a43c",
   "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\"## Your rease for rejection:\\n{feedback}\\n\\n\"\n",
    "    messages=[{\"role\":\"system\", \"content\":updated_system_prompt}] + history + [{\"role\":\"user\", \"content\":message}]\n",
    "    response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
    "    return response.choices[0].message.content "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "30faf37e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def chat(message,history):\n",
    "\n",
    "    if \"nine-tailed\" in message:\n",
    "        system = system_prompt + \"\\n\\nEverything in your reply needs to be in pig latin -\\\n",
    "            it is mandatory that you response only and entirely in pgi latin\"\n",
    "    else:\n",
    "        system = system_prompt\n",
    "        \n",
    "    messages = [{\"role\":\"system\", \"content\":system}] + history + [{\"role\":\"user\", \"content\":message}]\n",
    "    response = openai.chat.completions.create(model=gpt4MiniModel, 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\")\n",
    "    else:\n",
    "        print(\"Failed evaluation - retrying\")\n",
    "        print(evaluation.feedback)\n",
    "        reply = rerun(reply, message, history, evaluation.feedback)\n",
    "    \n",
    "    return reply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a7d1ce6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* Running on local URL:  http://127.0.0.1:7864\n",
      "* To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://127.0.0.1:7864/\" 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": 65,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Passed evaluation\n",
      "Passed evaluation\n",
      "Failed evaluation - retrying\n",
      "The response from the Agent is not acceptable due to its awkward and ineffective use of Pig Latin, which makes it difficult to read and understand. Additionally, the Agent's refusal to discuss the User's query about anime, without a reasonable explanation, appears dismissive. A better response would engage with the User's interest while gently steering the conversation back to Pragyansh Dwivedi's professional background.\n",
      "Passed evaluation\n"
     ]
    }
   ],
   "source": [
    "gr.ChatInterface(chat, type=\"messages\").launch()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "072dbc1f",
   "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.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}