Add support of reply and do not get borred if prev message is borred. Manage memory.

This commit is contained in:
OK
2024-03-16 23:55:29 +01:00
parent d6942943b5
commit 53ed068519
4 changed files with 58 additions and 7 deletions
+23
View File
@@ -110,3 +110,26 @@ class OpenAIResponder(AIResponder, LeonardoAIDrawMixIn):
except Exception as err:
logging.warning(f"failed to translate the text: {repr(err)}")
return text
async def memory_rewrite(self, memory: str, user: str, question: str, answer: str) -> str:
if 'memory-model' not in self.config:
return memory
messages = [{'role': 'system', 'content': self.config.get('memory-system', 'You are an memory assistant.')},
{'role': 'user', 'content': f'Here is my previous memory:\n```\n{memory}\n```\n\n'
f'Here is my conversanion:\n```\n{user}: {question}\n\nassistant: {answer}\n```\n\n'
f'Please rewrite the memory in a way, that it contain the content mentioned in conversation. '
f'The whole memory should not be too long, summarize if required. '
f'Write just new memory data without any comments.'}]
try:
logging.info(f'send this memory request:\n{pp(messages)}')
result = await openai_chat(self.client,
model=self.config['memory-model'],
messages=messages,
temperature=0.6,
max_tokens=4096)
new_memory = result.choices[0].message.content
logging.info(f'new memory:\n{pp(new_memory)}')
return new_memory
except Exception as err:
logging.warning(f"failed to create new memory: {repr(err)}")
return memory