srinuksv commited on
Commit
23174f3
1 Parent(s): a6ab03d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -27,25 +27,7 @@ llm_client = InferenceClient(
27
  model=repo_id,
28
  token=os.getenv("HF_TOKEN"),
29
  )
30
- def summarize_conversation(history: list):
31
- try:
32
- hist = ''.join([f"'{entry['sender']}: {entry['message']}'\n" for entry in history])
33
- hist = "summarize this context and tell me user interest: " + hist
34
-
35
- client = Client("Qwen/Qwen2.5-72B-Instruct")
36
- result = client.predict(
37
- query=hist,
38
- history=[],
39
- system="You are clara, created by redferntech. You are a helpful assistant.",
40
- api_name="/predict"
41
- )
42
- return result
43
- except Exception as e:
44
- print(f"Summarization error: {str(e)}")
45
- return "Error during summarization"
46
-
47
-
48
-
49
  os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
50
  username = os.getenv("username")
51
  password = os.getenv("password")
@@ -181,14 +163,17 @@ async def save_chat_history(history: dict):
181
  # Check if 'history' is a key in the incoming dictionary
182
  user_id = history.get('userId')
183
  print(user_id)
184
- if 'history' in history and isinstance(history['history'], list):
185
- print("Received history:", history['history']) # Debugging line
186
- cleaned_summary = summarize_conversation(history['history'])
187
- print("Cleaned summary:", cleaned_summary,type(cleaned_summary)) # Debugging line
188
- sf.Lead.update(user_id,{'Description': cleaned_summary})
189
- return {"summary": cleaned_summary, "message": "Chat history saved"}
190
- else:
191
- return JSONResponse(status_code=400, content={"message": "Invalid history format"})
 
 
 
192
  @app.post("/webhook")
193
  async def receive_form_data(request: Request):
194
  form_data = await request.json()
 
27
  model=repo_id,
28
  token=os.getenv("HF_TOKEN"),
29
  )
30
+ client = Client("Qwen/Qwen2.5-72B-Instruct")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN")
32
  username = os.getenv("username")
33
  password = os.getenv("password")
 
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
+ query=hist,
171
+ history=[],
172
+ system="You are clara, created by redferntech. You are a helpful assistant.",
173
+ api_name="/predict"
174
+ )
175
+ sf.Lead.update(user_id,{'Description': result})
176
+ return {"summary": result, "message": "Chat history saved"}
177
  @app.post("/webhook")
178
  async def receive_form_data(request: Request):
179
  form_data = await request.json()