Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -109,33 +109,34 @@ If you can't answer something, call `record_unknown_question`. If a user seems i
|
|
109 |
return results
|
110 |
|
111 |
def chat_stream(self, message, history):
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
-
|
128 |
-
for chunk in stream:
|
129 |
-
delta = chunk.choices[0].delta
|
130 |
-
if hasattr(delta, "content") and delta.content:
|
131 |
-
full_response += delta.content
|
132 |
-
yield full_response
|
133 |
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
self.session_log.append({"role": "assistant", "content": full_response})
|
138 |
-
self.save_session_log()
|
139 |
|
140 |
def save_session_log(self):
|
141 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
109 |
return results
|
110 |
|
111 |
def chat_stream(self, message, history):
|
112 |
+
messages = [{"role": "system", "content": self.system_prompt()}]
|
113 |
+
|
114 |
+
for msg in history:
|
115 |
+
if msg["role"] in ["user", "assistant"]:
|
116 |
+
messages.append(msg)
|
117 |
+
|
118 |
+
messages.append({"role": "user", "content": message})
|
119 |
+
self.session_log.append({"role": "user", "content": message})
|
120 |
+
|
121 |
+
stream = self.openai.chat.completions.create(
|
122 |
+
model="gpt-4o",
|
123 |
+
messages=messages,
|
124 |
+
tools=tools,
|
125 |
+
stream=True
|
126 |
+
)
|
127 |
+
|
128 |
+
full_response = ""
|
129 |
+
for chunk in stream:
|
130 |
+
delta = chunk.choices[0].delta
|
131 |
+
if hasattr(delta, "content") and delta.content:
|
132 |
+
full_response += delta.content
|
133 |
+
yield full_response
|
134 |
|
135 |
+
full_response += "\n\n💬 Let me know if you’d like to follow up or need help connecting with Jacob."
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
+
self.session_log.append({"role": "assistant", "content": full_response})
|
138 |
+
self.save_session_log()
|
139 |
|
|
|
|
|
140 |
|
141 |
def save_session_log(self):
|
142 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|