34 lines
923 B
Python
Executable File
34 lines
923 B
Python
Executable File
import json
|
|
import os
|
|
import datetime
|
|
|
|
MEMORY_FILE = "/opt/wevads/data/ai_memory.json"
|
|
|
|
def record_chat(user_input, ai_response):
|
|
timestamp = datetime.datetime.now().isoformat()
|
|
entry = {
|
|
"timestamp": timestamp,
|
|
"text": f"Discussion du {timestamp} - User: {user_input} | AI: {ai_response}",
|
|
"source": "chat_history"
|
|
}
|
|
|
|
data = []
|
|
if os.path.exists(MEMORY_FILE):
|
|
with open(MEMORY_FILE, 'r') as f:
|
|
try:
|
|
data = json.load(f)
|
|
except:
|
|
data = []
|
|
|
|
data.append(entry)
|
|
|
|
# On garde les 1000 dernières entrées pour la performance
|
|
with open(MEMORY_FILE, 'w') as f:
|
|
json.dump(data[-1000:], f, indent=2)
|
|
print(f"✅ Échange archivé dans la mémoire sémantique.")
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
if len(sys.argv) > 2:
|
|
record_chat(sys.argv[1], sys.argv[2])
|