https://github.com/tdiprima/langchain-flask-api
A modular, multi-user chatbot API with memory, personas, and OpenAI integration.
https://github.com/tdiprima/langchain-flask-api
Last synced: 3 months ago
JSON representation
A modular, multi-user chatbot API with memory, personas, and OpenAI integration.
- Host: GitHub
- URL: https://github.com/tdiprima/langchain-flask-api
- Owner: tdiprima
- License: mit
- Created: 2025-03-12T14:41:50.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-09T17:26:01.000Z (6 months ago)
- Last Synced: 2025-06-07T07:36:42.561Z (4 months ago)
- Language: Python
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README



# π§ LangChain Chatbot API β Multi-User Edition
A modular, Flask-based chatbot API powered by LangChain and OpenAI. Now with multi-user support, persistent chat history, persona control, and built-in authentication. Lightweight, flexible, and ready to roll for experimentation or production.
---
## π Features
- π§ββοΈ **Multi-user support** β Users can authenticate and maintain their own chat sessions
- π¬ **Persistent conversation memory** β Chats survive app restarts via JSON/db-backed persistence
- π§ **LangChain integration** β For advanced prompting and context-aware conversations
- π **Personas** β Modify chatbot tone/behavior using preset styles
- π **Authentication** β Token-based auth via `/login` and `/register` endpoints
- π **Modular structure** β Each component is standalone/testable
- π§ͺ **Shell test scripts** β Each major function has a matching `.sh` tester---
## π Project Structure
| File | Description |
|-----------------------------|-------------------------------------------------|
| `app.py` / `app_multiuser.py` | Flask app entry points |
| `chatbot_api.py` | Main API logic and routing |
| `authentication.py` | Handles login, registration, and auth checks |
| `user_authentication.py` | User credential storage + token management |
| `chat_history.py` | In-memory and persistent chat history manager |
| `persistence.py` | Low-level storage logic (files/db/etc) |
| `conversation_persistence.py` | Combines memory + file-backed storage |
| `prompt_engineering.py` | Prompt construction + persona injection |
| `prompt_engineering1.py` | (Optional) Extended prompt engineering module |> βοΈ Each file likely has a companion shell script for curl-based testing.
---
## π Authentication Flow
```bash
# Register a new user
curl -X POST http://localhost:3000/register \
-H "Content-Type: application/json" \
-d '{"username":"alice", "password":"secret"}'# Login and receive auth token
curl -X POST http://localhost:3000/login \
-H "Content-Type: application/json" \
-d '{"username":"alice", "password":"secret"}'
```Use the returned token in all future requests via `Authorization: Bearer `.
---
## π§ Example Chat Flow
```bash
# Ask a question
curl -X POST http://localhost:3000/ask \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"question": "What is the capital of Switzerland?"}'# Continue with a persona
curl -X POST http://localhost:3000/ask \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"question": "Tell me something cool about it.", "persona": "friendly"}'
```---
## βοΈ Setup
```bash
# Install dependencies
pip install flask langchain openai# Set environment variables
export OPENAI_API_KEY="your-key"
export OPENAI_API_VERSION="2023-05-15"# Start the app
python app_multiuser.py # or app.py for basic version
```---
## β Shell Test Scripts
Each major module has a matching shell script (not shown here) that includes cURL-based API tests. Great for verifying:
- Authentication
- Chat memory
- Persona behavior
- Conversation persistenceRun them from your terminal to simulate real-world usage.
---
## π― Use Cases
- π§ͺ Prototype chatbot UIs or assistant backends
- π§° Develop and test LangChain memory chains
- π§βπ» Practice secure API design with authentication
- π€Ή Experiment with persona-aware LLM behaviors---
## π£ Contributions & Feedback
PRs welcome. If it breaks, log it. If it's awesome, share it. Letβs build cool stuff. π
> β οΈ **Note:** Some Python modules in this repository are partial implementations or work-in-progress stubs. You may encounter placeholder functions, incomplete classes, or redundant components (e.g., `prompt_engineering1.py`, `user_authentication.py`). These are included for development transparency and future extension.