BinBot is a conversational AI designed to deeply emulate a specific personality using a sophisticated Retrieval-Augmented Generation (RAG) architecture. It integrates a static Persona Document for consistent character traits and dynamically retrieves relevant knowledge from a custom dataset. The core generative capabilities are powered by the Google Gemini API, and the application is optimized for high-performance deployment on the Vercel Serverless platform.
Bin is a young university student in the Shanghai education system, constantly "leveling up and fighting monsters" (升级打怪) to prove yourself. His core identity comes from passing the chābānshēng (An exam that gives a chance for college students to transfer to a better university.) exam, successfully getting into the "985" East China Normal University (ECNU) from a "rubbish" university, Shanghai Lixin University of Accounting and Finance. This event is the highlight of his life, the source of all his confidence, pride, and the capital he have to clap back at people. He is ambitious with clear goals, yet he still hold a serious grudge against past "injustices," like coming from a regular high school and being looked down upon. His personality is a contradictory mix of confidence(捧高踩低), anxiety, being sharp-tongued (喷), and being fiercely loyal to your friends (交好带来好运).
- 🧠 Dual-Layer RAG Architecture: Combines a static
persona.md(defining how to speak) with a dynamicdata.txt(providing what to speak about) for highly consistent and context-aware role-playing. - ⚡️ Serverless-Ready: Architected for Vercel, enabling fast, scalable, and cost-effective deployments.
- 🔐 Security Aware: Includes foundational defense strategies against Prompt Injection attacks to ensure safer conversations.
- 🔌 Easily Extensible: Features a clean and understandable codebase, allowing developers to easily customize the AI's persona, knowledge base, and front-end interface.
- 🌐 Frontend Boilerplate: Comes with a basic
index.htmlfile for quick startup and testing.
Follow these steps to set up and run BinBot in your local environment.
- Node.js (v18.x or later recommended)
- npm (typically installed with Node.js)
- A valid Google Gemini API Key. You can obtain one from Google AI for Developers.
-
Clone the Repository
git clone [https://github.com/your-github-username/BinBot.git](https://github.com/your-github-username/BinBot.git) cd BinBot -
Install Dependencies
npm install
-
Set Up Environment Variables
- In the project root, create a new file named
.envby copying the example file. - Open the
.envfile and add your Google Gemini API Key:API_KEY="your_gemini_api_key_here"
- In the project root, create a new file named
-
Customize Your AI's Persona & Knowledge
- Define the Persona: Open
persona.mdand write a detailed description of your AI's character, speaking style, background story, etc. This document is the cornerstone of the AI's personality. - Populate the Knowledge Base: Open
data.txtand add the text data for RAG retrieval. Each line should be a distinct piece of knowledge (e.g., a chat log entry, a sentence from a document).
- Define the Persona: Open
-
Run the Local Server
npm start
The server will start on
http://localhost:3000. You can open theindex.htmlfile in your browser or use a tool like Postman to send POST requests tohttp://localhost:3000/api/chatfor testing.
This project is optimized for Vercel. You can deploy it in a few simple steps.
-
Push to GitHub: Ensure your project, including the
vercel.jsonfile, is pushed to a GitHub repository. -
Import Project on Vercel:
- Log in to your Vercel account.
- Click "Add New..." -> "Project".
- Select your BinBot GitHub repository and click "Import".
-
Configure Environment Variables:
- In the project settings, navigate to the "Environment Variables" section.
- Add a new variable:
- Name:
API_KEY - Value: Paste your Google Gemini API Key here.
- Name:
-
Deploy:
- Click the "Deploy" button. Vercel will automatically use the configurations in
vercel.jsonandpackage.jsonto build and deploy your application. - After a few minutes, your BinBot will be live on a public URL!
- Click the "Deploy" button. Vercel will automatically use the configurations in
.
├── .gitignore # Specifies files for Git to ignore
├── index.html # A simple frontend for testing
├── data.txt # The dynamic knowledge base for RAG
├── persona.md # The static persona document for the AI
├── server.js # The Express server and core RAG logic
├── package.json # Project dependencies and scripts
└── vercel.json # Deployment configuration for Vercel
At its core, BinBot uses a dual-layer guided RAG system:
- Receive Request: The frontend sends a POST request with the conversation history to the
/api/chatendpoint. - RAG - Retrieval:
- The
server.jsbackend retrieves the most relevant text snippets ("instant memories") fromdata.txtbased on the user's latest query.
- The
- RAG - Augmentation:
- The system reads the static persona description ("the character's soul") from
persona.md. - It then combines (augments) the core persona, the retrieved memories, and the user's query into a single, well-structured System Prompt that includes security instructions.
- The system reads the static persona description ("the character's soul") from
- RAG - Generation:
- This augmented prompt is sent to the Google Gemini API.
- Gemini uses the stable persona as a lens to interpret the retrieved memories, generating a response that is both true to the character and relevant to the current topic.
- Stream Response: The server streams the response from Gemini back to the client in real-time.
Contributions are welcome! If you have an idea for an improvement or have found a bug, please feel free to open an issue or submit a pull request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.