Fixing memory of Conjurer

This commit is contained in:
2024-04-28 12:27:29 +02:00
parent 217533c91f
commit 032cc41c9b
2 changed files with 51 additions and 11 deletions
+18 -11
View File
@@ -1021,26 +1021,33 @@ async def handle_response(
logger.info(result) logger.info(result)
temp = {"role": "assistant", "content": result} temp = {"role": "assistant", "content": result}
history.append(temp) history.append(temp)
if request_type: if request_type == "MUSIC":
with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file: with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as file_music_memory:
# First we load existing data into a dict. # 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 # Join new_data with file_data inside emp_details
file_data.append(temp) file_data.append(temp)
# Sets file's current position at offset. file_music_memory.seek(0)
file.seek(0)
# convert back to json. # 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: 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. # 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 # Join new_data with file_data inside emp_details
file_data.append(temp) file_data.append(temp)
# Sets file's current position at offset. file_memory.seek(0)
file.seek(0)
# convert back to json. # convert back to json.
json.dump(file_data, file, indent=4) json.dump(file_data, file_memory, indent=4)
return result, MESSAGE_TABLE return result, MESSAGE_TABLE
+33
View File
@@ -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)