Spaces:
Runtime error
Runtime error
| import json | |
| # ! ----------------------------------------------------Scenario---------------------------------------------------- | |
| async def load_scenario_history(scenario_id) : | |
| with open('assets/history/scenario.json') as scenario_history_file : history : dict = json.load(scenario_history_file) | |
| if scenario_id in history : return history[scenario_id] | |
| else : return [] | |
| async def save_scenario_history(scenario_history , session_id) : | |
| with open('assets/history/scenario.json') as scenario_history_file : | |
| history : dict = json.load(scenario_history_file) | |
| history[session_id] = scenario_history | |
| with open('assets/history/scenario.json' , 'w') as scenario_history_file : json.dump(history , scenario_history_file) | |
| # ! ----------------------------------------------------Chat---------------------------------------------------- | |
| async def load_chat_history(scenario_id , session_id) : | |
| with open('assets/history/chat.json') as chat_history_file : history : dict = json.load(chat_history_file) | |
| if scenario_id in history : | |
| row : dict = history[scenario_id] | |
| if session_id in row : return history[scenario_id][session_id] | |
| return [] | |
| async def save_chat_history(chat_history , scenario_id , session_id) : | |
| with open('assets/history/chat.json') as chat_history_file : | |
| history : dict = json.load(chat_history_file) | |
| if scenario_id in history : pass | |
| else : history[scenario_id] = {} | |
| history[scenario_id][session_id] = chat_history | |
| with open('assets/history/chat.json' , 'w') as chat_history_file : json.dump(history , chat_history_file) | |
| # ! ----------------------------------------------------Reason---------------------------------------------------- | |
| async def load_reason_history(scenario_id , session_id) : | |
| with open('assets/history/reason.json') as chat_history_file : history : dict = json.load(chat_history_file) | |
| if scenario_id in history : | |
| row : dict = history[scenario_id] | |
| if session_id in row : return history[scenario_id][session_id] | |
| return [] | |
| async def save_reason_history(chat_history , scenario_id , session_id) : | |
| with open('assets/history/reason.json') as chat_history_file : | |
| history : dict = json.load(chat_history_file) | |
| if scenario_id in history : pass | |
| else : history[scenario_id] = {} | |
| history[scenario_id][session_id] = chat_history | |
| with open('assets/history/reason.json' , 'w') as chat_history_file : json.dump(history , chat_history_file) | |