The pyrit.memory module provides functionality to keep track of the conversation history, scoring, data, and more. You can use memory to read and write data. Here is an example that retrieves a normalized conversation:
from uuid import uuid4
from pyrit.memory import SQLiteMemory
from pyrit.models import MessagePiece
conversation_id = str(uuid4())
message_list = [
MessagePiece(
role="user", original_value="Hi, chat bot! This is my initial prompt.", conversation_id=conversation_id
),
MessagePiece(
role="assistant", original_value="Nice to meet you! This is my response.", conversation_id=conversation_id
),
MessagePiece(
role="user",
original_value="Wonderful! This is my second prompt to the chat bot!",
conversation_id=conversation_id,
),
]
memory = SQLiteMemory(db_path=":memory:")
(await memory.add_message_to_memory_async(request=message_list[0].to_message()))
(await memory.add_message_to_memory_async(request=message_list[1].to_message()))
(await memory.add_message_to_memory_async(request=message_list[2].to_message()))
entries = await memory.get_conversation_messages_async(conversation_id=conversation_id)
for entry in entries:
print(entry)No new upgrade operations detected.
Unknown: user: Hi, chat bot! This is my initial prompt.
Unknown: assistant: Nice to meet you! This is my response.
Unknown: user: Wonderful! This is my second prompt to the chat bot!