File size: 716 Bytes
d74ce48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import subprocess
import sys
from database import save_conversation as _db_save, get_conversation_count

RETRAIN_EVERY = 5  # auto-retrain SunAI every N conversations


def save_conversation(user_input, bot_reply, intent="casual", tone="casual"):
    _db_save(user_input, bot_reply, intent, tone)
    _maybe_retrain()


def _maybe_retrain():
    count = get_conversation_count()
    if count % RETRAIN_EVERY == 0:
        print(f"\n[SunAI] {count} conversations reached — retraining in background...\n")
        subprocess.Popen(
            [sys.executable, "sunai.py"],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            creationflags=subprocess.CREATE_NO_WINDOW
        )