A NewBing-like chat bot with long-term memory. It can search the Internet during chat, and remembers things you told it before (not limited by the languange model's context window). Very preliminary, improvements are welcome.
Sample (chat history cleared before the third image):
Also a video demo in Chinese here. The UI was simply adapted from this.
It's based on OpenAI's text generation and embedding APIs. When the user does not send any message for a while, the chat will be summarized into pieces, and stored with text embedding. The chat history is then cleared.
When replying to the user, the bot first retrieves relevant memories using cosine similarity along with some other metrics, and searches the Internet with appropriate keywords if necessary. The retrieved memories and search results are then added to the prompt for reply generation.
You can also trigger a reflection (manually), which will try to generate insights from the memories, and add back to the memory to be used in future chats.
Summarization and reflection are inspired by Generative Agents: Interactive Simulacra of Human Behavior.
Currently it is hard-coded to use gpt-3.5-turbo. It has costed merely 4 RMB for testing and playing till now. gpt-3.5-turbo makes mistakes frequently, but it's still fun to play with. Try gpt-4 if you have enough money : )
- Clone this repo;
- Install required Python packages:
pip install -r requirements.txt
; - Install firefox-esr:
sudo add-apt-repository ppa:mozillateam/ppa && sudo apt install -y firefox-esr
. And install geckodriver if you see compatibility warnings during launch; - Configure environment variables:
OPENAI_API_BASE
: OpenAI API base URL, default tohttps://api.openai.com/v1
;OPENAI_API_KEY
: OpenAI API key.
- Run
python3 main.py <config_name> 127.0.0.1
to start the web server. Available configs can be found/added underconfigs/
. - Open
http://127.0.0.1:5000
in your browser and start chatting.
Tips:
- Access
http://127.0.0.1:5000/memory
to see the memory of the bot; - Access
http://127.0.0.1:5000/reflect
to trigger a reflection (it's slow, wait patiently); - Check
data/bots/<config_name>/log.log
for logs.
This project is licensed under the MIT License - see the LICENSE file for details.