Prompt engineering tutorial

Add memory to GPT-4

Teemu Maatta
4 min readMay 31, 2023

I integrate memory to GPT-4 in JSON-format.

Photo by Samsung Memory on Unsplash

Introduction

In this tutorial, I will create a Large Language Model (LLM) application with an integrated memory¹.

  • Internal memory improves factual accuracy.

Humans write text with ability to ground knowledge from our memories, such as lived experiences.

I will use OpenAI API to feed and retrieve information using an external JSON-memory file.

Following this tutorial dos not require any additional packages beside OpenAI API python package.

Let’s get started!

Memory with GPT-4

Let´s start by adding the required packages and the OpenAI API key.

!pip install --upgrade openai #to upgrade latest OpenAI API-Python package
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")

I next define the prompts to be used:

#Input processing
system_instruction = "You are a world-class prompt engineer producing right prompts to LLM in JSON format only to support programming anything. Only one overall objective. Prompts solve correctly anything by mapping up to 5, short, precise, measurable task/sub-task…

--

--

Teemu Maatta

Author (+200k views) in Artificial General Intelligence. Autonomous Agents. Robotics. Madrid.