jisaacso219 commited on
Commit
b19d7d9
·
verified ·
1 Parent(s): d99b8a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -49
app.py CHANGED
@@ -32,36 +32,26 @@ def push(text):
32
  def record_user_details(email, name="Name not provided", notes="not provided"):
33
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
34
  filename = f"chat_logs/session_{timestamp}.json"
35
- latest_log = "
36
- ".join([
37
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
38
  for entry in me.session_log[-6:]
39
  ])
40
  with open(filename, "w", encoding="utf-8") as f:
41
  json.dump(me.session_log, f, indent=2)
42
- msg = f"[New Contact]
43
- Name: {name}
44
- Email: {email}
45
- Notes: {notes}
46
-
47
- 🔗 View log: {filename}"
48
  push(msg)
49
  return {"recorded": "ok"}
50
 
51
  def record_unknown_question(question):
52
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
53
  filename = f"chat_logs/session_{timestamp}.json"
54
- latest_log = "
55
- ".join([
56
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
57
  for entry in me.session_log[-6:]
58
  ])
59
  with open(filename, "w", encoding="utf-8") as f:
60
  json.dump(me.session_log, f, indent=2)
61
- msg = f"[Unknown Question]
62
- Q: {question}
63
-
64
- 🔗 View log: {filename}"
65
  push(msg)
66
  return {"recorded": "ok"}
67
 
@@ -104,6 +94,9 @@ class Me:
104
  self.name = "Jacob Isaacson"
105
  self.session_log = []
106
  Path("chat_logs").mkdir(exist_ok=True)
 
 
 
107
 
108
  gdown.download("https://drive.google.com/uc?id=1xz2RowkImpI8odYv8zvKdlRHaKfILn40", "linkedin.pdf", quiet=False)
109
  reader = PdfReader("linkedin.pdf")
@@ -141,6 +134,10 @@ If you can't answer something, call `record_unknown_question`. If a user seems i
141
  def chat_stream(self, message, history):
142
  messages = [{"role": "system", "content": self.system_prompt()}]
143
 
 
 
 
 
144
  for msg in history:
145
  if isinstance(msg, dict) and msg.get("role") in ["user", "assistant"]:
146
  messages.append(msg)
@@ -152,43 +149,15 @@ If you can't answer something, call `record_unknown_question`. If a user seems i
152
  model="gpt-4o",
153
  messages=messages,
154
  tools=tools,
155
- stream=False
156
  )
157
 
158
- reply = response.choices[0].message
159
-
160
- if reply.tool_calls:
161
- tool_results = self.handle_tool_call(reply.tool_calls)
162
- messages.append(reply)
163
- messages.extend(tool_results)
164
-
165
- final_response = self.openai.chat.completions.create(
166
- model="gpt-4o",
167
- messages=messages,
168
- tools=tools,
169
- stream=True
170
- )
171
-
172
- full_response = ""
173
- for chunk in final_response:
174
- delta = chunk.choices[0].delta
175
- if hasattr(delta, "content") and delta.content:
176
- full_response += delta.content
177
- yield full_response
178
- else:
179
- stream = self.openai.chat.completions.create(
180
- model="gpt-4o",
181
- messages=messages,
182
- tools=tools,
183
- stream=True
184
- )
185
-
186
- full_response = ""
187
- for chunk in stream:
188
- delta = chunk.choices[0].delta
189
- if hasattr(delta, "content") and delta.content:
190
- full_response += delta.content
191
- yield full_response
192
 
193
  full_response += "\n\n💬 Let me know if you’d like to follow up or need help connecting with Jacob."
194
  self.session_log.append({"role": "assistant", "content": full_response})
 
32
  def record_user_details(email, name="Name not provided", notes="not provided"):
33
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
34
  filename = f"chat_logs/session_{timestamp}.json"
35
+ latest_log = "\n".join([
 
36
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
37
  for entry in me.session_log[-6:]
38
  ])
39
  with open(filename, "w", encoding="utf-8") as f:
40
  json.dump(me.session_log, f, indent=2)
41
+ msg = f"[New Contact]\nName: {name}\nEmail: {email}\nNotes: {notes}\n\n🔗 View log: {filename}\n\nLast messages:\n{latest_log}"
 
 
 
 
 
42
  push(msg)
43
  return {"recorded": "ok"}
44
 
45
  def record_unknown_question(question):
46
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
47
  filename = f"chat_logs/session_{timestamp}.json"
48
+ latest_log = "\n".join([
 
49
  f"{entry['role'].capitalize()}: {entry['content'][:200]}"
50
  for entry in me.session_log[-6:]
51
  ])
52
  with open(filename, "w", encoding="utf-8") as f:
53
  json.dump(me.session_log, f, indent=2)
54
+ msg = f"[Unknown Question]\nQ: {question}\n\n🔗 View log: {filename}\n\nLast messages:\n{latest_log}"
 
 
 
55
  push(msg)
56
  return {"recorded": "ok"}
57
 
 
94
  self.name = "Jacob Isaacson"
95
  self.session_log = []
96
  Path("chat_logs").mkdir(exist_ok=True)
97
+ keep_path = Path("chat_logs/.keep")
98
+ if not keep_path.exists():
99
+ keep_path.touch()
100
 
101
  gdown.download("https://drive.google.com/uc?id=1xz2RowkImpI8odYv8zvKdlRHaKfILn40", "linkedin.pdf", quiet=False)
102
  reader = PdfReader("linkedin.pdf")
 
134
  def chat_stream(self, message, history):
135
  messages = [{"role": "system", "content": self.system_prompt()}]
136
 
137
+ if not history:
138
+ self.session_log.append({"role": "assistant", "content": "Hello, my name is Jacob Isaacson. Please ask me any questions about my professional career and I will do my best to respond."})
139
+ yield self.session_log[-1]["content"]
140
+
141
  for msg in history:
142
  if isinstance(msg, dict) and msg.get("role") in ["user", "assistant"]:
143
  messages.append(msg)
 
149
  model="gpt-4o",
150
  messages=messages,
151
  tools=tools,
152
+ stream=True
153
  )
154
 
155
+ full_response = ""
156
+ for chunk in response:
157
+ delta = chunk.choices[0].delta
158
+ if hasattr(delta, "content") and delta.content:
159
+ full_response += delta.content
160
+ yield full_response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  full_response += "\n\n💬 Let me know if you’d like to follow up or need help connecting with Jacob."
163
  self.session_log.append({"role": "assistant", "content": full_response})