Spaces:
Sleeping
Sleeping
Commit
Β·
e3fee32
1
Parent(s):
9d6015f
Update services/intent_classifier.py
Browse files- services/intent_classifier.py +67 -14
services/intent_classifier.py
CHANGED
|
@@ -86,7 +86,7 @@ class IntentClassifier:
|
|
| 86 |
"suggested_response_type": "friendly"
|
| 87 |
}
|
| 88 |
|
| 89 |
-
# Question patterns (informational)
|
| 90 |
is_question = False
|
| 91 |
for pattern in IntentClassifier.QUESTION_PATTERNS:
|
| 92 |
if re.search(pattern, message, re.IGNORECASE):
|
|
@@ -99,7 +99,37 @@ class IntentClassifier:
|
|
| 99 |
if keyword in message
|
| 100 |
)
|
| 101 |
|
| 102 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
if pipeline_keyword_count > 0:
|
| 104 |
return {
|
| 105 |
"intent": "pipeline_request",
|
|
@@ -109,15 +139,6 @@ class IntentClassifier:
|
|
| 109 |
"keyword_matches": pipeline_keyword_count
|
| 110 |
}
|
| 111 |
|
| 112 |
-
# Questions without pipeline keywords
|
| 113 |
-
if is_question:
|
| 114 |
-
return {
|
| 115 |
-
"intent": "question",
|
| 116 |
-
"confidence": 0.8,
|
| 117 |
-
"requires_pipeline": False,
|
| 118 |
-
"suggested_response_type": "informational"
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
# Default: treat as casual if short, otherwise might be pipeline request
|
| 122 |
if len(message.split()) < 3:
|
| 123 |
return {
|
|
@@ -183,9 +204,41 @@ class IntentClassifier:
|
|
| 183 |
3. I'll create a pipeline for you to approve
|
| 184 |
4. Watch the magic happen! β¨"""
|
| 185 |
|
| 186 |
-
# Who are you
|
| 187 |
-
if "who are you"
|
| 188 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
# Help
|
| 191 |
if message_lower in ["help", "?"] or "help me" in message_lower:
|
|
|
|
| 86 |
"suggested_response_type": "friendly"
|
| 87 |
}
|
| 88 |
|
| 89 |
+
# Question patterns (informational) - CHECK THIS FIRST!
|
| 90 |
is_question = False
|
| 91 |
for pattern in IntentClassifier.QUESTION_PATTERNS:
|
| 92 |
if re.search(pattern, message, re.IGNORECASE):
|
|
|
|
| 99 |
if keyword in message
|
| 100 |
)
|
| 101 |
|
| 102 |
+
# IMPORTANT: Questions take priority over pipeline keywords!
|
| 103 |
+
# "tell me about X" is a question, not a pipeline request
|
| 104 |
+
if is_question:
|
| 105 |
+
# If it's clearly asking about the system itself, it's informational
|
| 106 |
+
if any(term in message for term in ["masterllm", "you", "this", "system", "bot", "chatbot", "assistant"]):
|
| 107 |
+
return {
|
| 108 |
+
"intent": "question",
|
| 109 |
+
"confidence": 0.95,
|
| 110 |
+
"requires_pipeline": False,
|
| 111 |
+
"suggested_response_type": "informational"
|
| 112 |
+
}
|
| 113 |
+
# If it's a question but with strong pipeline keywords, could be pipeline request
|
| 114 |
+
# But only if the keywords are very explicit (e.g., "extract text from page 5")
|
| 115 |
+
elif pipeline_keyword_count >= 2 and not message.startswith("tell me"):
|
| 116 |
+
return {
|
| 117 |
+
"intent": "pipeline_request",
|
| 118 |
+
"confidence": 0.7,
|
| 119 |
+
"requires_pipeline": True,
|
| 120 |
+
"suggested_response_type": "pipeline_generation",
|
| 121 |
+
"keyword_matches": pipeline_keyword_count
|
| 122 |
+
}
|
| 123 |
+
# Otherwise, it's just a question
|
| 124 |
+
else:
|
| 125 |
+
return {
|
| 126 |
+
"intent": "question",
|
| 127 |
+
"confidence": 0.85,
|
| 128 |
+
"requires_pipeline": False,
|
| 129 |
+
"suggested_response_type": "informational"
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
# If has pipeline keywords but is NOT a question, then pipeline request
|
| 133 |
if pipeline_keyword_count > 0:
|
| 134 |
return {
|
| 135 |
"intent": "pipeline_request",
|
|
|
|
| 139 |
"keyword_matches": pipeline_keyword_count
|
| 140 |
}
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# Default: treat as casual if short, otherwise might be pipeline request
|
| 143 |
if len(message.split()) < 3:
|
| 144 |
return {
|
|
|
|
| 204 |
3. I'll create a pipeline for you to approve
|
| 205 |
4. Watch the magic happen! β¨"""
|
| 206 |
|
| 207 |
+
# Who are you / What are you / Tell me about MasterLLM
|
| 208 |
+
if any(phrase in message_lower for phrase in ["who are you", "what are you", "about masterllm", "about you", "tell me about"]):
|
| 209 |
+
return """**About MasterLLM** π€
|
| 210 |
+
|
| 211 |
+
I'm MasterLLM, an intelligent AI-powered document processing orchestrator that helps you automate complex document workflows.
|
| 212 |
+
|
| 213 |
+
**What I Do:**
|
| 214 |
+
- π **Analyze** your requests and understand what you need
|
| 215 |
+
- π οΈ **Create** custom processing pipelines automatically
|
| 216 |
+
- β‘ **Execute** multi-step document workflows
|
| 217 |
+
- π **Deliver** structured results
|
| 218 |
+
|
| 219 |
+
**My Capabilities:**
|
| 220 |
+
- Extract text from PDFs and images (OCR)
|
| 221 |
+
- Summarize long documents
|
| 222 |
+
- Translate content to different languages
|
| 223 |
+
- Classify documents
|
| 224 |
+
- Extract tables and structured data
|
| 225 |
+
- Detect signatures and stamps
|
| 226 |
+
- Describe images
|
| 227 |
+
- Extract named entities (people, places, organizations)
|
| 228 |
+
|
| 229 |
+
**How I'm Different:**
|
| 230 |
+
I'm not just a single tool - I'm a **smart orchestrator** that:
|
| 231 |
+
1. Understands your natural language requests
|
| 232 |
+
2. Determines the best sequence of operations
|
| 233 |
+
3. Uses powerful AI models (AWS Bedrock Claude & Google Gemini)
|
| 234 |
+
4. Combines multiple tools into efficient pipelines
|
| 235 |
+
5. Executes everything seamlessly
|
| 236 |
+
|
| 237 |
+
**My Role:**
|
| 238 |
+
Think of me as your AI assistant for document processing. I have a natural conversation with you, understand what you need, propose a plan, and execute it - all while keeping you informed every step of the way!
|
| 239 |
+
|
| 240 |
+
Want to see me in action? Just upload a document and tell me what you'd like to do with it! π"""
|
| 241 |
+
|
| 242 |
|
| 243 |
# Help
|
| 244 |
if message_lower in ["help", "?"] or "help me" in message_lower:
|