mozzic commited on
Commit
7d94266
·
verified ·
1 Parent(s): a4eccb6

Upload src\intent.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src//intent.py +52 -0
src//intent.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Intent inference for notebook cells
3
+ """
4
+
5
+ from typing import List, Optional
6
+ import re
7
+ from src.models import ContextUnit, CellType
8
+
9
+
10
+ class ContextThreadEnricher:
11
+ """Enriches context threads with intent information."""
12
+
13
+ def __init__(self, infer_intents: bool = True):
14
+ self.infer_intents = infer_intents
15
+
16
+ def enrich(self, thread):
17
+ """Enrich the thread with intents."""
18
+ if not self.infer_intents:
19
+ return thread
20
+
21
+ for unit in thread.units:
22
+ if unit.intent == "[Pending intent inference]":
23
+ unit.intent = self._infer_intent_heuristic(unit)
24
+
25
+ return thread
26
+
27
+ def _infer_intent_heuristic(self, unit: ContextUnit) -> str:
28
+ """Infer intent using heuristics."""
29
+ source = unit.cell.source.lower()
30
+
31
+ # Data loading
32
+ if any(keyword in source for keyword in ['read_csv', 'read_excel', 'load', 'open']):
33
+ return "Load data from file"
34
+
35
+ # Data cleaning
36
+ if any(keyword in source for keyword in ['dropna', 'fillna', 'clean', 'remove', 'filter']):
37
+ return "Clean and preprocess data"
38
+
39
+ # Analysis/Modeling
40
+ if any(keyword in source for keyword in ['fit', 'predict', 'train', 'model', 'regression']):
41
+ return "Build and train model"
42
+
43
+ # Visualization
44
+ if any(keyword in source for keyword in ['plot', 'chart', 'graph', 'visualize', 'show']):
45
+ return "Create visualization"
46
+
47
+ # Statistics
48
+ if any(keyword in source for keyword in ['mean', 'std', 'sum', 'count', 'describe']):
49
+ return "Compute statistics"
50
+
51
+ # Default
52
+ return "Execute code"