Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -256,11 +256,11 @@ class MessageRequest(BaseModel):
|
|
256 |
message: str
|
257 |
|
258 |
# Environment variables for Salesforce
|
259 |
-
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN") # Optional: Needed for model download if gated
|
260 |
username = os.getenv("username")
|
261 |
password = os.getenv("password")
|
262 |
security_token = os.getenv("security_token")
|
263 |
-
domain = os.getenv("domain") #
|
264 |
session_id, sf_instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
|
265 |
|
266 |
# Create Salesforce object
|
@@ -368,10 +368,10 @@ def handle_query(query):
|
|
368 |
|
369 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
370 |
index = load_index_from_storage(storage_context)
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
|
376 |
logger.info(f"Query: {query}")
|
377 |
logger.info(f"Context: {context_str}")
|
@@ -411,16 +411,13 @@ async def save_chat_history(history: dict):
|
|
411 |
hist = "You are a Redfernstech summarize model. Your aim is to use this conversation to identify user interests solely based on that conversation: " + hist
|
412 |
logger.info(f"Chat history: {hist}")
|
413 |
|
414 |
-
# Get the summarized result
|
415 |
-
result = hist
|
416 |
-
|
417 |
try:
|
418 |
-
sf.Lead.update(user_id, {"Description":
|
419 |
except Exception as e:
|
420 |
logger.error(f"Failed to update lead: {str(e)}")
|
421 |
return {"error": f"Failed to update lead: {str(e)}"}, 500
|
422 |
|
423 |
-
return {"summary":
|
424 |
|
425 |
@app.post("/webhook")
|
426 |
async def receive_form_data(request: Request):
|
@@ -430,8 +427,8 @@ async def receive_form_data(request: Request):
|
|
430 |
data = {
|
431 |
"FirstName": first_name,
|
432 |
"LastName": last_name,
|
433 |
-
"Description": "
|
434 |
-
"Company": form_data
|
435 |
"Phone": form_data["phone"].strip(), # Phone from form data
|
436 |
"Email": form_data["email"], # Email from form data
|
437 |
}
|
|
|
256 |
message: str
|
257 |
|
258 |
# Environment variables for Salesforce
|
259 |
+
os.environ["HF_TOKEN"] = os.getenv("HF_TOKEN", "") # Optional: Needed for model download if gated
|
260 |
username = os.getenv("username")
|
261 |
password = os.getenv("password")
|
262 |
security_token = os.getenv("security_token")
|
263 |
+
domain = os.getenv("domain", "test") # Default to sandbox environment
|
264 |
session_id, sf_instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
|
265 |
|
266 |
# Create Salesforce object
|
|
|
368 |
|
369 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
370 |
index = load_index_from_storage(storage_context)
|
371 |
+
|
372 |
+
# Build context from chat history
|
373 |
+
context_str = "\n".join([f"User asked: '{past_query}'\nBot answered: '{response}'"
|
374 |
+
for past_query, response in reversed(current_chat_history)])
|
375 |
|
376 |
logger.info(f"Query: {query}")
|
377 |
logger.info(f"Context: {context_str}")
|
|
|
411 |
hist = "You are a Redfernstech summarize model. Your aim is to use this conversation to identify user interests solely based on that conversation: " + hist
|
412 |
logger.info(f"Chat history: {hist}")
|
413 |
|
|
|
|
|
|
|
414 |
try:
|
415 |
+
sf.Lead.update(user_id, {"Description": hist})
|
416 |
except Exception as e:
|
417 |
logger.error(f"Failed to update lead: {str(e)}")
|
418 |
return {"error": f"Failed to update lead: {str(e)}"}, 500
|
419 |
|
420 |
+
return {"summary": hist, "message": "Chat history saved"}
|
421 |
|
422 |
@app.post("/webhook")
|
423 |
async def receive_form_data(request: Request):
|
|
|
427 |
data = {
|
428 |
"FirstName": first_name,
|
429 |
"LastName": last_name,
|
430 |
+
"Description": f"New lead created via webhook: {form_data['name']}",
|
431 |
+
"Company": form_data.get("company", ""), # Assuming company might be optional
|
432 |
"Phone": form_data["phone"].strip(), # Phone from form data
|
433 |
"Email": form_data["email"], # Email from form data
|
434 |
}
|