File size: 2,724 Bytes
c481f8a | 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 | 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()
|