Skip to content

Commit 709d3d5

Browse files
author
self
committed
Mostly fixed ChatGPT's issue with heavily hallucinating when making memory text
1 parent e54dfc5 commit 709d3d5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

chatbot.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def remember(self):
545545

546546
def save_memories(self):
547547
gpt = GPT3(self.api_key)
548+
gpt.set_model('chatgpt')
548549

549550
# 0. Create directory for long-term memory storage
550551
if not os.path.exists('neocortex'):
@@ -569,16 +570,16 @@ def save_memories(self):
569570
info('Conversation', 'topic')
570571
info(conversation_string, 'plain')
571572

572-
prompt = ("Create a memory text file with the following format:\n\n" +
573+
prompt = ("Create a new single memory text file with the following format:\n\n" +
573574
"{humans_job:[], humans_likes:[], humans_dislikes[], humans_personality:[], facts_about_human:[], things_discussed:[], humans_interests:[], things_to_remember:[]}\n\n" +
574-
"Fill the text file in with information you obtain from your previous memories and the conversation. If the conversation is empty, update none of your memories. If you " +
575-
"have no memories and the conversation is empty, create a placeholder text with 'nothing' in each key's list. If the conversation is not empty, fill in the memory text " +
576-
"with as much info as is relevant, using as few words as possible, using natural language processing. Please make as few assumptions as possible when recording memories, " +
577-
"sticking only to the facts avaliable. Please ignore the name \"AI:\", as this is the bot.\n\n" +
578-
f"PREVIOUS_MEMORIES: {self.memories}.\n\n" +
575+
"Fill the above dict's lists with information you compile from your previous memories and the conversation. Keep dict list data short and understandable. Keep dict encased in '|' characters. If you " +
576+
"have no data to store, create a placeholder text with 'nothing' in the key's list. If the conversation is not empty, fill in the dict " +
577+
"with as much info as is relevant, using as few words as possible. Please make as few assumptions as possible when recording data, " +
578+
"sticking only to the facts avaliable from the text you are given. Especially aim to record data about the user (their name, likes, etc.)\n\n" +
579+
f"PREVIOUS_MEMORIES:\n{self.memories}.\n\n" +
579580
f"CONVERSATION:\n{conversation_string}")
580581

581-
print(prompt)
582+
#print(prompt)
582583

583584
# 2. Remember the info as short term
584585
memories = gpt.get_text_tokens(prompt, 500)[0]
@@ -646,10 +647,10 @@ def restore_memory(self, max_memories=5):
646647
# 2. Create new memory text
647648
prompt = ("Create a new single memory text file with the following format:\n\n" +
648649
"{humans_job:[], humans_likes:[], humans_dislikes[], humans_personality:[], facts_about_human:[], things_discussed:[], humans_interests:[], things_to_remember:[]}\n\n" +
649-
"Fill the text file in with information you compile from your previous memories; preserve as much info as is efficient. Each old memory text is encased in '|' characters. If you " +
650-
"have no memories, create a placeholder text with 'nothing' in each key's list. If the conversation is not empty, fill in the memory text " +
651-
"with as much info as is relevant, using as few words as possible, using natural language processing. Please make as few assumptions as possible when recording memories, " +
652-
"sticking only to the facts avaliable.\n\n" +
650+
"Fill the above dict's lists with information you compile from your previous memories and the conversation. Keep dict list data short and understandable. Keep dict encased in '|' characters. If you " +
651+
"have no data to store, create a placeholder text with 'nothing' in the key's list. If the conversation is not empty, fill in the dict " +
652+
"with as much info as is relevant, using as few words as possible. Please make as few assumptions as possible when recording data, " +
653+
"sticking only to the facts avaliable from the text you are given. Especially aim to record data about the user (their name, likes, etc.)\n\n" +
653654
f"PREVIOUS_MEMORIES:\n{selected_memories}.\n")
654655
ct = 0
655656

@@ -895,6 +896,11 @@ class GPT3(Chatbot):
895896
interfere with the chatbot.
896897
"""
897898

899+
def __init__(self, api_key):
900+
# 1. Set up apis
901+
self.api_key = api_key
902+
openai.api_key = api_key
903+
898904
def request(self, text:str, tokens: int = 1000):
899905
if not hostile_or_personal(text) and not self.flagged_by_openai(text):
900906

@@ -949,7 +955,8 @@ def get_text_tokens(self, prompt: str, max_token_ct: int = 200) -> tuple:
949955
tokens = reply['usage']['total_tokens']
950956

951957
else:
952-
query = [{'role':'user', 'content':prompt}]
958+
query = [{'role':'system', 'content':'Follow all the users\' directives'},
959+
{'role':'user', 'content':prompt}]
953960
response = openai.ChatCompletion.create(
954961
model="gpt-3.5-turbo",
955962
messages=query,

0 commit comments

Comments
 (0)