Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -160,17 +160,28 @@ async def load_chat(request: Request, id: str):
|
|
160 |
# Route to save chat history
|
161 |
@app.post("/hist/")
|
162 |
async def save_chat_history(history: dict):
|
163 |
-
# Check if '
|
164 |
user_id = history.get('userId')
|
165 |
print(user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
hist = ''.join([f"'{entry['sender']}: {entry['message']}'\n" for entry in history['history']])
|
167 |
-
hist = "summarize this
|
168 |
print(hist)
|
|
|
|
|
169 |
result = client.predict(
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
174 |
return {"summary": result, "message": "Chat history saved"}
|
175 |
@app.post("/webhook")
|
176 |
async def receive_form_data(request: Request):
|
|
|
160 |
# Route to save chat history
|
161 |
@app.post("/hist/")
|
162 |
async def save_chat_history(history: dict):
|
163 |
+
# Check if 'userId' is present in the incoming dictionary
|
164 |
user_id = history.get('userId')
|
165 |
print(user_id)
|
166 |
+
|
167 |
+
# Ensure user_id is defined before proceeding
|
168 |
+
if user_id is None:
|
169 |
+
return {"error": "userId is required"}, 400
|
170 |
+
|
171 |
+
# Construct the chat history string
|
172 |
hist = ''.join([f"'{entry['sender']}: {entry['message']}'\n" for entry in history['history']])
|
173 |
+
hist = "You are a Redfernstech summarize model. Your aim is to use this conversation to identify user interests solely based on that conversation: " + hist
|
174 |
print(hist)
|
175 |
+
|
176 |
+
# Get the summarized result from the client model
|
177 |
result = client.predict(
|
178 |
+
message=hist,
|
179 |
+
api_name="/chat"
|
180 |
+
)
|
181 |
+
|
182 |
+
# Update the lead's description with the summary result
|
183 |
+
sf.Lead.update(user_id, {'Description': result})
|
184 |
+
|
185 |
return {"summary": result, "message": "Chat history saved"}
|
186 |
@app.post("/webhook")
|
187 |
async def receive_form_data(request: Request):
|