samurai9776 commited on
Commit
3d6d1fc
·
verified ·
1 Parent(s): 4233284

Upload pipeline.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pipeline.py +19 -24
pipeline.py CHANGED
@@ -18,7 +18,8 @@ class ThoughtCompletionPipeline(Pipeline):
18
  def ends_with_incomplete_word(self, text):
19
  """Check if text ends with words that indicate incomplete thought"""
20
  text = text.strip().lower()
21
- text = re.sub(r'[.,!?;]$', '', text)
 
22
  words = text.split()
23
 
24
  if not words:
@@ -36,35 +37,29 @@ class ThoughtCompletionPipeline(Pipeline):
36
 
37
  ai_utterance = parts[0].strip()
38
  cx_utterance = parts[1].strip()
 
39
 
40
- # Check if customer utterance ends with incomplete word
41
- if self.ends_with_incomplete_word(cx_utterance):
42
- return [{'label': 'INCOMPLETE', 'score': 0.95}], 'rule:incomplete_ending'
43
-
44
- cx_lower = cx_utterance.lower()
45
 
46
- # Complete thought indicators
47
- complete_phrases = [
48
- "that's all", "nothing else", "i'm done", "that's it",
49
- "no thanks", "no thank you", "yes", "yes please",
50
- "perfect", "great", "sounds good", "that's everything"
 
 
51
  ]
52
 
53
- for phrase in complete_phrases:
54
- if phrase in cx_lower:
55
- return [{'label': 'COMPLETE', 'score': 0.95}], f'rule:contains_{phrase}'
56
 
57
- # Incomplete thought indicators
58
- incomplete_phrases = [
59
- "let me add", "actually", "wait", "i also need",
60
- "can i get", "i want", "i'd like", "i need",
61
- "hold on", "one more", "oh and"
62
- ]
63
-
64
- for phrase in incomplete_phrases:
65
- if phrase in cx_lower:
66
- return [{'label': 'INCOMPLETE', 'score': 0.95}], f'rule:contains_{phrase}'
67
 
 
68
  return None, None
69
 
70
  def preprocess(self, inputs):
 
18
  def ends_with_incomplete_word(self, text):
19
  """Check if text ends with words that indicate incomplete thought"""
20
  text = text.strip().lower()
21
+ # Remove trailing punctuation
22
+ text = re.sub(r'[.,!?;:]$', '', text)
23
  words = text.split()
24
 
25
  if not words:
 
37
 
38
  ai_utterance = parts[0].strip()
39
  cx_utterance = parts[1].strip()
40
+ cx_lower = cx_utterance.lower().strip()
41
 
42
+ # Remove punctuation for exact matching
43
+ cx_lower_clean = re.sub(r'[.,!?;:]$', '', cx_lower)
 
 
 
44
 
45
+ # RULE 1: Check for EXACT MATCH complete thoughts (full sentence match)
46
+ complete_full_sentences = [
47
+ "that's all", "that's it", "nothing else", "i'm done", "i'm good",
48
+ "no thanks", "no thank you", "yes please", "yes", "no",
49
+ "perfect", "great", "sounds good", "that's everything",
50
+ "all set", "done", "finished", "that is all", "that is it",
51
+ "nope", "yep", "yeah"
52
  ]
53
 
54
+ for phrase in complete_full_sentences:
55
+ if cx_lower_clean == phrase: # EXACT MATCH ONLY
56
+ return [{'label': 'COMPLETE', 'score': 0.95}], f'rule:exact_match_{phrase.replace(" ", "_")}'
57
 
58
+ # RULE 2: Check if sentence ENDS with incomplete word
59
+ if self.ends_with_incomplete_word(cx_utterance):
60
+ return [{'label': 'INCOMPLETE', 'score': 0.95}], 'rule:ends_with_incomplete_word'
 
 
 
 
 
 
 
61
 
62
+ # No rule applies - use the neural model
63
  return None, None
64
 
65
  def preprocess(self, inputs):