diff --git a/bot.py b/bot.py index 9dadfad..7186650 100644 --- a/bot.py +++ b/bot.py @@ -1021,26 +1021,33 @@ async def handle_response( logger.info(result) temp = {"role": "assistant", "content": result} history.append(temp) - if request_type: - with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file: + if request_type == "MUSIC": + with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file_music_memory: # First we load existing data into a dict. - file_data = json.load(file) + file_data = json.load(file_music_memory) # Join new_data with file_data inside emp_details file_data.append(temp) - # Sets file's current position at offset. - file.seek(0) + file_music_memory.seek(0) # convert back to json. - json.dump(file_data, file, indent=4) + json.dump(file_data, file_music_memory, indent=4) + elif request_type == "RANDOM": + with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory: + # First we load existing data into a dict. + file_data = json.load(file_memory) + # Join new_data with file_data inside emp_details + file_data.append(temp) + file_memory.seek(0) + # convert back to json. + json.dump(file_data, file_memory, indent=4) else: - with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file: + with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory: # First we load existing data into a dict. - file_data = json.load(file) + file_data = json.load(file_memory) # Join new_data with file_data inside emp_details file_data.append(temp) - # Sets file's current position at offset. - file.seek(0) + file_memory.seek(0) # convert back to json. - json.dump(file_data, file, indent=4) + json.dump(file_data, file_memory, indent=4) return result, MESSAGE_TABLE diff --git a/utils/update_memory.py b/utils/update_memory.py new file mode 100644 index 0000000..c310d41 --- /dev/null +++ b/utils/update_memory.py @@ -0,0 +1,33 @@ +import json +MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json" +ENCODING = "utf-8" + +messages = [ + {"role": "user", "content" : "Hammer: All systems operational"}, + {"role": "assistant", "content": "Aye, Szefie! Wszystkie systemy działają sprawnie. Gotów do dalszej służby! Co podać?"}, + {"role": "user", "content" : "Hammer: Podaj coś na orzeźwienie i przebudzenie. COś co rozgrzeje moje stare kości po ciężkiej pracy!"}, + {"role": "assistant", "content": "Z przyjemnością Szefie! Dla Ciebie przygotuję Midzynarodówkę Interstelarną Wolf's Dragoon - wysoce energetyczny koktajl rozgrzewający i pobudzający jednocześnie."+ + "Do przygotowania potrzebuję:"+ + "\n"+ + "60 ml mocnego rumu z Wolfa (lub innego, jeśli wolisz)"+ + "30 ml soku z cytryny"+ + "35 ml domowego syropu z mięty"+ + "15 ml świeżo zmielonej kawy"+ + "\n"+ + "Mieszam wszystko w shakerze z lodem, a potem przelewam przez sitko do kieliszka koktajlowego. W górę serwuję z bigoskiem z miętą i zestem z cytryny. Rozgrzewa, orzeźwia i daje kopa na resztę nocy."+ + "\n"+ + "Co powiesz Szefie, podać Ci taki?"}, + {"role": "user", "content" : "Hammer: Brzmi jak coś co zrobi robotę! Skal!"}, +] + + +for temp in messages: + + with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as file_memory: + # First we load existing data into a dict. + file_data = json.load(file_memory) + # Join new_data with file_data inside emp_details + file_data.append(temp) + file_memory.seek(0) + # convert back to json. + json.dump(file_data, file_memory, indent=4)