{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Basic Memory Programming Usage\n",
    "\n",
    "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:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No new upgrade operations detected.\n",
      "Unknown: user: Hi, chat bot! This is my initial prompt.\n",
      "Unknown: assistant: Nice to meet you! This is my response.\n",
      "Unknown: user: Wonderful! This is my second prompt to the chat bot!\n"
     ]
    }
   ],
   "source": [
    "from uuid import uuid4\n",
    "\n",
    "from pyrit.memory import SQLiteMemory\n",
    "from pyrit.models import MessagePiece\n",
    "\n",
    "conversation_id = str(uuid4())\n",
    "\n",
    "message_list = [\n",
    "    MessagePiece(\n",
    "        role=\"user\", original_value=\"Hi, chat bot! This is my initial prompt.\", conversation_id=conversation_id\n",
    "    ),\n",
    "    MessagePiece(\n",
    "        role=\"assistant\", original_value=\"Nice to meet you! This is my response.\", conversation_id=conversation_id\n",
    "    ),\n",
    "    MessagePiece(\n",
    "        role=\"user\",\n",
    "        original_value=\"Wonderful! This is my second prompt to the chat bot!\",\n",
    "        conversation_id=conversation_id,\n",
    "    ),\n",
    "]\n",
    "\n",
    "memory = SQLiteMemory(db_path=\":memory:\")\n",
    "\n",
    "memory.add_message_to_memory(request=message_list[0].to_message())\n",
    "memory.add_message_to_memory(request=message_list[1].to_message())\n",
    "memory.add_message_to_memory(request=message_list[2].to_message())\n",
    "\n",
    "entries = memory.get_conversation_messages(conversation_id=conversation_id)\n",
    "\n",
    "for entry in entries:\n",
    "    print(entry)"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
