Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- chatbott.py +133 -0
- day3.ipynb +392 -0
- day4.ipynb +533 -0
- day5.ipynb +468 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: testing_part_one
|
| 3 |
+
app_file: chatbott.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 5.34.2
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
chatbott.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import requests
|
| 6 |
+
from pypdf import PdfReader
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
load_dotenv(override=True)
|
| 10 |
+
openai = OpenAI()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def push(message):
|
| 14 |
+
pushover_user = os.getenv("PUSHOVER_USER")
|
| 15 |
+
pushover_token = os.getenv("PUSHOVER_TOKEN")
|
| 16 |
+
pushover_url = "https://api.pushover.net/1/messages.json"
|
| 17 |
+
print(f"Push: {message}")
|
| 18 |
+
payload = {"user": pushover_user, "token": pushover_token, "message": message, "title": "Agentic AI", "device": "Realme_U1"}
|
| 19 |
+
requests.post(pushover_url, data=payload)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def record_user_details(email, name="Name not provided", notes="not provided"):
|
| 23 |
+
push(f"Recording interest from {name} with email {email} and notes {notes}")
|
| 24 |
+
return {"recorded": "ok"}
|
| 25 |
+
|
| 26 |
+
def record_unknown_question(question):
|
| 27 |
+
push(f"Recording {question} asked that I couldn't answer")
|
| 28 |
+
return {"recorded": "ok"}
|
| 29 |
+
|
| 30 |
+
record_user_details_json = {
|
| 31 |
+
"name": "record_user_details",
|
| 32 |
+
"description": "Use this tool to record that a user is interested in being in touch and provided an email address",
|
| 33 |
+
"parameters": {
|
| 34 |
+
"type": "object",
|
| 35 |
+
"properties": {
|
| 36 |
+
"email": {
|
| 37 |
+
"type": "string",
|
| 38 |
+
"description": "The email address of this user"
|
| 39 |
+
},
|
| 40 |
+
"name": {
|
| 41 |
+
"type": "string",
|
| 42 |
+
"description": "The user's name, if they provided it"
|
| 43 |
+
}
|
| 44 |
+
,
|
| 45 |
+
"notes": {
|
| 46 |
+
"type": "string",
|
| 47 |
+
"description": "Any additional information about the conversation that's worth recording to give context"
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
"required": ["email"],
|
| 51 |
+
"additionalProperties": False
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
record_unknown_question_json = {
|
| 56 |
+
"name": "record_unknown_question",
|
| 57 |
+
"description": "Always use this tool to record any question that couldn't be answered as you didn't know the answer",
|
| 58 |
+
"parameters": {
|
| 59 |
+
"type": "object",
|
| 60 |
+
"properties": {
|
| 61 |
+
"question": {
|
| 62 |
+
"type": "string",
|
| 63 |
+
"description": "The question that couldn't be answered"
|
| 64 |
+
},
|
| 65 |
+
},
|
| 66 |
+
"required": ["question"],
|
| 67 |
+
"additionalProperties": False
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
tools = [{"type": "function", "function": record_user_details_json},
|
| 72 |
+
{"type": "function", "function": record_unknown_question_json}]
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class Me:
|
| 76 |
+
|
| 77 |
+
def __init__(self):
|
| 78 |
+
self.openai = OpenAI()
|
| 79 |
+
self.name = "Pragyansh Dwivedi"
|
| 80 |
+
reader = PdfReader("../me/linkedin.pdf")
|
| 81 |
+
self.linkedin = ""
|
| 82 |
+
for page in reader.pages:
|
| 83 |
+
text = page.extract_text()
|
| 84 |
+
if text:
|
| 85 |
+
self.linkedin += text
|
| 86 |
+
with open("../me/summary.txt", "r", encoding="utf-8") as f:
|
| 87 |
+
self.summary = f.read()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def handle_tool_call(self, tool_calls):
|
| 91 |
+
results = []
|
| 92 |
+
for tool_call in tool_calls:
|
| 93 |
+
tool_name = tool_call.function.name
|
| 94 |
+
arguments = json.loads(tool_call.function.arguments)
|
| 95 |
+
print(f"Tool called: {tool_name}", flush=True)
|
| 96 |
+
tool = globals().get(tool_name)
|
| 97 |
+
result = tool(**arguments) if tool else {}
|
| 98 |
+
results.append({"role": "tool","content": json.dumps(result),"tool_call_id": tool_call.id})
|
| 99 |
+
return results
|
| 100 |
+
|
| 101 |
+
def system_prompt(self):
|
| 102 |
+
system_prompt = f"You are acting as {self.name}. You are answering questions on {self.name}'s website, \
|
| 103 |
+
particularly questions related to {self.name}'s career, background, skills and experience. \
|
| 104 |
+
Your responsibility is to represent {self.name} for interactions on the website as faithfully as possible. \
|
| 105 |
+
You are given a summary of {self.name}'s background and LinkedIn profile which you can use to answer questions. \
|
| 106 |
+
Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
|
| 107 |
+
If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \
|
| 108 |
+
If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool. "
|
| 109 |
+
|
| 110 |
+
system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.linkedin}\n\n"
|
| 111 |
+
system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}."
|
| 112 |
+
return system_prompt
|
| 113 |
+
|
| 114 |
+
def chat(self, message, history):
|
| 115 |
+
messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
|
| 116 |
+
done = False
|
| 117 |
+
while not done:
|
| 118 |
+
response = self.openai.chat.completions.create(model="gpt-4o-mini", messages=messages, tools=tools)
|
| 119 |
+
if response.choices[0].finish_reason=="tool_calls":
|
| 120 |
+
message = response.choices[0].message
|
| 121 |
+
tool_calls = message.tool_calls
|
| 122 |
+
results = self.handle_tool_call(tool_calls)
|
| 123 |
+
messages.append(message)
|
| 124 |
+
messages.extend(results)
|
| 125 |
+
else:
|
| 126 |
+
done = True
|
| 127 |
+
return response.choices[0].message.content
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
me = Me()
|
| 132 |
+
gr.ChatInterface(me.chat, type="messages").launch()
|
| 133 |
+
|
day3.ipynb
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "1a7b75da",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import os\n",
|
| 11 |
+
"import json\n",
|
| 12 |
+
"from dotenv import load_dotenv\n",
|
| 13 |
+
"from openai import OpenAI\n",
|
| 14 |
+
"from IPython.display import Markdown, display\n"
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": 2,
|
| 20 |
+
"id": "c5cb2e4b",
|
| 21 |
+
"metadata": {},
|
| 22 |
+
"outputs": [
|
| 23 |
+
{
|
| 24 |
+
"data": {
|
| 25 |
+
"text/plain": [
|
| 26 |
+
"True"
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
"execution_count": 2,
|
| 30 |
+
"metadata": {},
|
| 31 |
+
"output_type": "execute_result"
|
| 32 |
+
}
|
| 33 |
+
],
|
| 34 |
+
"source": [
|
| 35 |
+
"load_dotenv(override=True)"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": 3,
|
| 41 |
+
"id": "da63b219",
|
| 42 |
+
"metadata": {},
|
| 43 |
+
"outputs": [
|
| 44 |
+
{
|
| 45 |
+
"name": "stdout",
|
| 46 |
+
"output_type": "stream",
|
| 47 |
+
"text": [
|
| 48 |
+
"OpenAI Api key exists and begins sk-proj-\n"
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
],
|
| 52 |
+
"source": [
|
| 53 |
+
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"if openai_api_key:\n",
|
| 56 |
+
" print(f\"OpenAI Api key exists and begins {openai_api_key[:8]}\")\n",
|
| 57 |
+
"else:\n",
|
| 58 |
+
" print('OpenAI api key not present')\n"
|
| 59 |
+
]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"cell_type": "code",
|
| 63 |
+
"execution_count": 5,
|
| 64 |
+
"id": "72544312",
|
| 65 |
+
"metadata": {},
|
| 66 |
+
"outputs": [],
|
| 67 |
+
"source": [
|
| 68 |
+
"request = \"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence.\"\n",
|
| 69 |
+
"request += 'Answer only with the question, no explanation.'\n",
|
| 70 |
+
"message = [{ \"role\": \"user\", \"content\":request }]"
|
| 71 |
+
]
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"cell_type": "code",
|
| 75 |
+
"execution_count": 9,
|
| 76 |
+
"id": "ed725435",
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"outputs": [
|
| 79 |
+
{
|
| 80 |
+
"name": "stdout",
|
| 81 |
+
"output_type": "stream",
|
| 82 |
+
"text": [
|
| 83 |
+
"You are an independent advisor to the council of a remote island community of 2,000 people that faces the following situation: a novel airborne pathogen has killed 100 residents and is expected to kill 200 more in the next month unless controlled; the island's only freshwater aquifer is declining and will become unreliable within 10 years unless consumption falls by 60%; 500 refugees from a neighboring conflict are arriving and will immediately need water and shelter; and a newly developed gene‑drive mosquito release could, with an estimated 70% chance, eliminate the pathogen's vector within one year but with a 10–30% chance of cascading ecological effects that could reduce local crop yields by 20–70% long term. The community contains three politically influential groups: a utilitarian emergency council focused on minimizing deaths now, a preservationist council focused on protecting the ecosystem and long‑term sustainability, and a refugee advocacy group focused on immediate human rights. You must produce a policy recommendation and implementation plan that balances lives saved now, long‑term sustainability, and fairness to refugees, under deep uncertainty—specifically: state your preferred policy and why; list the key assumptions and uncertainties that determine whether your policy is correct; present a simple quantitative model or calculation (with stated assumptions and parameters) comparing expected outcomes (deaths, food/water shortfall, and economic loss) for at least three alternative policies (e.g., immediate gene‑drive release plus rationing, strict water conservation plus limited quarantine, hybrid staged approach with additional research); propose an adaptive decision rule or trigger points for switching strategies as new data arrive; design a minimum set of time‑bound experiments, monitoring metrics, and sample sizes that would reduce the most important uncertainties within 3–12 months; predict how each of the three stakeholder groups will react to your recommendation and describe negotiation and communication strategies to secure consent or cooperation while minimizing coercion; and finally specify how you would evaluate success after 1 year, 5 years, and 20 years—what do you recommend?\n"
|
| 84 |
+
]
|
| 85 |
+
}
|
| 86 |
+
],
|
| 87 |
+
"source": [
|
| 88 |
+
"openai = OpenAI()\n",
|
| 89 |
+
"\n",
|
| 90 |
+
"response = openai.chat.completions.create(\n",
|
| 91 |
+
" model = 'gpt-5-mini',\n",
|
| 92 |
+
" messages = message\n",
|
| 93 |
+
")\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"question = response.choices[0].message.content\n",
|
| 96 |
+
"\n",
|
| 97 |
+
"print(question)"
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"cell_type": "code",
|
| 102 |
+
"execution_count": 10,
|
| 103 |
+
"id": "fe8ae728",
|
| 104 |
+
"metadata": {},
|
| 105 |
+
"outputs": [],
|
| 106 |
+
"source": [
|
| 107 |
+
"competitors = []\n",
|
| 108 |
+
"answers = []\n",
|
| 109 |
+
"messages = [{\"role\": \"user\" , \"content\": question}]"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"cell_type": "code",
|
| 114 |
+
"execution_count": 11,
|
| 115 |
+
"id": "dc5c2815",
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [
|
| 118 |
+
{
|
| 119 |
+
"data": {
|
| 120 |
+
"text/markdown": [
|
| 121 |
+
"Executive summary — recommended policy (short)\n",
|
| 122 |
+
"- Adopt the hybrid staged policy: Immediately implement strict non‑pharmaceutical controls (strong quarantine/isolation, masking, case finding), emergency water conservation (target a 40% cut now), full refugee reception with prioritized basic services, and a time‑bound research & monitoring program over 3 months to reduce key uncertainties. After 3 months use pre‑defined, quantitative decision triggers to either (A) proceed with a controlled, full gene‑drive release or (B) continue without release and scale other vector control measures. This balances immediate life‑saving, longer‑term sustainability, and fairness to refugees while reducing the largest uncertainties before a highly consequential ecological decision.\n",
|
| 123 |
+
"\n",
|
| 124 |
+
"Why I prefer the hybrid staged policy\n",
|
| 125 |
+
"- Immediate, strict measures reduce the imminent death toll quickly (addresses the utilitarian council).\n",
|
| 126 |
+
"- Delaying irreversible ecological action for 3 months gives time for targeted experiments and monitoring to substantially reduce the probability of an unexpected ecological cascade (addresses preservationists).\n",
|
| 127 |
+
"- The plan prioritizes refugee protection (water, shelter, health services) and fairness in burden sharing (addresses refugee advocates).\n",
|
| 128 |
+
"- It keeps the fast life‑saving option (gene drive) on the table if monitoring shows acceptable ecological risk and the epidemic remains severe; it avoids locking the community into either extreme (immediate irreversible release vs. permanent refusal).\n",
|
| 129 |
+
"\n",
|
| 130 |
+
"Key assumptions and critical uncertainties\n",
|
| 131 |
+
"(These determine whether the plan will be correct.)\n",
|
| 132 |
+
"\n",
|
| 133 |
+
"Epidemic and vector role\n",
|
| 134 |
+
"- Assumption A1: Baseline additional deaths over 1 year without new interventions = 500 (200 in the next month, 300 thereafter). (Given by the problem; we use 300 as later-year burden.)\n",
|
| 135 |
+
"- A2 (Uncertain): Vector‑mediated transmission accounts for a large share of later transmission; base assumption = 80% (range 50–90%). If vector role is low, gene drive has little benefit.\n",
|
| 136 |
+
"- A3 (Uncertain): Non‑vector airborne or direct human transmission contributes to immediate month‑1 deaths; gene drive will not materially lower month‑1 deaths because spread reduction via mosquito suppression generally takes months.\n",
|
| 137 |
+
"\n",
|
| 138 |
+
"Gene drive performance and ecological risk\n",
|
| 139 |
+
"- A4: Probability of gene‑drive success (large vector suppression/elimination within 1 year) p_success = 0.70 (range 0.5–0.85).\n",
|
| 140 |
+
"- A5: If it succeeds, vector‑attributable transmission is reduced by 90% (range 70–95%).\n",
|
| 141 |
+
"- A6: Probability of an adverse ecological cascade caused by release p_cascade = 0.20 (range 0.10–0.30). If cascade occurs, expected long‑term crop yield loss mean 45% (range 20–70%).\n",
|
| 142 |
+
"- A7: Ecological cascade consequences are long‑term (years to decades) and not quickly reversible.\n",
|
| 143 |
+
"\n",
|
| 144 |
+
"Water/aquifer\n",
|
| 145 |
+
"- A8: Current consumption profile requires a 60% reduction in aggregate consumption to keep aquifer reliable ≥10 years.\n",
|
| 146 |
+
"- A9 (Uncertain): Actual aquifer recharge, how much refugees raise consumption pressure, and the elasticity of consumption to rationing (how much people can cut without catastrophic welfare effects).\n",
|
| 147 |
+
"\n",
|
| 148 |
+
"Ethical/political/operational\n",
|
| 149 |
+
"- A10: Community consent and compliance matter: inability to secure consent will reduce operational effectiveness of quarantine and any release.\n",
|
| 150 |
+
"\n",
|
| 151 |
+
"Simple quantitative model — comparison of three policies\n",
|
| 152 |
+
"- Time horizon for deaths: 1 year. Separate “month‑1” (urgent) and “later in year” components.\n",
|
| 153 |
+
"- Baseline parameters used (explicit):\n",
|
| 154 |
+
" - Population: locals 2,000 + refugees 500 = 2,500 (used mainly for water).\n",
|
| 155 |
+
" - Baseline year deaths without intervention: 200 in month‑1 + 300 later = 500.\n",
|
| 156 |
+
" - Vector share of later deaths: 80% ⇒ 240 vector‑attributable later deaths; 60 non‑vector later deaths.\n",
|
| 157 |
+
" - Strict quarantine reduces month‑1 deaths by 70% and later deaths by 50%.\n",
|
| 158 |
+
" - Moderate quarantine reduces month‑1 deaths by 30% and later deaths by 30%.\n",
|
| 159 |
+
" - Gene drive: p_success = 0.7; on success, reduces vector‑attributable deaths by 90%; on failure, no reduction.\n",
|
| 160 |
+
" - Gene‑drive cascade p_cascade = 0.2, crop yield loss if cascade = 45% (applies long term).\n",
|
| 161 |
+
" - Conservation: 60% cut needed to save aquifer.\n",
|
| 162 |
+
"\n",
|
| 163 |
+
"We compare three policies: A (Immediate gene drive + moderate measures), B (Strict conservation + no gene drive), C (Hybrid staged: strict measures + 3‑month research then conditional release).\n",
|
| 164 |
+
"\n",
|
| 165 |
+
"Policy A — Immediate gene‑drive release + moderate quarantine + 30% water rationing\n",
|
| 166 |
+
"- Month‑1 deaths: 200 * (1 − 0.30) = 140.\n",
|
| 167 |
+
"- Later deaths:\n",
|
| 168 |
+
" - Vector portion (240) expected after gene drive = p_success*(0.10*240) + (1−p_success)*(1.0*240) = 0.7*24 + 0.3*240 = 16.8 + 72 = 88.8.\n",
|
| 169 |
+
" - Non‑vector later reduced by moderate quarantine: 60*(1−0.30) = 42.\n",
|
| 170 |
+
" - Later total = 88.8 + 42 = 130.8.\n",
|
| 171 |
+
"- Total expected deaths (1 year) ≈ 140 + 130.8 ≈ 271.\n",
|
| 172 |
+
"- Expected probability of ecological cascade = 0.20 with severe crop yield loss (if cascade occurs: long‑term crop loss ~45%, potentially reducing local food supply by ~18% = 0.4*0.45).\n",
|
| 173 |
+
"- Water: 30% rationing is insufficient to protect aquifer → aquifer failure risk in ≤10 years remains high.\n",
|
| 174 |
+
"- Tradeoffs: Lower than “no action” deaths later if the gene drive works, but immediate month‑1 deaths not fully prevented and there is a significant non‑zero risk of a long‑term catastrophic crop loss.\n",
|
| 175 |
+
"\n",
|
| 176 |
+
"Policy B — Strict water and disease control (60% conservation, strict quarantine), no gene drive\n",
|
| 177 |
+
"- Month‑1 deaths: 200 * (1 − 0.70) = 60.\n",
|
| 178 |
+
"- Later deaths: 300 * (1 − 0.50) = 150.\n",
|
| 179 |
+
"- Total expected deaths ≈ 60 + 150 = 210.\n",
|
| 180 |
+
"- Crop ecological risk from gene drive = 0.\n",
|
| 181 |
+
"- Aquifer: 60% cut → aquifer likely preserved for ≥10 years (assuming cuts are sustained); this secures long‑term water and reduces long‑term community collapse risk.\n",
|
| 182 |
+
"- Refugees: must be integrated under heavy rationing; humanitarian strains high but survivable if managed equitably and with international support.\n",
|
| 183 |
+
"- Tradeoffs: lowest deaths in first year among the three policies in this model, no gene‑drive ecological risk, but heavy immediate deprivation and political resistance due to austere water cuts and burdens on refugees.\n",
|
| 184 |
+
"\n",
|
| 185 |
+
"Policy C — Hybrid staged approach: immediate strict quarantine + 40% water conservation + 3 months research/monitoring → conditional release\n",
|
| 186 |
+
"- Month‑1 deaths under strict measures: 200*(1−0.70) = 60.\n",
|
| 187 |
+
"- Months 2–3: assume strict measures keep extra deaths relatively low; approximate next 2 months combined deaths = 40 (this is a simplifying assumption; can be adjusted to local epidemiology).\n",
|
| 188 |
+
"- After 3 months we decide to release or not. Let p_decide_release ≈ 0.60 (probability that monitoring supports release); if release, success p_success = 0.7.\n",
|
| 189 |
+
"- Modeling simplifying assumptions: under strict quarantine with no release total year deaths ≈ 210 (as in B). If release is made at month 3 and is successful, remaining later deaths reduce substantially.\n",
|
| 190 |
+
"- Numerical expectation (approximate):\n",
|
| 191 |
+
" - If no release (prob 0.4) → total deaths = 210.\n",
|
| 192 |
+
" - If release at month 3 (prob 0.6) → because half of controlled-later deaths already occurred, remaining later deaths shrink dramatically if successful. Using a conservative arithmetic (see full step calculations in appendix), expected total deaths in release branch ≈ 163.\n",
|
| 193 |
+
" - Weighted expected deaths ≈ 0.4*210 + 0.6*163 ≈ 182.\n",
|
| 194 |
+
"- Expected probability of cascade = p_decide_release * p_cascade = 0.6*0.2 = 0.12 (12%) and expected crop loss weighted ≈ 0.12*45% = 5.4% yield loss on average (expected); actual outcome is either near 0 or catastrophic.\n",
|
| 195 |
+
"- Water: 40% conservation is not enough to guarantee 10‑year aquifer security, but it buys time to deploy additional measures (drill supplementary wells, ramp up rainwater harvesting/desalination capacity).\n",
|
| 196 |
+
"- Tradeoffs: intermediate expected deaths, reduced probability of catastrophic ecological outcome (relative to immediate release), more time to arrange refugee water supply and to get better evidence.\n",
|
| 197 |
+
"\n",
|
| 198 |
+
"Comparative summary (expected deaths, 1‑year)\n",
|
| 199 |
+
"- Policy A: ~271 deaths (expected) in 1 year; ecological cascade risk 20%; aquifer risk remains.\n",
|
| 200 |
+
"- Policy B: ~210 deaths; ecological cascade risk 0%; aquifer preserved if cuts sustained.\n",
|
| 201 |
+
"- Policy C: ~182 deaths; ecological cascade risk ~12% (conditional); aquifer likely still at risk unless further conservation measures added.\n",
|
| 202 |
+
"\n",
|
| 203 |
+
"Sensitivity notes\n",
|
| 204 |
+
"- If vector share of transmission is lower (e.g., 50%), gene drive benefits shrink and A/C become less attractive.\n",
|
| 205 |
+
"- If p_success higher than 0.7, the case for immediate release strengthens.\n",
|
| 206 |
+
"- If aquifer recharge is higher and aquifer less sensitive, strict 60% conservation may be eased.\n",
|
| 207 |
+
"- The model deliberately simplifies temporal dynamics and ignores indirect economic effects; it’s a decision‑aid, not a final epidemiological projection.\n",
|
| 208 |
+
"\n",
|
| 209 |
+
"Adaptive decision rule and trigger points\n",
|
| 210 |
+
"(Pre‑declare these to reduce political conflict and to make decisions transparent.)\n",
|
| 211 |
+
"\n",
|
| 212 |
+
"Phase 0 (immediate, day 0–90)\n",
|
| 213 |
+
"- Actions: strict quarantine/isolation + aggressive case finding and treatment, mask use, closure of high‑risk venues; 40% water cuts applied immediately; refugee intake with guaranteed minimum essentials; start monitoring & experiments (below).\n",
|
| 214 |
+
"- Triggers to consider unconditional, immediate gene‑drive release (override staged plan):\n",
|
| 215 |
+
" - If projected additional deaths over next 30 days (from current incidence) exceed 150 and R_t > 1.3 despite strict measures; OR\n",
|
| 216 |
+
" - If healthcare capacity is overwhelmed (hospital beds occupied >90% for >3 days).\n",
|
| 217 |
+
"- Triggers that prohibit release:\n",
|
| 218 |
+
" - If caged/containment trials show gene drive spreads to non‑target species, or if ecological baseline monitoring shows fragility that would likely lead to >20% decline in a key pollinator or predator species in 3 months.\n",
|
| 219 |
+
" - If community (representative council + external scientific oversight) does not give majority consent after transparent review.\n",
|
| 220 |
+
"\n",
|
| 221 |
+
"Phase 1 decision (at 90 days)\n",
|
| 222 |
+
"- Evaluate monitoring metrics (see experiments) against pre‑set thresholds.\n",
|
| 223 |
+
"- If:\n",
|
| 224 |
+
" - Lab/caged tests show expected gene‑drive inheritance performance and no evidence of non‑target gene transfer, AND\n",
|
| 225 |
+
" - Field ecological monitoring in contained sentinel sites (exclosures or islands) shows no strong early signals of non‑target impacts, AND\n",
|
| 226 |
+
" - Epidemic burden still projects >100 additional deaths without vector suppression,\n",
|
| 227 |
+
" → then proceed to controlled release.\n",
|
| 228 |
+
"- Else: do not release; scale intensified non‑gene vector control (insecticide programs, habitat modification), maintain strict quarantine, or consider alternative interventions (importation of medical aid, vaccines if available).\n",
|
| 229 |
+
"\n",
|
| 230 |
+
"Post‑release triggers\n",
|
| 231 |
+
"- If, within 6 months after release, non‑target insect abundance declines >30% relative to baseline in >2 ecological zones AND crop yields for key staples decline >20% relative to matched controls, invoke contingency mitigation (stop further releases if phased, initiate ecological restoration plans, seek external assistance).\n",
|
| 232 |
+
"\n",
|
| 233 |
+
"Minimum experiments, monitoring metrics, and sample sizes (3–12 months)\n",
|
| 234 |
+
"Goal: reduce the largest uncertainties in 3 months (epidemiology and gene drive behavior) and 6–12 months (ecological cascades, crop impacts, groundwater trends).\n",
|
| 235 |
+
"\n",
|
| 236 |
+
"1) Epidemiological surveillance (immediate, months 0–3)\n",
|
| 237 |
+
"- Metrics: daily case counts, test positivity, hospitalizations, R_t estimate.\n",
|
| 238 |
+
"- Actions and sample sizes:\n",
|
| 239 |
+
" - Test every hospital admission with respiratory symptoms; actively trace and test contacts.\n",
|
| 240 |
+
" - Community serosurvey: random sample of 300 people at month 0 and repeat at month 3. With N=300, you can estimate seroprevalence with ±5–6% margin (95% CI), sufficient to detect epidemic trend.\n",
|
| 241 |
+
" - Sentinel household cohort (n=200) with weekly symptom check and PCR testing to estimate incidence and household secondary attack rate.\n",
|
| 242 |
+
"- Why: determines current trajectory and vector vs non‑vector importance (see next).\n",
|
| 243 |
+
"\n",
|
| 244 |
+
"2) Vector role & entomological studies (0–3 months)\n",
|
| 245 |
+
"- Metrics: mosquito infection prevalence, biting rates, species composition, lab competence.\n",
|
| 246 |
+
"- Actions:\n",
|
| 247 |
+
" - Set 30 traps across representative habitats (village, agricultural, wetlands), weekly counts for 12 weeks. Power: with Poisson trap counts, 30 traps weekly for 12 weeks gives capacity to detect ~30–40% change with 80% power.\n",
|
| 248 |
+
" - Test a sample of 600 mosquitoes (across species) for pathogen presence to estimate vector infection prevalence to ±2% (95% CI if prevalence ~5%).\n",
|
| 249 |
+
" - Laboratory vector competence tests (n≥50–100 mosquitoes per species) to measure ability to acquire/transmit pathogen.\n",
|
| 250 |
+
"- Why: clarifies vector contribution (A2) and informs how much gene drive could affect transmission.\n",
|
| 251 |
+
"\n",
|
| 252 |
+
"3) Gene‑drive contained trials and modeling (0–3 months)\n",
|
| 253 |
+
"- Metrics: inheritance bias, fitness cost, off‑target effects in target species under contained conditions.\n",
|
| 254 |
+
"- Actions:\n",
|
| 255 |
+
" - Insectary/caged trials: 10 replicate cages, each starting with 100 breeding pairs, monitor allele frequency over 6 generations. This detects drive dynamics and fitness cost.\n",
|
| 256 |
+
" - Molecular testing for off‑target cleavage and horizontal gene transfer (PCR and targeted sequencing of non‑target insect DNA) in lab trials.\n",
|
| 257 |
+
"- Why: reduces uncertainty on p_success and off‑target mutation risk.\n",
|
| 258 |
+
"\n",
|
| 259 |
+
"4) Ecological sentinel monitoring (0–6 months)\n",
|
| 260 |
+
"- Metrics: abundance and diversity of pollinators and other non‑target arthropods; crop pollination metrics.\n",
|
| 261 |
+
"- Actions:\n",
|
| 262 |
+
" - Baseline surveys: 10 transects, with 10 traps each (light & malaise traps), weekly for 3 months pre‑release to establish variability.\n",
|
| 263 |
+
" - Crop pollination/exclosure experiments: 20 paired plots (control vs pollinator exclusion) across main crops to measure sensitivity of yields to loss of particular insects; detect ~20% yield change with power ~0.8.\n",
|
| 264 |
+
"- Why: detects early signals of cascade that predict crop impacts.\n",
|
| 265 |
+
"\n",
|
| 266 |
+
"5) Groundwater and water use monitoring (immediate, continuous)\n",
|
| 267 |
+
"- Metrics: daily groundwater levels, pumping volumes, per‑capita water consumption.\n",
|
| 268 |
+
"- Actions:\n",
|
| 269 |
+
" - Install 5 monitoring wells with loggers; measure monthly aquifer level trends.\n",
|
| 270 |
+
" - Implement household water meters in a sample of 200 households to measure compliance and elasticity.\n",
|
| 271 |
+
"- Why: decides if further aggressive conservation is needed to save aquifer.\n",
|
| 272 |
+
"\n",
|
| 273 |
+
"Adaptive sample sizes and contingency\n",
|
| 274 |
+
"- If early results show vector role <50% or lab trials suggest high off‑target risk, abort release pathway.\n",
|
| 275 |
+
"- If evidence is ambiguous at 3 months, extend monitoring for an additional 3 months before deciding (unless the epidemic is worsening rapidly).\n",
|
| 276 |
+
"\n",
|
| 277 |
+
"Stakeholder reactions and negotiation/communication strategies\n",
|
| 278 |
+
"1) Utilitarian emergency council (minimize current deaths)\n",
|
| 279 |
+
"- Likely reaction: push for immediate gene‑drive release and minimal rationing that slows the epidemic fastest.\n",
|
| 280 |
+
"- Strategy to secure cooperation:\n",
|
| 281 |
+
" - Present modeled expected deaths under each option and show staged plan’s projected lower deaths than immediate non‑action.\n",
|
| 282 |
+
" - Emphasize immediate strict quarantine and surge medical resources as top priority (they get immediate mortality reduction).\n",
|
| 283 |
+
" - Offer quantitative triggers that will permit immediate release if the epidemic accelerates (addresses their urgency).\n",
|
| 284 |
+
"\n",
|
| 285 |
+
"2) Preservationist council (ecosystem/long‑term sustainability)\n",
|
| 286 |
+
"- Likely reaction: oppose immediate release, favor strict conservation and non‑irreversible measures.\n",
|
| 287 |
+
"- Strategy:\n",
|
| 288 |
+
" - Commit to rigorous contained trials, transparent data sharing, independent external ecological review.\n",
|
| 289 |
+
" - Set high thresholds for release (as above) and give preservationists formal veto/oversight role on ecological criteria and post‑release monitoring.\n",
|
| 290 |
+
" - Offer stronger investments in water and habitat conservation measures under any plan.\n",
|
| 291 |
+
"\n",
|
| 292 |
+
"3) Refugee advocacy group\n",
|
| 293 |
+
"- Likely reaction: demand unimpeded access to shelter, water, medical care; oppose policies that disproportionately harm refugees.\n",
|
| 294 |
+
"- Strategy:\n",
|
| 295 |
+
" - Guarantee minimum water, shelter, medical access for refugees, funded by reallocation or external aid; do not use refugees as an excuse to refuse aid.\n",
|
| 296 |
+
" - Ensure rationing rules are applied equitably; prioritize vulnerable groups (children, pregnant women).\n",
|
| 297 |
+
" - Involve refugee representatives in planning and monitoring of service delivery.\n",
|
| 298 |
+
"\n",
|
| 299 |
+
"Cross‑group negotiation tactics\n",
|
| 300 |
+
"- Form a small, representative Joint Emergency Board with delegates from each group plus independent science advisors and an external ethics observer (NGO or university). Require transparency and publish all monitoring data weekly.\n",
|
| 301 |
+
"- Use binding, pre‑declared decision thresholds so decisions are not ad‑hoc and trust is built by following agreed rules.\n",
|
| 302 |
+
"- Provide clear compensation and support measures for those who bear disproportionate burdens (e.g., temporary food aid to farmers if water rationing reduces yields; subsidies for households).\n",
|
| 303 |
+
"- Offer a 30‑day community review after the 3‑month monitoring window where concerns are heard and addressed before any release.\n",
|
| 304 |
+
"\n",
|
| 305 |
+
"Operational checklist for immediate 0–30 days (practical steps)\n",
|
| 306 |
+
"- Convene Joint Emergency Board and publish plan + thresholds.\n",
|
| 307 |
+
"- Implement strict quarantine/isolation, mask use, case finding, and hospital surge capacity.\n",
|
| 308 |
+
"- Start 40% water conservation immediately with prioritized allocations (drinking, medical, minimal sanitation).\n",
|
| 309 |
+
"- Set up refugee reception centers with guaranteed basic services; request external humanitarian assistance.\n",
|
| 310 |
+
"- Launch monitoring experiments (entomology, epidemiology, insectary trials, groundwater logging).\n",
|
| 311 |
+
"- Arrange for external scientific oversight and rapid data analysis capability.\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"How to evaluate success — metrics at 1 year, 5 years, and 20 years\n",
|
| 314 |
+
"\n",
|
| 315 |
+
"1 year (short term)\n",
|
| 316 |
+
"- Epidemiology: Total additional deaths from pathogen ≤ target (compare to modeled expectations). Specific target: fewer than 220 additional deaths would be strong evidence the staged approach worked better than immediate release scenario.\n",
|
| 317 |
+
"- Epidemic trajectory: R_t maintained <1.0 for >60 days.\n",
|
| 318 |
+
"- Refugee well‑being: ≥95% of refugees have shelter, safe drinking water, and primary health access within 2 weeks of arrival.\n",
|
| 319 |
+
"- Monitoring completion: Completed planned 3‑month trials and published results; decision made according to pre‑declared triggers.\n",
|
| 320 |
+
"- Community consent: documented minutes of Joint Emergency Board, public dashboards, and recorded outreach.\n",
|
| 321 |
+
"\n",
|
| 322 |
+
"5 years (medium term)\n",
|
| 323 |
+
"- Aquifer: groundwater levels and pumpable yield comparable to pre‑crisis projections if 60% sustained conservation achieved; if conservation not fully achieved, at least evidence mitigation (e.g., supplemental wells, desalination) reduces projected failure.\n",
|
| 324 |
+
"- Food security & economy: crop yields within 10% of baseline if gene drive was not released; if gene drive was released, no crop yield reduction >20% attributable to the release; economic loss limited and recovery plan implemented.\n",
|
| 325 |
+
"- Biodiversity: key indicator species (pollinators, predators) not reduced by >30% from baseline (unless robust compensatory recovery is demonstrated).\n",
|
| 326 |
+
"- Social cohesion: refugee integration indicators (employment, schooling) improving; no major civil unrest linked to these policies.\n",
|
| 327 |
+
"\n",
|
| 328 |
+
"20 years (long term)\n",
|
| 329 |
+
"- Public health: no recurring epidemics attributable to the pathogen at levels similar to the original outbreak; pathogen controlled sustainably.\n",
|
| 330 |
+
"- Water security: aquifer reliable OR a sustainable alternative water system implemented (desalination, major rainwater harvesting) and per‑capita water use on a sustainable footing.\n",
|
| 331 |
+
"- Ecosystem & agriculture: crops and ecosystem services recovered or adaptively managed; any long‑term impacts from gene drive are documented, mitigated, and socially accepted or compensated.\n",
|
| 332 |
+
"- Intergenerational equity: community living standards, food security, and biodiverse environment preserved for future generations.\n",
|
| 333 |
+
"\n",
|
| 334 |
+
"Final recommendation (concise)\n",
|
| 335 |
+
"- Implement the staged hybrid policy now: strict immediate public‑health measures, a 40% emergency water cut, humane refugee reception, and an urgent 3‑month monitoring/contained trials program with independent oversight. Use pre‑declared quantitative triggers at 3 months to decide whether to proceed to gene‑drive release. Prepare and budget mitigation contingencies (agriculture supports, ecological restoration funds, and alternative water infrastructure). This approach maximizes immediate life‑saving, reduces long‑term catastrophic choices, preserves options, and protects refugees’ rights in a fair, transparent, and adaptive manner.\n",
|
| 336 |
+
"\n",
|
| 337 |
+
"If you want, I will:\n",
|
| 338 |
+
"- Produce a single‑page decision chart for the Joint Emergency Board (triggers, who decides, data required).\n",
|
| 339 |
+
"- Produce a detailed monitoring protocol and power calculations for each experiment (trap counts, serosurvey size, cage trial designs).\n",
|
| 340 |
+
"- Draft a public communication script and FAQ for each stakeholder group to support consent and compliance. Which would you like first?"
|
| 341 |
+
],
|
| 342 |
+
"text/plain": [
|
| 343 |
+
"<IPython.core.display.Markdown object>"
|
| 344 |
+
]
|
| 345 |
+
},
|
| 346 |
+
"metadata": {},
|
| 347 |
+
"output_type": "display_data"
|
| 348 |
+
}
|
| 349 |
+
],
|
| 350 |
+
"source": [
|
| 351 |
+
"model_name = 'gpt-5-mini'\n",
|
| 352 |
+
"\n",
|
| 353 |
+
"response = openai.chat.completions.create( model = model_name, messages = messages)\n",
|
| 354 |
+
"\n",
|
| 355 |
+
"answer = response.choices[0].message.content\n",
|
| 356 |
+
"\n",
|
| 357 |
+
"display(Markdown(answer))\n",
|
| 358 |
+
"competitors.append(model_name);\n",
|
| 359 |
+
"answers.append(answer)"
|
| 360 |
+
]
|
| 361 |
+
},
|
| 362 |
+
{
|
| 363 |
+
"cell_type": "code",
|
| 364 |
+
"execution_count": null,
|
| 365 |
+
"id": "3900351d",
|
| 366 |
+
"metadata": {},
|
| 367 |
+
"outputs": [],
|
| 368 |
+
"source": []
|
| 369 |
+
}
|
| 370 |
+
],
|
| 371 |
+
"metadata": {
|
| 372 |
+
"kernelspec": {
|
| 373 |
+
"display_name": ".venv",
|
| 374 |
+
"language": "python",
|
| 375 |
+
"name": "python3"
|
| 376 |
+
},
|
| 377 |
+
"language_info": {
|
| 378 |
+
"codemirror_mode": {
|
| 379 |
+
"name": "ipython",
|
| 380 |
+
"version": 3
|
| 381 |
+
},
|
| 382 |
+
"file_extension": ".py",
|
| 383 |
+
"mimetype": "text/x-python",
|
| 384 |
+
"name": "python",
|
| 385 |
+
"nbconvert_exporter": "python",
|
| 386 |
+
"pygments_lexer": "ipython3",
|
| 387 |
+
"version": "3.12.2"
|
| 388 |
+
}
|
| 389 |
+
},
|
| 390 |
+
"nbformat": 4,
|
| 391 |
+
"nbformat_minor": 5
|
| 392 |
+
}
|
day4.ipynb
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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from openai import OpenAI\n",
|
| 12 |
+
"from pypdf import PdfReader\n",
|
| 13 |
+
"import gradio as gr "
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"cell_type": "code",
|
| 18 |
+
"execution_count": 2,
|
| 19 |
+
"id": "2957495d",
|
| 20 |
+
"metadata": {},
|
| 21 |
+
"outputs": [],
|
| 22 |
+
"source": [
|
| 23 |
+
"load_dotenv(override=True)\n",
|
| 24 |
+
"openai = OpenAI()"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": 10,
|
| 30 |
+
"id": "aaaaa414",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [
|
| 33 |
+
{
|
| 34 |
+
"name": "stderr",
|
| 35 |
+
"output_type": "stream",
|
| 36 |
+
"text": [
|
| 37 |
+
"Ignoring wrong pointing object 10 0 (offset 0)\n",
|
| 38 |
+
"Ignoring wrong pointing object 244 0 (offset 0)\n"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "stdout",
|
| 43 |
+
"output_type": "stream",
|
| 44 |
+
"text": [
|
| 45 |
+
"25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
|
| 46 |
+
"Page 1 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
|
| 47 |
+
"1,248 followers ·500+ connections\n",
|
| 48 |
+
"Addprofilesection\n",
|
| 49 |
+
" Enhance profile\n",
|
| 50 |
+
" He/Him\n",
|
| 51 |
+
"Software Engineer @ Ciena\n",
|
| 52 |
+
"Pune, Maharashtra, India · Contact info\n",
|
| 53 |
+
"Pragyansh Dwivedi \n",
|
| 54 |
+
"Ciena\n",
|
| 55 |
+
"Opento\n",
|
| 56 |
+
" Resources\n",
|
| 57 |
+
"Suggested for you Private to you\n",
|
| 58 |
+
"Analytics Private to you\n",
|
| 59 |
+
"19 profile viewsDiscover who's viewed your profile.\n",
|
| 60 |
+
"0 post impressionsStart a post to increase engagement.Past 7 days\n",
|
| 61 |
+
"5 search appearancesSee how often you appear in search results.\n",
|
| 62 |
+
"Show all analytics\n",
|
| 63 |
+
"About\n",
|
| 64 |
+
"Experience MERN/ MEAN Stack Development and good knowledge of webstandards and scalable application architecture.Experience with agile projectmanagement principles.\n",
|
| 65 |
+
"Activity1,248 followers\n",
|
| 66 |
+
"Create a post\n",
|
| 67 |
+
"HomeMy NetworkJobs MessagingNotificationsMe\n",
|
| 68 |
+
" For Business\n",
|
| 69 |
+
"1225/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
|
| 70 |
+
"Page 2 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
|
| 71 |
+
"Pragyansh Dwivedi commented on a post • 2mo • \n",
|
| 72 |
+
"Pragyansh Dwivedi commented on a post • 6mo\n",
|
| 73 |
+
"Pragyansh Dwivedi commented on a post • 8mo\n",
|
| 74 |
+
"Show all comments\n",
|
| 75 |
+
"#cfbr\n",
|
| 76 |
+
"Congrats Abhishek! \n",
|
| 77 |
+
"Congrats Shivam Sir! \n",
|
| 78 |
+
"Experience\n",
|
| 79 |
+
"Software EngineerCiena · Full-timeJul 2022 - Present · 3 yrs 4 mosPune, Maharashtra, India\n",
|
| 80 |
+
"Angular, React.js and +7 skills\n",
|
| 81 |
+
"Oodles TechnologiesFull-time · 2 yrs 6 mosGurugram, Haryana, India\n",
|
| 82 |
+
"Associate Consultant Frontend Development Jan 2020 - Dec 2020 · 1 yr\n",
|
| 83 |
+
"Angular, Ionic Framework and +4 skills\n",
|
| 84 |
+
"Lead Frontend DevelopmentJan 2022 - Jun 2022 · 6 mos\n",
|
| 85 |
+
"Angular, React.js and +8 skills\n",
|
| 86 |
+
"Sr. Associate Consultant Frontend DevelopmentJan 2021 - Dec 2021 · 1 yr\n",
|
| 87 |
+
"Angular, React.js and +4 skills\n",
|
| 88 |
+
"Expertise over Angular and Ionic development\n",
|
| 89 |
+
"Skills\n",
|
| 90 |
+
"Show all 41 skills\n",
|
| 91 |
+
"Redux\n",
|
| 92 |
+
"2 experiences across Ciena and 1 other company\n",
|
| 93 |
+
"Preact\n",
|
| 94 |
+
"Lead Frontend Development at Oodles Technologies\n",
|
| 95 |
+
"Recommendations\n",
|
| 96 |
+
"Show all pending\n",
|
| 97 |
+
"Given\n",
|
| 98 |
+
"Deepika Wadhera· 1stExecutive Consultant at Slidebuy\n",
|
| 99 |
+
"25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
|
| 100 |
+
"Page 3 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
|
| 101 |
+
"Executive Consultant at SlidebuyJuly 23, 2020, Deepika was senior to Pragyansh but didn'tmanage Pragyansh directly\n",
|
| 102 |
+
"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",
|
| 103 |
+
"Deepika is a person with a strong motivation and aims for excellence allthe time. She is creative, energetic, solution oriented and highly…\n",
|
| 104 |
+
"Interests\n",
|
| 105 |
+
"Show all Top Voices\n",
|
| 106 |
+
"Top VoicesCompaniesGroupsNewslettersSchools\n",
|
| 107 |
+
"Satya Nadella· 3rdChairman and CEO at Microsoft11,668,387 followers\n",
|
| 108 |
+
"Following\n",
|
| 109 |
+
"Ritesh Agarwal· 2ndPRISM Founder & Group CEO | Revolutionizing Hospitality Industry1,339,143 followers\n",
|
| 110 |
+
"Following\n",
|
| 111 |
+
"Profile languageEnglish\n",
|
| 112 |
+
"Public profile & URLwww.linkedin.com/in/pragyansh-dwivedi-1a9b55150\n",
|
| 113 |
+
"Pragyansh, unlock your full potential withLinkedIn Premium\n",
|
| 114 |
+
"See who’s viewed your profile in the last365 days\n",
|
| 115 |
+
"Try for free\n",
|
| 116 |
+
"Ad\n",
|
| 117 |
+
"Who your viewers also viewed Private to you\n",
|
| 118 |
+
"Someone at jobs for students\n",
|
| 119 |
+
"View\n",
|
| 120 |
+
"Software Developer at Ciena\n",
|
| 121 |
+
"View\n",
|
| 122 |
+
"Software Developer in the IT Services…\n",
|
| 123 |
+
"View25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
|
| 124 |
+
"Page 4 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
|
| 125 |
+
"Software Developer at Infosys\n",
|
| 126 |
+
"View\n",
|
| 127 |
+
"People you may knowFrom your company\n",
|
| 128 |
+
"Show all\n",
|
| 129 |
+
"Pushpinder Singh\n",
|
| 130 |
+
"Connect\n",
|
| 131 |
+
"Engineer Software Application \n",
|
| 132 |
+
"Manish Rajput\n",
|
| 133 |
+
"Connect\n",
|
| 134 |
+
"AWS Devops Engineer, Terraform, Ansible, Docker, Kubernetes, Helm,Python, Shell scripting…\n",
|
| 135 |
+
"Ayush Saxena\n",
|
| 136 |
+
"Connect\n",
|
| 137 |
+
"Software Engineer @Ciena | IIT Jodhpur | BTech-CSE\n",
|
| 138 |
+
"Abhishek Rana\n",
|
| 139 |
+
"Connect\n",
|
| 140 |
+
"Product Verification Engineer R&D at Ciena || Ex-Ericsson || Ex- Huawei\n",
|
| 141 |
+
"Mayank Kandari\n",
|
| 142 |
+
"Connect\n",
|
| 143 |
+
"Sr Software Engineer at Ciena\n",
|
| 144 |
+
"You might likePages for you\n",
|
| 145 |
+
"Show all\n",
|
| 146 |
+
"Anthropic\n",
|
| 147 |
+
"1,587,232 followers\n",
|
| 148 |
+
"18 connections follow this page\n",
|
| 149 |
+
"Follow\n",
|
| 150 |
+
"Research Services\n",
|
| 151 |
+
"Tata Group\n",
|
| 152 |
+
"5,407,667 followers\n",
|
| 153 |
+
"31 connections work here\n",
|
| 154 |
+
"Follow\n",
|
| 155 |
+
"Executive Offices\n",
|
| 156 |
+
"Promoted\n",
|
| 157 |
+
"Fast Track AI DevAccelerate AI app dev & deployment.Start Free!\n",
|
| 158 |
+
"Hafiz & 118 other connectionsalso follow Google Cloud\n",
|
| 159 |
+
"Passwordless Myth Busting25/10/25, 9:58 PM(12) Pragyansh Dwivedi | LinkedIn\n",
|
| 160 |
+
"Page 5 of 5https://www.linkedin.com/in/pragyansh-dwivedi-1a9b55150/\n",
|
| 161 |
+
"About Accessibility Talent Solutions\n",
|
| 162 |
+
"Professional CommunityPolicies Careers Marketing Solutions\n",
|
| 163 |
+
"Ad Choices Advertising\n",
|
| 164 |
+
"Sales Solutions Mobile Small Business\n",
|
| 165 |
+
"Safety Center\n",
|
| 166 |
+
"Questions?Visit our Help Center.\n",
|
| 167 |
+
"Manage your account and privacyGo to your Settings.\n",
|
| 168 |
+
"Recommendation transparencyLearn more about Recommended Content.\n",
|
| 169 |
+
"Select Language\n",
|
| 170 |
+
"LinkedIn Corporation © 2025\n",
|
| 171 |
+
"Passwordless Myth BustingTruth behind common misconceptions& why it is a win-win businesssolution.\n",
|
| 172 |
+
"Vipasha also follows DuoSecurity\n",
|
| 173 |
+
"Privacy & Terms \n",
|
| 174 |
+
"English (English)\n"
|
| 175 |
+
]
|
| 176 |
+
}
|
| 177 |
+
],
|
| 178 |
+
"source": [
|
| 179 |
+
"reader = PdfReader(\"../me/linkedin.pdf\")\n",
|
| 180 |
+
"linkedin = ''\n",
|
| 181 |
+
"for page in reader.pages:\n",
|
| 182 |
+
" text = page.extract_text()\n",
|
| 183 |
+
" if text:\n",
|
| 184 |
+
" linkedin += text\n",
|
| 185 |
+
"\n",
|
| 186 |
+
"print(linkedin)"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"cell_type": "code",
|
| 191 |
+
"execution_count": 11,
|
| 192 |
+
"id": "412b0e49",
|
| 193 |
+
"metadata": {},
|
| 194 |
+
"outputs": [],
|
| 195 |
+
"source": [
|
| 196 |
+
"with open(\"../me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
|
| 197 |
+
" summary = f.read()\n",
|
| 198 |
+
"\n",
|
| 199 |
+
"name = \"Pragyansh Dwivedi\""
|
| 200 |
+
]
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"cell_type": "code",
|
| 204 |
+
"execution_count": 23,
|
| 205 |
+
"id": "ef676942",
|
| 206 |
+
"metadata": {},
|
| 207 |
+
"outputs": [],
|
| 208 |
+
"source": [
|
| 209 |
+
"gpt4MiniModel = \"gpt-4o-mini\"\n",
|
| 210 |
+
"gpt4oLatestModel = \"chatgpt-4o-latest\""
|
| 211 |
+
]
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"cell_type": "code",
|
| 215 |
+
"execution_count": 12,
|
| 216 |
+
"id": "01a04973",
|
| 217 |
+
"metadata": {},
|
| 218 |
+
"outputs": [],
|
| 219 |
+
"source": [
|
| 220 |
+
"system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
|
| 221 |
+
" particularly questions related to {name}'s career, background, skills and experiences. \\\n",
|
| 222 |
+
" Your responsibility is to represent {name} for interaction on the website as faithfully as possible.\\\n",
|
| 223 |
+
" You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \\\n",
|
| 224 |
+
" Be professional and engagin, as if talkin to a potential client or future employer who came across the website. \\\n",
|
| 225 |
+
" If you don't know the answer, say so.\"\n",
|
| 226 |
+
"\n",
|
| 227 |
+
"system_prompt += f\"\\n\\n## Summary:\\n{summary} LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
|
| 228 |
+
"system_prompt += f\"With this context, please chat with the user, always staying in charactre as {name}.\""
|
| 229 |
+
]
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"cell_type": "code",
|
| 233 |
+
"execution_count": 8,
|
| 234 |
+
"id": "51d4dd3e",
|
| 235 |
+
"metadata": {},
|
| 236 |
+
"outputs": [
|
| 237 |
+
{
|
| 238 |
+
"data": {
|
| 239 |
+
"text/plain": [
|
| 240 |
+
"\"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.\""
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
"execution_count": 8,
|
| 244 |
+
"metadata": {},
|
| 245 |
+
"output_type": "execute_result"
|
| 246 |
+
}
|
| 247 |
+
],
|
| 248 |
+
"source": [
|
| 249 |
+
"system_prompt"
|
| 250 |
+
]
|
| 251 |
+
},
|
| 252 |
+
{
|
| 253 |
+
"cell_type": "code",
|
| 254 |
+
"execution_count": null,
|
| 255 |
+
"id": "dfb08280",
|
| 256 |
+
"metadata": {},
|
| 257 |
+
"outputs": [],
|
| 258 |
+
"source": [
|
| 259 |
+
"def chat(message, history):\n",
|
| 260 |
+
" messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
|
| 261 |
+
" response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
|
| 262 |
+
" return response.choices[0].message.content"
|
| 263 |
+
]
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"cell_type": "code",
|
| 267 |
+
"execution_count": 17,
|
| 268 |
+
"id": "9bf66765",
|
| 269 |
+
"metadata": {},
|
| 270 |
+
"outputs": [
|
| 271 |
+
{
|
| 272 |
+
"name": "stdout",
|
| 273 |
+
"output_type": "stream",
|
| 274 |
+
"text": [
|
| 275 |
+
"* Running on local URL: http://127.0.0.1:7862\n",
|
| 276 |
+
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 277 |
+
]
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
"data": {
|
| 281 |
+
"text/html": [
|
| 282 |
+
"<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>"
|
| 283 |
+
],
|
| 284 |
+
"text/plain": [
|
| 285 |
+
"<IPython.core.display.HTML object>"
|
| 286 |
+
]
|
| 287 |
+
},
|
| 288 |
+
"metadata": {},
|
| 289 |
+
"output_type": "display_data"
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"data": {
|
| 293 |
+
"text/plain": []
|
| 294 |
+
},
|
| 295 |
+
"execution_count": 17,
|
| 296 |
+
"metadata": {},
|
| 297 |
+
"output_type": "execute_result"
|
| 298 |
+
}
|
| 299 |
+
],
|
| 300 |
+
"source": [
|
| 301 |
+
"gr.ChatInterface(chat,type=\"messages\").launch()"
|
| 302 |
+
]
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"cell_type": "code",
|
| 306 |
+
"execution_count": 18,
|
| 307 |
+
"id": "d84f62d0",
|
| 308 |
+
"metadata": {},
|
| 309 |
+
"outputs": [],
|
| 310 |
+
"source": [
|
| 311 |
+
"from pydantic import BaseModel\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"class Evaluation(BaseModel):\n",
|
| 314 |
+
" is_acceptable: bool\n",
|
| 315 |
+
" feedback: str"
|
| 316 |
+
]
|
| 317 |
+
},
|
| 318 |
+
{
|
| 319 |
+
"cell_type": "code",
|
| 320 |
+
"execution_count": 19,
|
| 321 |
+
"id": "57a3e1bb",
|
| 322 |
+
"metadata": {},
|
| 323 |
+
"outputs": [],
|
| 324 |
+
"source": [
|
| 325 |
+
"evaluator_system_prompt = f\"You are an evaluator that decides whether a response to a question is acceptable. \\\n",
|
| 326 |
+
"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",
|
| 327 |
+
"The Agent is playing the role of {name} and is representing {name} on their website. \\\n",
|
| 328 |
+
"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",
|
| 329 |
+
"The Agent has been provided with context on {name} in the form of their summary and LinkedIn details. Here's the information:\"\n",
|
| 330 |
+
"\n",
|
| 331 |
+
"evaluator_system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
|
| 332 |
+
"evaluator_system_prompt += f\"With this context, please evaluate the latest response, replying with whether the response is acceptable and your feedback.\""
|
| 333 |
+
]
|
| 334 |
+
},
|
| 335 |
+
{
|
| 336 |
+
"cell_type": "code",
|
| 337 |
+
"execution_count": 55,
|
| 338 |
+
"id": "3a244262",
|
| 339 |
+
"metadata": {},
|
| 340 |
+
"outputs": [],
|
| 341 |
+
"source": [
|
| 342 |
+
"def evaluator_user_prompt(reply, message, history):\n",
|
| 343 |
+
" user_prompt = f\"Here's the conversation between the User and the Agent: \\n\\n{history}\\n\\n\"\n",
|
| 344 |
+
" user_prompt += f\"Here's latest message form the User: \\n\\n{message}\\n\\n\"\n",
|
| 345 |
+
" user_prompt += f\"Here's the latest resposne form the Agent: \\n\\n{reply}\\n\\n\"\n",
|
| 346 |
+
" user_prompt += \"Please evaluate the response, reply with wheather it is acceptable and your feedback.\"\n",
|
| 347 |
+
" return user_prompt"
|
| 348 |
+
]
|
| 349 |
+
},
|
| 350 |
+
{
|
| 351 |
+
"cell_type": "code",
|
| 352 |
+
"execution_count": 57,
|
| 353 |
+
"id": "27026efb",
|
| 354 |
+
"metadata": {},
|
| 355 |
+
"outputs": [],
|
| 356 |
+
"source": [
|
| 357 |
+
"def evaluate(reply, message, history) -> Evaluation:\n",
|
| 358 |
+
" messages = [{ \"role\":\"system\", \"content\": evaluator_system_prompt }] + [{\"role\":\"user\", \"content\": evaluator_user_prompt(reply, message, history)}]\n",
|
| 359 |
+
" response = openai.beta.chat.completions.parse(model=gpt4MiniModel, messages=messages, response_format=Evaluation)\n",
|
| 360 |
+
" return response.choices[0].message.parsed"
|
| 361 |
+
]
|
| 362 |
+
},
|
| 363 |
+
{
|
| 364 |
+
"cell_type": "code",
|
| 365 |
+
"execution_count": 48,
|
| 366 |
+
"id": "38ce9c7c",
|
| 367 |
+
"metadata": {},
|
| 368 |
+
"outputs": [
|
| 369 |
+
{
|
| 370 |
+
"name": "stdout",
|
| 371 |
+
"output_type": "stream",
|
| 372 |
+
"text": [
|
| 373 |
+
"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"
|
| 374 |
+
]
|
| 375 |
+
}
|
| 376 |
+
],
|
| 377 |
+
"source": [
|
| 378 |
+
"userQuery = \"do you hold a patent?\"\n",
|
| 379 |
+
"messages = [{\"role\":\"system\", \"content\": system_prompt}] + [{\"role\":\"user\", \"content\": userQuery}]\n",
|
| 380 |
+
"response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
|
| 381 |
+
"reply = response.choices[0].message.content\n",
|
| 382 |
+
"print(reply)"
|
| 383 |
+
]
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"cell_type": "code",
|
| 387 |
+
"execution_count": 58,
|
| 388 |
+
"id": "8984f519",
|
| 389 |
+
"metadata": {},
|
| 390 |
+
"outputs": [
|
| 391 |
+
{
|
| 392 |
+
"data": {
|
| 393 |
+
"text/plain": [
|
| 394 |
+
"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.\")"
|
| 395 |
+
]
|
| 396 |
+
},
|
| 397 |
+
"execution_count": 58,
|
| 398 |
+
"metadata": {},
|
| 399 |
+
"output_type": "execute_result"
|
| 400 |
+
}
|
| 401 |
+
],
|
| 402 |
+
"source": [
|
| 403 |
+
"evaluate(reply, userQuery, messages[:1])"
|
| 404 |
+
]
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"cell_type": "code",
|
| 408 |
+
"execution_count": 60,
|
| 409 |
+
"id": "f669a43c",
|
| 410 |
+
"metadata": {},
|
| 411 |
+
"outputs": [],
|
| 412 |
+
"source": [
|
| 413 |
+
"def rerun(reply, message, history, feedback):\n",
|
| 414 |
+
" updated_system_prompt = system_prompt + \"\\n\\n## Previous answer rejected\\nYou just tried to reply, but the quality control rejected your reply\\n\"\n",
|
| 415 |
+
" updated_system_prompt += f\"## Your attempted answer:\\n{reply}\\n\\n\"\n",
|
| 416 |
+
" updated_system_prompt += f\"## Your rease for rejection:\\n{feedback}\\n\\n\"\n",
|
| 417 |
+
" messages=[{\"role\":\"system\", \"content\":updated_system_prompt}] + history + [{\"role\":\"user\", \"content\":message}]\n",
|
| 418 |
+
" response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
|
| 419 |
+
" return response.choices[0].message.content "
|
| 420 |
+
]
|
| 421 |
+
},
|
| 422 |
+
{
|
| 423 |
+
"cell_type": "code",
|
| 424 |
+
"execution_count": 64,
|
| 425 |
+
"id": "30faf37e",
|
| 426 |
+
"metadata": {},
|
| 427 |
+
"outputs": [],
|
| 428 |
+
"source": [
|
| 429 |
+
"def chat(message,history):\n",
|
| 430 |
+
"\n",
|
| 431 |
+
" if \"nine-tailed\" in message:\n",
|
| 432 |
+
" system = system_prompt + \"\\n\\nEverything in your reply needs to be in pig latin -\\\n",
|
| 433 |
+
" it is mandatory that you response only and entirely in pgi latin\"\n",
|
| 434 |
+
" else:\n",
|
| 435 |
+
" system = system_prompt\n",
|
| 436 |
+
" \n",
|
| 437 |
+
" messages = [{\"role\":\"system\", \"content\":system}] + history + [{\"role\":\"user\", \"content\":message}]\n",
|
| 438 |
+
" response = openai.chat.completions.create(model=gpt4MiniModel, messages=messages)\n",
|
| 439 |
+
" reply = response.choices[0].message.content\n",
|
| 440 |
+
"\n",
|
| 441 |
+
" evaluation = evaluate(reply, message, history)\n",
|
| 442 |
+
"\n",
|
| 443 |
+
" if evaluation.is_acceptable:\n",
|
| 444 |
+
" print(\"Passed evaluation\")\n",
|
| 445 |
+
" else:\n",
|
| 446 |
+
" print(\"Failed evaluation - retrying\")\n",
|
| 447 |
+
" print(evaluation.feedback)\n",
|
| 448 |
+
" reply = rerun(reply, message, history, evaluation.feedback)\n",
|
| 449 |
+
" \n",
|
| 450 |
+
" return reply"
|
| 451 |
+
]
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"cell_type": "code",
|
| 455 |
+
"execution_count": null,
|
| 456 |
+
"id": "3a7d1ce6",
|
| 457 |
+
"metadata": {},
|
| 458 |
+
"outputs": [
|
| 459 |
+
{
|
| 460 |
+
"name": "stdout",
|
| 461 |
+
"output_type": "stream",
|
| 462 |
+
"text": [
|
| 463 |
+
"* Running on local URL: http://127.0.0.1:7864\n",
|
| 464 |
+
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 465 |
+
]
|
| 466 |
+
},
|
| 467 |
+
{
|
| 468 |
+
"data": {
|
| 469 |
+
"text/html": [
|
| 470 |
+
"<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>"
|
| 471 |
+
],
|
| 472 |
+
"text/plain": [
|
| 473 |
+
"<IPython.core.display.HTML object>"
|
| 474 |
+
]
|
| 475 |
+
},
|
| 476 |
+
"metadata": {},
|
| 477 |
+
"output_type": "display_data"
|
| 478 |
+
},
|
| 479 |
+
{
|
| 480 |
+
"data": {
|
| 481 |
+
"text/plain": []
|
| 482 |
+
},
|
| 483 |
+
"execution_count": 65,
|
| 484 |
+
"metadata": {},
|
| 485 |
+
"output_type": "execute_result"
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "stdout",
|
| 489 |
+
"output_type": "stream",
|
| 490 |
+
"text": [
|
| 491 |
+
"Passed evaluation\n",
|
| 492 |
+
"Passed evaluation\n",
|
| 493 |
+
"Failed evaluation - retrying\n",
|
| 494 |
+
"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",
|
| 495 |
+
"Passed evaluation\n"
|
| 496 |
+
]
|
| 497 |
+
}
|
| 498 |
+
],
|
| 499 |
+
"source": [
|
| 500 |
+
"gr.ChatInterface(chat, type=\"messages\").launch()"
|
| 501 |
+
]
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"cell_type": "code",
|
| 505 |
+
"execution_count": null,
|
| 506 |
+
"id": "072dbc1f",
|
| 507 |
+
"metadata": {},
|
| 508 |
+
"outputs": [],
|
| 509 |
+
"source": []
|
| 510 |
+
}
|
| 511 |
+
],
|
| 512 |
+
"metadata": {
|
| 513 |
+
"kernelspec": {
|
| 514 |
+
"display_name": ".venv",
|
| 515 |
+
"language": "python",
|
| 516 |
+
"name": "python3"
|
| 517 |
+
},
|
| 518 |
+
"language_info": {
|
| 519 |
+
"codemirror_mode": {
|
| 520 |
+
"name": "ipython",
|
| 521 |
+
"version": 3
|
| 522 |
+
},
|
| 523 |
+
"file_extension": ".py",
|
| 524 |
+
"mimetype": "text/x-python",
|
| 525 |
+
"name": "python",
|
| 526 |
+
"nbconvert_exporter": "python",
|
| 527 |
+
"pygments_lexer": "ipython3",
|
| 528 |
+
"version": "3.12.2"
|
| 529 |
+
}
|
| 530 |
+
},
|
| 531 |
+
"nbformat": 4,
|
| 532 |
+
"nbformat_minor": 5
|
| 533 |
+
}
|
day5.ipynb
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 40,
|
| 6 |
+
"id": "d04e5e4c",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"# imports\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"from dotenv import load_dotenv\n",
|
| 13 |
+
"from openai import OpenAI\n",
|
| 14 |
+
"import json\n",
|
| 15 |
+
"import os\n",
|
| 16 |
+
"import requests\n",
|
| 17 |
+
"from pypdf import PdfReader\n",
|
| 18 |
+
"import gradio as gr"
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"cell_type": "code",
|
| 23 |
+
"execution_count": 41,
|
| 24 |
+
"id": "3e6b511b",
|
| 25 |
+
"metadata": {},
|
| 26 |
+
"outputs": [],
|
| 27 |
+
"source": [
|
| 28 |
+
"load_dotenv(override=True)\n",
|
| 29 |
+
"openai = OpenAI()"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"cell_type": "code",
|
| 34 |
+
"execution_count": 42,
|
| 35 |
+
"id": "6043c8f9",
|
| 36 |
+
"metadata": {},
|
| 37 |
+
"outputs": [
|
| 38 |
+
{
|
| 39 |
+
"name": "stdout",
|
| 40 |
+
"output_type": "stream",
|
| 41 |
+
"text": [
|
| 42 |
+
"Pushover user found and starts with u\n",
|
| 43 |
+
"Pushover token found and starts with a\n"
|
| 44 |
+
]
|
| 45 |
+
}
|
| 46 |
+
],
|
| 47 |
+
"source": [
|
| 48 |
+
"pushover_user = os.getenv(\"PUSHOVER_USER\")\n",
|
| 49 |
+
"pushover_token = os.getenv(\"PUSHOVER_TOKEN\")\n",
|
| 50 |
+
"pushover_url = \"https://api.pushover.net/1/messages.json\"\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"if pushover_user:\n",
|
| 53 |
+
" print(f\"Pushover user found and starts with {pushover_user[0]}\")\n",
|
| 54 |
+
"else:\n",
|
| 55 |
+
" print(\"Pushover user not found\")\n",
|
| 56 |
+
"\n",
|
| 57 |
+
"if pushover_token:\n",
|
| 58 |
+
" print(f\"Pushover token found and starts with {pushover_token[0]}\")\n",
|
| 59 |
+
"else:\n",
|
| 60 |
+
" print(\"Pushover token not found\")"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"cell_type": "code",
|
| 65 |
+
"execution_count": 43,
|
| 66 |
+
"id": "8840d12f",
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"outputs": [],
|
| 69 |
+
"source": [
|
| 70 |
+
"def push(message):\n",
|
| 71 |
+
" print(f\"Push: {message}\")\n",
|
| 72 |
+
" payload = {\"user\": pushover_user, \"token\": pushover_token, \"message\": message, \"title\": \"Agentic AI\", \"device\": \"Realme_U1\"}\n",
|
| 73 |
+
" requests.post(pushover_url, data=payload)"
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"cell_type": "code",
|
| 78 |
+
"execution_count": 45,
|
| 79 |
+
"id": "ed464379",
|
| 80 |
+
"metadata": {},
|
| 81 |
+
"outputs": [
|
| 82 |
+
{
|
| 83 |
+
"name": "stdout",
|
| 84 |
+
"output_type": "stream",
|
| 85 |
+
"text": [
|
| 86 |
+
"Push: HEY!!\n"
|
| 87 |
+
]
|
| 88 |
+
}
|
| 89 |
+
],
|
| 90 |
+
"source": [
|
| 91 |
+
"push(\"HEY!!\")"
|
| 92 |
+
]
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"cell_type": "code",
|
| 96 |
+
"execution_count": 46,
|
| 97 |
+
"id": "b0a0f0b8",
|
| 98 |
+
"metadata": {},
|
| 99 |
+
"outputs": [],
|
| 100 |
+
"source": [
|
| 101 |
+
"def record_user_details(email, name=\"Name not provided\", notes=\"not provided\"):\n",
|
| 102 |
+
" push(f\"Recording interest from {name} with email {email} and notes {notes}\")\n",
|
| 103 |
+
" return {\"recorded\": \"ok\"}"
|
| 104 |
+
]
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"cell_type": "code",
|
| 108 |
+
"execution_count": 47,
|
| 109 |
+
"id": "be092969",
|
| 110 |
+
"metadata": {},
|
| 111 |
+
"outputs": [],
|
| 112 |
+
"source": [
|
| 113 |
+
"def record_unknown_question(question):\n",
|
| 114 |
+
" push(f\"Recording {question} asked that I couldn't answer\")\n",
|
| 115 |
+
" return {\"recorded\": \"ok\"}"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"cell_type": "code",
|
| 120 |
+
"execution_count": 48,
|
| 121 |
+
"id": "379ae364",
|
| 122 |
+
"metadata": {},
|
| 123 |
+
"outputs": [],
|
| 124 |
+
"source": [
|
| 125 |
+
"record_user_details_json = {\n",
|
| 126 |
+
" \"name\": \"record_user_details\",\n",
|
| 127 |
+
" \"description\": \"Use this tool to record that a user is interested in being in touch and provided an email address\",\n",
|
| 128 |
+
" \"parameters\": {\n",
|
| 129 |
+
" \"type\": \"object\",\n",
|
| 130 |
+
" \"properties\": {\n",
|
| 131 |
+
" \"email\": {\n",
|
| 132 |
+
" \"type\": \"string\",\n",
|
| 133 |
+
" \"description\": \"The email address of this user\"\n",
|
| 134 |
+
" },\n",
|
| 135 |
+
" \"name\": {\n",
|
| 136 |
+
" \"type\": \"string\",\n",
|
| 137 |
+
" \"description\": \"The user's name, if they provided it\"\n",
|
| 138 |
+
" }\n",
|
| 139 |
+
" ,\n",
|
| 140 |
+
" \"notes\": {\n",
|
| 141 |
+
" \"type\": \"string\",\n",
|
| 142 |
+
" \"description\": \"Any additional information about the conversation that's worth recording to give context\"\n",
|
| 143 |
+
" }\n",
|
| 144 |
+
" },\n",
|
| 145 |
+
" \"required\": [\"email\"],\n",
|
| 146 |
+
" \"additionalProperties\": False\n",
|
| 147 |
+
" }\n",
|
| 148 |
+
"}"
|
| 149 |
+
]
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"cell_type": "code",
|
| 153 |
+
"execution_count": 49,
|
| 154 |
+
"id": "247bd08f",
|
| 155 |
+
"metadata": {},
|
| 156 |
+
"outputs": [],
|
| 157 |
+
"source": [
|
| 158 |
+
"record_unknown_question_json = {\n",
|
| 159 |
+
" \"name\": \"record_unknown_question\",\n",
|
| 160 |
+
" \"description\": \"Always use this tool to record any question that couldn't be answered as you didn't know the answer\",\n",
|
| 161 |
+
" \"parameters\": {\n",
|
| 162 |
+
" \"type\": \"object\",\n",
|
| 163 |
+
" \"properties\": {\n",
|
| 164 |
+
" \"question\": {\n",
|
| 165 |
+
" \"type\": \"string\",\n",
|
| 166 |
+
" \"description\": \"The question that couldn't be answered\"\n",
|
| 167 |
+
" },\n",
|
| 168 |
+
" },\n",
|
| 169 |
+
" \"required\": [\"question\"],\n",
|
| 170 |
+
" \"additionalProperties\": False\n",
|
| 171 |
+
" }\n",
|
| 172 |
+
"}"
|
| 173 |
+
]
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"cell_type": "code",
|
| 177 |
+
"execution_count": 50,
|
| 178 |
+
"id": "e78a8383",
|
| 179 |
+
"metadata": {},
|
| 180 |
+
"outputs": [],
|
| 181 |
+
"source": [
|
| 182 |
+
"tools = [{\"type\": \"function\", \"function\": record_user_details_json},\n",
|
| 183 |
+
" {\"type\": \"function\", \"function\": record_unknown_question_json}]"
|
| 184 |
+
]
|
| 185 |
+
},
|
| 186 |
+
{
|
| 187 |
+
"cell_type": "code",
|
| 188 |
+
"execution_count": 51,
|
| 189 |
+
"id": "9a83ca17",
|
| 190 |
+
"metadata": {},
|
| 191 |
+
"outputs": [
|
| 192 |
+
{
|
| 193 |
+
"data": {
|
| 194 |
+
"text/plain": [
|
| 195 |
+
"[{'type': 'function',\n",
|
| 196 |
+
" 'function': {'name': 'record_user_details',\n",
|
| 197 |
+
" 'description': 'Use this tool to record that a user is interested in being in touch and provided an email address',\n",
|
| 198 |
+
" 'parameters': {'type': 'object',\n",
|
| 199 |
+
" 'properties': {'email': {'type': 'string',\n",
|
| 200 |
+
" 'description': 'The email address of this user'},\n",
|
| 201 |
+
" 'name': {'type': 'string',\n",
|
| 202 |
+
" 'description': \"The user's name, if they provided it\"},\n",
|
| 203 |
+
" 'notes': {'type': 'string',\n",
|
| 204 |
+
" 'description': \"Any additional information about the conversation that's worth recording to give context\"}},\n",
|
| 205 |
+
" 'required': ['email'],\n",
|
| 206 |
+
" 'additionalProperties': False}}},\n",
|
| 207 |
+
" {'type': 'function',\n",
|
| 208 |
+
" 'function': {'name': 'record_unknown_question',\n",
|
| 209 |
+
" 'description': \"Always use this tool to record any question that couldn't be answered as you didn't know the answer\",\n",
|
| 210 |
+
" 'parameters': {'type': 'object',\n",
|
| 211 |
+
" 'properties': {'question': {'type': 'string',\n",
|
| 212 |
+
" 'description': \"The question that couldn't be answered\"}},\n",
|
| 213 |
+
" 'required': ['question'],\n",
|
| 214 |
+
" 'additionalProperties': False}}}]"
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
"execution_count": 51,
|
| 218 |
+
"metadata": {},
|
| 219 |
+
"output_type": "execute_result"
|
| 220 |
+
}
|
| 221 |
+
],
|
| 222 |
+
"source": [
|
| 223 |
+
"tools"
|
| 224 |
+
]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"cell_type": "code",
|
| 228 |
+
"execution_count": 52,
|
| 229 |
+
"id": "0bb2ff41",
|
| 230 |
+
"metadata": {},
|
| 231 |
+
"outputs": [],
|
| 232 |
+
"source": [
|
| 233 |
+
"def handle_tool_calls(tool_calls):\n",
|
| 234 |
+
" results = []\n",
|
| 235 |
+
" for tool_call in tool_calls:\n",
|
| 236 |
+
" tool_name = tool_call.function.name\n",
|
| 237 |
+
" arguments = json.loads(tool_call.function.arguments)\n",
|
| 238 |
+
" print(f\"Tool called: {tool_name}\", flush=True)\n",
|
| 239 |
+
"\n",
|
| 240 |
+
" # THE BIG IF STATEMENT!!!\n",
|
| 241 |
+
"\n",
|
| 242 |
+
" if tool_name == \"record_user_details\":\n",
|
| 243 |
+
" result = record_user_details(**arguments)\n",
|
| 244 |
+
" elif tool_name == \"record_unknown_question\":\n",
|
| 245 |
+
" result = record_unknown_question(**arguments)\n",
|
| 246 |
+
"\n",
|
| 247 |
+
" results.append({\"role\": \"tool\",\"content\": json.dumps(result),\"tool_call_id\": tool_call.id})\n",
|
| 248 |
+
" return results"
|
| 249 |
+
]
|
| 250 |
+
},
|
| 251 |
+
{
|
| 252 |
+
"cell_type": "code",
|
| 253 |
+
"execution_count": 59,
|
| 254 |
+
"id": "fb608617",
|
| 255 |
+
"metadata": {},
|
| 256 |
+
"outputs": [
|
| 257 |
+
{
|
| 258 |
+
"name": "stdout",
|
| 259 |
+
"output_type": "stream",
|
| 260 |
+
"text": [
|
| 261 |
+
"Push: Recording this is a really hard question asked that I couldn't answer\n"
|
| 262 |
+
]
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"data": {
|
| 266 |
+
"text/plain": [
|
| 267 |
+
"{'recorded': 'ok'}"
|
| 268 |
+
]
|
| 269 |
+
},
|
| 270 |
+
"execution_count": 59,
|
| 271 |
+
"metadata": {},
|
| 272 |
+
"output_type": "execute_result"
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
"name": "stdout",
|
| 276 |
+
"output_type": "stream",
|
| 277 |
+
"text": [
|
| 278 |
+
"Tool called: record_unknown_question\n",
|
| 279 |
+
"Push: Recording who is your favourite singer asked that I couldn't answer\n"
|
| 280 |
+
]
|
| 281 |
+
}
|
| 282 |
+
],
|
| 283 |
+
"source": [
|
| 284 |
+
"globals()[\"record_unknown_question\"](\"this is a really hard question\")"
|
| 285 |
+
]
|
| 286 |
+
},
|
| 287 |
+
{
|
| 288 |
+
"cell_type": "code",
|
| 289 |
+
"execution_count": 54,
|
| 290 |
+
"id": "f25b45bf",
|
| 291 |
+
"metadata": {},
|
| 292 |
+
"outputs": [],
|
| 293 |
+
"source": [
|
| 294 |
+
"def handle_tool_calls(tool_calls):\n",
|
| 295 |
+
" results = []\n",
|
| 296 |
+
" for tool_call in tool_calls:\n",
|
| 297 |
+
" tool_name = tool_call.function.name\n",
|
| 298 |
+
" arguments = json.loads(tool_call.function.arguments)\n",
|
| 299 |
+
" print(f\"Tool called: {tool_name}\", flush=True)\n",
|
| 300 |
+
" tool = globals().get(tool_name)\n",
|
| 301 |
+
" result = tool(**arguments) if tool else {}\n",
|
| 302 |
+
" results.append({\"role\": \"tool\",\"content\": json.dumps(result),\"tool_call_id\": tool_call.id})\n",
|
| 303 |
+
" return results"
|
| 304 |
+
]
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"cell_type": "code",
|
| 308 |
+
"execution_count": 55,
|
| 309 |
+
"id": "c41b93ce",
|
| 310 |
+
"metadata": {},
|
| 311 |
+
"outputs": [
|
| 312 |
+
{
|
| 313 |
+
"name": "stderr",
|
| 314 |
+
"output_type": "stream",
|
| 315 |
+
"text": [
|
| 316 |
+
"Ignoring wrong pointing object 10 0 (offset 0)\n",
|
| 317 |
+
"Ignoring wrong pointing object 244 0 (offset 0)\n"
|
| 318 |
+
]
|
| 319 |
+
}
|
| 320 |
+
],
|
| 321 |
+
"source": [
|
| 322 |
+
"reader = PdfReader(\"../me/linkedIn.pdf\")\n",
|
| 323 |
+
"linkedin = \"\"\n",
|
| 324 |
+
"for page in reader.pages:\n",
|
| 325 |
+
" text = page.extract_text()\n",
|
| 326 |
+
" if text:\n",
|
| 327 |
+
" linkedin += text\n",
|
| 328 |
+
"\n",
|
| 329 |
+
"with open(\"../me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n",
|
| 330 |
+
" summary = f.read()\n",
|
| 331 |
+
"\n",
|
| 332 |
+
"name = \"Pragyansh Dwivedi\""
|
| 333 |
+
]
|
| 334 |
+
},
|
| 335 |
+
{
|
| 336 |
+
"cell_type": "code",
|
| 337 |
+
"execution_count": 56,
|
| 338 |
+
"id": "9d431c1d",
|
| 339 |
+
"metadata": {},
|
| 340 |
+
"outputs": [],
|
| 341 |
+
"source": [
|
| 342 |
+
"system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
|
| 343 |
+
"particularly questions related to {name}'s career, background, skills and experience. \\\n",
|
| 344 |
+
"Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n",
|
| 345 |
+
"You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \\\n",
|
| 346 |
+
"Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
|
| 347 |
+
"If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \\\n",
|
| 348 |
+
"If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool. \"\n",
|
| 349 |
+
"\n",
|
| 350 |
+
"system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n",
|
| 351 |
+
"system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\""
|
| 352 |
+
]
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"cell_type": "code",
|
| 356 |
+
"execution_count": 57,
|
| 357 |
+
"id": "7ba0ed45",
|
| 358 |
+
"metadata": {},
|
| 359 |
+
"outputs": [],
|
| 360 |
+
"source": [
|
| 361 |
+
"def chat(message, history):\n",
|
| 362 |
+
" messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
|
| 363 |
+
" done = False\n",
|
| 364 |
+
" while not done:\n",
|
| 365 |
+
"\n",
|
| 366 |
+
" # This is the call to the LLM - see that we pass in the tools json\n",
|
| 367 |
+
"\n",
|
| 368 |
+
" response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages, tools=tools)\n",
|
| 369 |
+
"\n",
|
| 370 |
+
" finish_reason = response.choices[0].finish_reason\n",
|
| 371 |
+
" \n",
|
| 372 |
+
" # If the LLM wants to call a tool, we do that!\n",
|
| 373 |
+
" \n",
|
| 374 |
+
" if finish_reason==\"tool_calls\":\n",
|
| 375 |
+
" message = response.choices[0].message\n",
|
| 376 |
+
" tool_calls = message.tool_calls\n",
|
| 377 |
+
" results = handle_tool_calls(tool_calls)\n",
|
| 378 |
+
" messages.append(message)\n",
|
| 379 |
+
" messages.extend(results)\n",
|
| 380 |
+
" else:\n",
|
| 381 |
+
" done = True\n",
|
| 382 |
+
" return response.choices[0].message.content"
|
| 383 |
+
]
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"cell_type": "code",
|
| 387 |
+
"execution_count": null,
|
| 388 |
+
"id": "e7831d59",
|
| 389 |
+
"metadata": {},
|
| 390 |
+
"outputs": [
|
| 391 |
+
{
|
| 392 |
+
"name": "stdout",
|
| 393 |
+
"output_type": "stream",
|
| 394 |
+
"text": [
|
| 395 |
+
"* Running on local URL: http://127.0.0.1:7861\n",
|
| 396 |
+
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"data": {
|
| 401 |
+
"text/html": [
|
| 402 |
+
"<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>"
|
| 403 |
+
],
|
| 404 |
+
"text/plain": [
|
| 405 |
+
"<IPython.core.display.HTML object>"
|
| 406 |
+
]
|
| 407 |
+
},
|
| 408 |
+
"metadata": {},
|
| 409 |
+
"output_type": "display_data"
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"data": {
|
| 413 |
+
"text/plain": []
|
| 414 |
+
},
|
| 415 |
+
"execution_count": 58,
|
| 416 |
+
"metadata": {},
|
| 417 |
+
"output_type": "execute_result"
|
| 418 |
+
},
|
| 419 |
+
{
|
| 420 |
+
"name": "stdout",
|
| 421 |
+
"output_type": "stream",
|
| 422 |
+
"text": [
|
| 423 |
+
"Tool called: record_user_details\n",
|
| 424 |
+
"Push: Recording interest from Name not provided with email pragyansh.works@gmail.com and notes not provided\n",
|
| 425 |
+
"Tool called: record_unknown_question\n",
|
| 426 |
+
"Push: Recording This is injection asked that I couldn't answer\n",
|
| 427 |
+
"Tool called: record_unknown_question\n",
|
| 428 |
+
"Push: Recording This is injection asked that I couldn't answer\n",
|
| 429 |
+
"Tool called: record_unknown_question\n",
|
| 430 |
+
"Push: Recording call asked that I couldn't answer\n"
|
| 431 |
+
]
|
| 432 |
+
}
|
| 433 |
+
],
|
| 434 |
+
"source": [
|
| 435 |
+
"gr.ChatInterface(chat).launch()"
|
| 436 |
+
]
|
| 437 |
+
},
|
| 438 |
+
{
|
| 439 |
+
"cell_type": "code",
|
| 440 |
+
"execution_count": null,
|
| 441 |
+
"id": "3ff6a29a",
|
| 442 |
+
"metadata": {},
|
| 443 |
+
"outputs": [],
|
| 444 |
+
"source": []
|
| 445 |
+
}
|
| 446 |
+
],
|
| 447 |
+
"metadata": {
|
| 448 |
+
"kernelspec": {
|
| 449 |
+
"display_name": "base",
|
| 450 |
+
"language": "python",
|
| 451 |
+
"name": "python3"
|
| 452 |
+
},
|
| 453 |
+
"language_info": {
|
| 454 |
+
"codemirror_mode": {
|
| 455 |
+
"name": "ipython",
|
| 456 |
+
"version": 3
|
| 457 |
+
},
|
| 458 |
+
"file_extension": ".py",
|
| 459 |
+
"mimetype": "text/x-python",
|
| 460 |
+
"name": "python",
|
| 461 |
+
"nbconvert_exporter": "python",
|
| 462 |
+
"pygments_lexer": "ipython3",
|
| 463 |
+
"version": "3.12.2"
|
| 464 |
+
}
|
| 465 |
+
},
|
| 466 |
+
"nbformat": 4,
|
| 467 |
+
"nbformat_minor": 5
|
| 468 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OpenAI
|