Download orchestrator/interaction_parser.py from luoleyuan/XHS: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/spaces/luoleyuan/XHS/resolve/main/orchestrator/interaction_parser.py
- Command line
-
hf download hf://spaces/luoleyuan/XHS/orchestrator/interaction_parser.py
-
curl -L -o interaction_parser.py https://huggingface.co/spaces/luoleyuan/XHS/resolve/main/orchestrator/interaction_parser.py
2.72 kB
| import sqlite3 | |
| import os | |
| import sys | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from orchestrator.config import DB_PATH | |
| def get_intent_score(content): | |
| """ | |
| Mock AI intent scoring for interactions. | |
| Returns: | |
| intent_type (str): "pricing", "appointment", "contact", "other" | |
| intent_score (int): 0-100 | |
| is_high_intent (int): 1 if high intent, 0 otherwise | |
| """ | |
| if not content: | |
| return "other", 0, 0 | |
| high_intent_keywords = ["收费", "怎么卖", "联系方式", "微信", "电话", "私信", "预约"] | |
| medium_intent_keywords = ["效果", "了解", "怎么做"] | |
| score = 0 | |
| intent_type = "other" | |
| for kw in high_intent_keywords: | |
| if kw in content: | |
| score += 50 | |
| if "收费" in kw or "怎么卖" in kw: | |
| intent_type = "pricing" | |
| elif "预约" in kw: | |
| intent_type = "appointment" | |
| else: | |
| intent_type = "contact" | |
| for kw in medium_intent_keywords: | |
| if kw in content: | |
| score += 20 | |
| score = min(100, score) | |
| is_high = 1 if score >= 50 else 0 | |
| return intent_type, score, is_high | |
| def main(): | |
| conn = sqlite3.connect(DB_PATH) | |
| cursor = conn.cursor() | |
| # Add necessary columns to interaction_record | |
| try: | |
| cursor.execute("ALTER TABLE interaction_record ADD COLUMN intent_type TEXT;") | |
| cursor.execute("ALTER TABLE interaction_record ADD COLUMN intent_score INTEGER DEFAULT 0;") | |
| cursor.execute("ALTER TABLE interaction_record ADD COLUMN is_high_intent INTEGER DEFAULT 0;") | |
| cursor.execute("ALTER TABLE interaction_record ADD COLUMN processed INTEGER DEFAULT 0;") | |
| conn.commit() | |
| except sqlite3.OperationalError: | |
| pass | |
| cursor.execute("SELECT id, content FROM interaction_record WHERE processed = 0") | |
| unprocessed_interactions = cursor.fetchall() | |
| if not unprocessed_interactions: | |
| print("No unprocessed interactions found.") | |
| conn.close() | |
| return | |
| parsed_count = 0 | |
| for interaction_id, content in unprocessed_interactions: | |
| intent_type, intent_score, is_high_intent = get_intent_score(content) | |
| cursor.execute(""" | |
| UPDATE interaction_record | |
| SET intent_type = ?, intent_score = ?, is_high_intent = ?, processed = 1 | |
| WHERE id = ? | |
| """, (intent_type, intent_score, is_high_intent, interaction_id)) | |
| parsed_count += 1 | |
| conn.commit() | |
| print(f"Successfully parsed {parsed_count} interactions.") | |
| conn.close() | |
| if __name__ == "__main__": | |
| main() | |