mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 13:34:40 +00:00
Fixing memory of Conjurer
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user