srinuksv commited on
Commit
db6fcb0
1 Parent(s): d15c20a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
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 'history' is a key in the incoming dictionary
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 context and tell me user interest: " + hist
168
  print(hist)
 
 
169
  result = client.predict(
170
- message=hist,
171
- api_name="/chat"
172
- )
173
- sf.Lead.update(user_id,{'Description': result})
 
 
 
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):