Spaces:
Runtime error
Runtime error
Commit
·
f1184dc
1
Parent(s):
1741647
Add application files
Browse files
app.py
CHANGED
|
@@ -864,19 +864,32 @@ IMPORTANT: You MUST use the tools to save data. Follow these steps for EACH pros
|
|
| 864 |
- metadata: {{"summary": "company description", "industry": "their industry", "fit_reason": "why they're a good fit"}}
|
| 865 |
|
| 866 |
b. Use save_contact tool for 2-3 decision makers with:
|
| 867 |
-
- contact_id: unique ID
|
| 868 |
-
- company_id: same as above
|
| 869 |
-
-
|
|
|
|
| 870 |
- first_name: their first name
|
| 871 |
- last_name: their last name
|
| 872 |
-
- title: their job title (CEO, VP Sales, CTO, etc.)
|
| 873 |
-
|
| 874 |
-
c. Use send_email tool to draft outreach:
|
| 875 |
-
- to: the contact email
|
| 876 |
-
- subject:
|
| 877 |
-
- body: personalized email
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
- prospect_id: the prospect_id from step a
|
| 879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
Focus on finding companies that:
|
| 881 |
- Would benefit from {client_name}'s products/services
|
| 882 |
- Are in industries that match {client_name}'s target market
|
|
@@ -943,9 +956,13 @@ After processing all {num_prospects} prospects, provide a brief summary of what
|
|
| 943 |
else:
|
| 944 |
name = tool_input.get("name", "Unknown")
|
| 945 |
title = tool_input.get("title", "")
|
| 946 |
-
# Get company
|
| 947 |
-
|
| 948 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
# Capture contact data during tool_call
|
| 950 |
pending_contact = {
|
| 951 |
"name": name,
|
|
@@ -1269,7 +1286,7 @@ Complete the user's request and provide a helpful response."""
|
|
| 1269 |
|
| 1270 |
|
| 1271 |
def chat_with_ai(message: str, history: list, hf_token: str = "") -> tuple:
|
| 1272 |
-
"""Chat function -
|
| 1273 |
if not knowledge_base["client"]["name"]:
|
| 1274 |
return history + [[message, "⚠️ Please complete Setup first."]], ""
|
| 1275 |
|
|
@@ -1279,38 +1296,109 @@ def chat_with_ai(message: str, history: list, hf_token: str = "") -> tuple:
|
|
| 1279 |
client_name = knowledge_base["client"]["name"]
|
| 1280 |
msg_lower = message.lower()
|
| 1281 |
|
| 1282 |
-
# Check
|
| 1283 |
-
|
| 1284 |
-
|
| 1285 |
-
|
| 1286 |
-
|
| 1287 |
-
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
-
|
| 1297 |
-
|
| 1298 |
-
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
**
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
-
|
| 1312 |
-
|
| 1313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1314 |
"""
|
| 1315 |
return history + [[message, response]], ""
|
| 1316 |
|
|
|
|
| 864 |
- metadata: {{"summary": "company description", "industry": "their industry", "fit_reason": "why they're a good fit"}}
|
| 865 |
|
| 866 |
b. Use save_contact tool for 2-3 decision makers with:
|
| 867 |
+
- contact_id: unique ID like "contact_1"
|
| 868 |
+
- company_id: same company_id as above
|
| 869 |
+
- company_name: THE ACTUAL COMPANY NAME (e.g., "Acme Corp", NOT "company_1")
|
| 870 |
+
- email: their email using format "[email protected]"
|
| 871 |
- first_name: their first name
|
| 872 |
- last_name: their last name
|
| 873 |
+
- title: their job title (CEO, VP Sales, CTO, Marketing Director, etc.)
|
| 874 |
+
|
| 875 |
+
c. Use send_email tool to draft a PERSONALIZED outreach email:
|
| 876 |
+
- to: the contact email (use format: [email protected])
|
| 877 |
+
- subject: Compelling subject mentioning BOTH {client_name} and the prospect company name
|
| 878 |
+
- body: A personalized email that includes:
|
| 879 |
+
* Greeting using the contact's first name
|
| 880 |
+
* Specific reference to the prospect company's business/recent news
|
| 881 |
+
* Clear explanation of how {client_name} can help THIS specific company
|
| 882 |
+
* Mention their industry and specific challenges they face
|
| 883 |
+
* A concrete call-to-action (demo, call, meeting)
|
| 884 |
+
* Professional sign-off
|
| 885 |
- prospect_id: the prospect_id from step a
|
| 886 |
|
| 887 |
+
IMPORTANT EMAIL GUIDELINES:
|
| 888 |
+
- DO NOT write generic emails. Each email must be specific to the prospect.
|
| 889 |
+
- Reference the prospect's actual business, industry, or recent activities
|
| 890 |
+
- Explain why {client_name} is relevant to THEIR specific situation
|
| 891 |
+
- Keep emails concise (3-4 paragraphs max)
|
| 892 |
+
|
| 893 |
Focus on finding companies that:
|
| 894 |
- Would benefit from {client_name}'s products/services
|
| 895 |
- Are in industries that match {client_name}'s target market
|
|
|
|
| 956 |
else:
|
| 957 |
name = tool_input.get("name", "Unknown")
|
| 958 |
title = tool_input.get("title", "")
|
| 959 |
+
# Get company name - prioritize actual name over ID
|
| 960 |
+
# current_prospect_name has the actual name, company_id is just an identifier
|
| 961 |
+
company = tool_input.get("company_name") or current_prospect_name or "Unknown"
|
| 962 |
+
# If company still looks like an ID (company_1, etc.), use current_prospect_name
|
| 963 |
+
if company.startswith("company_") or company.startswith("prospect_"):
|
| 964 |
+
company = current_prospect_name or company
|
| 965 |
+
output += f"👤 Found contact: {name} ({title}) at {company}\n"
|
| 966 |
# Capture contact data during tool_call
|
| 967 |
pending_contact = {
|
| 968 |
"name": name,
|
|
|
|
| 1286 |
|
| 1287 |
|
| 1288 |
def chat_with_ai(message: str, history: list, hf_token: str = "") -> tuple:
|
| 1289 |
+
"""Chat function - handles queries using local data and templates"""
|
| 1290 |
if not knowledge_base["client"]["name"]:
|
| 1291 |
return history + [[message, "⚠️ Please complete Setup first."]], ""
|
| 1292 |
|
|
|
|
| 1296 |
client_name = knowledge_base["client"]["name"]
|
| 1297 |
msg_lower = message.lower()
|
| 1298 |
|
| 1299 |
+
# Check for specific prospect mention
|
| 1300 |
+
mentioned_prospect = None
|
| 1301 |
+
for p in knowledge_base["prospects"]:
|
| 1302 |
+
if p.get("name", "").lower() in msg_lower:
|
| 1303 |
+
mentioned_prospect = p
|
| 1304 |
+
break
|
| 1305 |
+
|
| 1306 |
+
# Handle "find decision makers" / "find contacts" for a known prospect
|
| 1307 |
+
if any(kw in msg_lower for kw in ["find decision", "find contact", "who works at", "contacts at"]):
|
| 1308 |
+
if mentioned_prospect:
|
| 1309 |
+
p_name = mentioned_prospect["name"]
|
| 1310 |
+
p_name_lower = p_name.lower()
|
| 1311 |
+
contacts = [c for c in knowledge_base["contacts"]
|
| 1312 |
+
if p_name_lower in c.get("company", "").lower()
|
| 1313 |
+
or c.get("company", "").lower() in p_name_lower]
|
| 1314 |
+
|
| 1315 |
+
if contacts:
|
| 1316 |
+
response = f"## 👥 Decision Makers at {p_name}\n\n"
|
| 1317 |
+
for c in contacts:
|
| 1318 |
+
response += f"**{c.get('name', 'Unknown')}** - {c.get('title', 'Unknown')}\n"
|
| 1319 |
+
response += f" - Email: {c.get('email', 'Not available')}\n"
|
| 1320 |
+
response += f" - Company: {c.get('company', p_name)}\n\n"
|
| 1321 |
+
else:
|
| 1322 |
+
response = f"No contacts found yet for **{p_name}**.\n\n"
|
| 1323 |
+
response += "To find contacts, go to **Prospects Tab** and run **Find Prospects** again."
|
| 1324 |
+
return history + [[message, response]], ""
|
| 1325 |
+
|
| 1326 |
+
# Handle "draft email" for a known prospect
|
| 1327 |
+
if any(kw in msg_lower for kw in ["draft", "write", "compose", "email to", "create email"]):
|
| 1328 |
+
if mentioned_prospect:
|
| 1329 |
+
p_name = mentioned_prospect["name"]
|
| 1330 |
+
p_name_lower = p_name.lower()
|
| 1331 |
+
|
| 1332 |
+
# Check if we already have an email for this prospect
|
| 1333 |
+
existing_emails = [e for e in knowledge_base["emails"]
|
| 1334 |
+
if p_name_lower in e.get("prospect_company", "").lower()]
|
| 1335 |
+
|
| 1336 |
+
if existing_emails:
|
| 1337 |
+
email = existing_emails[0]
|
| 1338 |
+
response = f"## ✉️ Existing Email Draft for {p_name}\n\n"
|
| 1339 |
+
response += f"**To:** {email.get('to', 'N/A')}\n"
|
| 1340 |
+
response += f"**Subject:** {email.get('subject', 'N/A')}\n\n"
|
| 1341 |
+
response += f"---\n\n{email.get('body', 'No content')}\n\n"
|
| 1342 |
+
response += "---\n\n*This email was drafted during prospect discovery.*"
|
| 1343 |
+
else:
|
| 1344 |
+
# Generate a template based on prospect info
|
| 1345 |
+
contacts = [c for c in knowledge_base["contacts"]
|
| 1346 |
+
if p_name_lower in c.get("company", "").lower()]
|
| 1347 |
+
contact = contacts[0] if contacts else None
|
| 1348 |
+
|
| 1349 |
+
to_email = contact.get("email", "contact@" + p_name.lower().replace(" ", "") + ".com") if contact else f"contact@{p_name.lower().replace(' ', '')}.com"
|
| 1350 |
+
contact_name = contact.get("name", "there").split()[0] if contact else "there"
|
| 1351 |
+
|
| 1352 |
+
response = f"## ✉️ Email Template for {p_name}\n\n"
|
| 1353 |
+
response += f"**To:** {to_email}\n"
|
| 1354 |
+
response += f"**Subject:** {client_name} + {p_name}: A Potential Partnership\n\n"
|
| 1355 |
+
response += f"---\n\n"
|
| 1356 |
+
response += f"Dear {contact_name},\n\n"
|
| 1357 |
+
response += f"I came across {p_name} and was impressed by your work in {mentioned_prospect.get('industry', 'your industry')}.\n\n"
|
| 1358 |
+
response += f"{mentioned_prospect.get('summary', '')}\n\n"
|
| 1359 |
+
response += f"At {client_name}, we help companies like yours {mentioned_prospect.get('fit_reason', 'grow their business')}.\n\n"
|
| 1360 |
+
response += f"Would you be open to a brief call to explore how we might work together?\n\n"
|
| 1361 |
+
response += f"Best regards,\n[Your Name]\n{client_name}\n\n"
|
| 1362 |
+
response += "---\n\n*This is a template. Customize it before sending.*"
|
| 1363 |
+
|
| 1364 |
+
return history + [[message, response]], ""
|
| 1365 |
+
|
| 1366 |
+
# Handle "suggest talking points" for a prospect
|
| 1367 |
+
if any(kw in msg_lower for kw in ["talking point", "suggest", "recommend", "strategy"]):
|
| 1368 |
+
if mentioned_prospect:
|
| 1369 |
+
p_name = mentioned_prospect["name"]
|
| 1370 |
+
response = f"## 💡 Talking Points for {p_name}\n\n"
|
| 1371 |
+
response += f"**About {p_name}:**\n"
|
| 1372 |
+
response += f"- Industry: {mentioned_prospect.get('industry', 'Unknown')}\n"
|
| 1373 |
+
response += f"- {mentioned_prospect.get('summary', 'No summary available')}\n\n"
|
| 1374 |
+
response += f"**Why they're a fit for {client_name}:**\n"
|
| 1375 |
+
response += f"- {mentioned_prospect.get('fit_reason', 'Matches target customer profile')}\n\n"
|
| 1376 |
+
response += f"**Suggested talking points:**\n"
|
| 1377 |
+
response += f"1. Reference their focus on {mentioned_prospect.get('industry', 'their industry')}\n"
|
| 1378 |
+
response += f"2. Highlight how {client_name} can help with scalability\n"
|
| 1379 |
+
response += f"3. Mention success stories from similar companies\n"
|
| 1380 |
+
response += f"4. Propose a specific next step (demo, call, pilot)\n"
|
| 1381 |
+
return history + [[message, response]], ""
|
| 1382 |
+
|
| 1383 |
+
# For generic "search" or "research" - guide to prospects tab
|
| 1384 |
+
if any(kw in msg_lower for kw in ["search for", "research", "find new", "discover", "look up"]):
|
| 1385 |
+
response = f"""🔍 **Research Request**
|
| 1386 |
+
|
| 1387 |
+
To search for new companies or research prospects, please use the **Prospects Tab**:
|
| 1388 |
+
|
| 1389 |
+
1. Go to **Prospects** tab
|
| 1390 |
+
2. Enter the number of prospects to find
|
| 1391 |
+
3. Click **"Find Prospects & Contacts"**
|
| 1392 |
+
|
| 1393 |
+
The AI will:
|
| 1394 |
+
- Search for companies matching {client_name}'s target market
|
| 1395 |
+
- Find decision makers at each company
|
| 1396 |
+
- Draft personalized outreach emails
|
| 1397 |
+
|
| 1398 |
+
**Currently in your pipeline:**
|
| 1399 |
+
- Prospects: {len(knowledge_base['prospects'])}
|
| 1400 |
+
- Contacts: {len(knowledge_base['contacts'])}
|
| 1401 |
+
- Emails: {len(knowledge_base['emails'])}
|
| 1402 |
"""
|
| 1403 |
return history + [[message, response]], ""
|
| 1404 |
|