Repository navigation
Expand file tree
/
Copy pathintent_parser.py
More file actions
106 lines (87 loc) · 3.84 KB
/
Copy pathintent_parser.py
File metadata and controls
106 lines (87 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from typing import List, Dict, Tuple
import re
class IntentParser:
"""Parse user prompts to extract intent, roles, and constraints."""
ROLE_KEYWORDS = {
"backend": ["backend", "server", "api", "devops"],
"frontend": ["frontend", "ui", "ux", "web"],
"full-stack": ["full-stack", "full stack", "fullstack"],
"web": ["web", "web dev", "web development"],
"ai": ["ai", "artificial intelligence", "llm"],
"ml": ["ml", "machine learning", "models"],
}
COMPANY_TYPE_KEYWORDS = {
"startup": ["startup", "startups", "early stage"],
"tech": ["tech", "technology", "saas"],
"any": ["company", "companies"],
}
def parse_intent(self, user_prompt: str) -> Dict[str, any]:
"""
Parse user prompt to extract:
- Target roles
- Company type
- Location (if specified)
- Any other constraints
Returns:
Dictionary with parsed intent
"""
prompt_lower = user_prompt.lower()
# Extract target roles
target_roles = self._extract_roles(prompt_lower)
# Extract company type
company_type = self._extract_company_type(prompt_lower)
# Extract location if mentioned
location = self._extract_location(prompt_lower)
# Determine if it's an outreach campaign
is_outreach = self._is_outreach_intent(prompt_lower)
return {
"original_prompt": user_prompt,
"target_roles": target_roles,
"company_type": company_type,
"location": location,
"is_outreach": is_outreach,
"confidence": self._calculate_confidence(target_roles, company_type)
}
def _extract_roles(self, prompt: str) -> List[str]:
"""Extract target roles from prompt."""
found_roles = []
for role, keywords in self.ROLE_KEYWORDS.items():
for keyword in keywords:
if keyword in prompt:
if role not in found_roles:
found_roles.append(role)
break
return found_roles if found_roles else ["full-stack"]
def _extract_company_type(self, prompt: str) -> str:
"""Extract company type preference."""
for comp_type, keywords in self.COMPANY_TYPE_KEYWORDS.items():
for keyword in keywords:
if keyword in prompt:
return comp_type
return "startup"
def _extract_location(self, prompt: str) -> str:
"""Extract location if mentioned."""
location_pattern = r'(san francisco|sf|nyc|new york|london|toronto|remote|anywhere)'
match = re.search(location_pattern, prompt)
return match.group(1) if match else "remote"
def _is_outreach_intent(self, prompt: str) -> bool:
"""Determine if prompt is requesting outreach emails."""
outreach_keywords = ["outreach", "email", "cold email", "reach out", "contact", "message"]
return any(keyword in prompt for keyword in outreach_keywords)
def _calculate_confidence(self, roles: List[str], company_type: str) -> float:
"""Calculate confidence score of intent parsing."""
score = 0.5 # Base score
score += min(len(roles) * 0.2, 0.3) # More roles = higher confidence
score += 0.2 if company_type != "startup" else 0 # Type specification helps
return min(score, 1.0)
def format_intent_summary(self, intent: Dict) -> str:
"""Format intent into readable summary."""
roles = ", ".join(intent["target_roles"])
return f"""
Intent Analysis:
- Target Roles: {roles}
- Company Type: {intent["company_type"]}
- Location: {intent["location"]}
- Is Outreach Campaign: {intent["is_outreach"]}
- Confidence: {intent["confidence"]:.0%}
"""