Peacy is an AI-powered mediator designed for group chats. Built using Python, Peacy leverages OpenAI’s language models (via the Groq API) to generate thoughtful, empathetic responses while maintaining a persistent memory of conversations using ChromaDB and PostgreSQL. Peacy listens to group discussions, learns from interactions, and responds only when activated by a wake word (e.g., "Peacy", "PC", etc.), continuously evolving its understanding of the community.
- Uses a Chroma vector store (via LangChain and ChromaDB) to store and retrieve conversation memories for context-aware responses.
- Stores user data and conversation summaries in PostgreSQL, enabling personalized interactions and continuity across sessions.
- Integrates conversation history into prompt templates using LangChain (with the ChatOpenAI interface) to generate smooth, context-sensitive replies.
- Listens for a predefined set of wake words (e.g., "Peacy", "PC", etc.) to trigger a response, preventing unnecessary interruptions.
- Periodically summarizes conversations and performs detailed analysis (sentiment, entity extraction) using background tasks scheduled via APScheduler.
- Includes scripts to reset the Chroma vector store and PostgreSQL tables for easy maintenance and testing.
Peacy uses Pipenv for dependency management. The following packages are required (see the Pipfile for full details):
- python-telegram-bot
- openai
- chromadb
- psycopg2-binary
- sentence-transformers
- apscheduler
- rich
- python-dotenv
- nest-asyncio
- spacy
- pytz
- langchain
- langchain_community
- langchain-huggingface
- langchain-chroma
git clone https://github.com/yourusername/peacy.git
cd peacypip install pipenvpipenv installThis command creates a virtual environment and installs all required packages from the Pipfile and Pipfile.lock.
pipenv shellCreate a .env file in the project root and set the following environment variables:
TELEGRAM_TOKEN=your_telegram_bot_token_here
GROQ_API_KEY=your_groq_api_key_here
OPEN_AI_API_KEY=your_open_ai_api_key_here
PG_CONNECTION_STRING="your_connection_string_here"
CHROMA_PERSIST_DIRECTORY=./chroma_db
PINECONE_API_KEY=your_pinecone_api_key_here # if using Pinecone
ENV=developmentEnsure these variables are correctly configured for your deployment.
To run the bot locally (with the virtual environment activated):
python src/bot.py- Initializes PostgreSQL database on startup (creates tables for messages, users, and summaries).
- Seeds the Chroma vector store if empty to kickstart context building.
- Scheduled tasks for summarization and analysis using APScheduler.
- Responds only when messages contain designated wake words.
To reset Chroma and PostgreSQL storage, run:
python reset_storage.pyThis script:
- Removes Chroma persistence directory (if exists).
- Drops PostgreSQL tables for messages, users, and conversation summaries.
peacy/
├── src/
│ ├── __init__.py
│ ├── bot.py # Main bot file
│ ├── config.py # Loads environment variables
│ ├── db_manager.py # PostgreSQL DB initialization & logging
│ ├── memory_manager.py # Persistent memory handling (ChromaDB)
│ ├── background_tasks.py # Scheduled summarization & analysis tasks
│ └── text_analysis.py # Sentiment analysis & entity extraction
│ └── reset_storage.py # Storage reset utilities
├── Pipfile # Pipenv dependencies
├── Pipfile.lock # Dependency versions
├── .env # Environment variable definitions
├── .gitignore
├── README.md # Project documentation- Modify the prompt template and parameters in
src/bot.py.
- Adjust logic in
src/db_manager.pyandsrc/memory_manager.py.
- Customize the wake words in
src/bot.py.
Uses asynchronous programming (asyncio and nest_asyncio) for smooth operation. To stop Peacy, press Ctrl+C. A graceful shutdown is designed, though forced shutdowns might display messages like "Cannot close a running event loop".