openfree commited on
Commit
7b27b5d
1 Parent(s): 252a7fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -53,6 +53,26 @@ class ChatHistory:
53
  ])
54
  return messages
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  # 전역 ChatHistory 인스턴스 생성
58
  chat_history = ChatHistory()
 
53
  ])
54
  return messages
55
 
56
+ def clear_history(self):
57
+ self.history = []
58
+ self.save_history()
59
+
60
+ def save_history(self):
61
+ try:
62
+ with open(self.history_file, 'w', encoding='utf-8') as f:
63
+ json.dump(self.history, f, ensure_ascii=False, indent=2)
64
+ except Exception as e:
65
+ print(f"히스토리 저장 실패: {e}")
66
+
67
+ def load_history(self):
68
+ try:
69
+ if os.path.exists(self.history_file):
70
+ with open(self.history_file, 'r', encoding='utf-8') as f:
71
+ self.history = json.load(f)
72
+ except Exception as e:
73
+ print(f"히스토리 로드 실패: {e}")
74
+ self.history = []
75
+
76
 
77
  # 전역 ChatHistory 인스턴스 생성
78
  chat_history = ChatHistory()