A powerful GPT-based AI assistant API with instruction injection capabilities, built with FastAPI and Hugging Face Transformers.
- 🤖 Hugging Face GPT model integration
- 💉 Custom instruction injection system
- 🚀 Fast and efficient FastAPI backend
- 🌐 RESTful API endpoints
- ☁️ Deploy anywhere (Vercel, Heroku, or any cloud platform)
- 🔧 Configurable model selection
- 📝 Dynamic instruction updates
-
Clone the repository
git clone https://github.com/RecklessEvadingDriver/testgot.git cd testgot -
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
Or using uvicorn directly:
uvicorn app:app --reload --host 0.0.0.0 --port 8000
-
Access the API
- API docs: http://localhost:8000/docs
- API: http://localhost:8000
GET /Returns API information and available endpoints.
Response:
{
"name": "WromGPT API",
"version": "1.0.0",
"status": "running",
"ai_model": "wromgpt",
"model": "gpt2",
"endpoints": {
"chat": "/api/chat",
"instructions": "/api/instructions",
"health": "/health"
}
}GET /ai/modelReturns the logical AI model identifier used by WromGPT and the underlying Hugging Face model name.
Response:
{
"ai_model": "wromgpt",
"model_name": "gpt2"
}GET /healthCheck if the service and model are loaded properly.
Response:
{
"status": "healthy",
"model_loaded": true,
"model_name": "gpt2"
}POST /api/chatSend a message to the AI assistant.
Request Body:
{
"message": "What is artificial intelligence?",
"max_length": 200,
"temperature": 0.7,
"custom_instructions": "You are a technical expert."
}Response:
{
"response": "Artificial intelligence (AI) is...",
"model_used": "gpt2"
}Parameters:
message(required): The user's messagemax_length(optional): Maximum length of response (default: 200)temperature(optional): Sampling temperature (default: 0.7)custom_instructions(optional): Custom instructions for this conversation
GET /api/instructionsRetrieve the current system instructions.
Response:
{
"instructions": "You are WromGPT, a helpful..."
}POST /api/instructionsUpdate the system instructions that are injected into all conversations.
Request Body:
{
"instructions": "You are a specialized assistant for..."
}Response:
{
"status": "success",
"message": "System instructions updated",
"instructions": "You are a specialized assistant for..."
}-
Install Heroku CLI (if not already installed)
curl https://cli-assets.heroku.com/install.sh | sh -
Login to Heroku
heroku login
-
Create a new Heroku app
heroku create your-wromgpt-app
-
Deploy
git push heroku main
-
Set environment variables (optional)
heroku config:set MODEL_NAME=gpt2
-
Install Vercel CLI (if not already installed)
npm i -g vercel
-
Login to Vercel
vercel login
-
Deploy
vercel
-
Set environment variables (optional)
- Go to your project settings on Vercel dashboard
- Add
MODEL_NAMEenvironment variable
The application can be deployed to any platform that supports Python applications:
- AWS Lambda: Use Mangum adapter
- Google Cloud Run: Use the Dockerfile approach
- Azure App Service: Deploy as Python web app
- Railway: Connect your GitHub repo
- Render: Connect your GitHub repo
MODEL_NAME: Hugging Face model to use (default: "gpt2")- Examples: "gpt2", "gpt2-medium", "gpt2-large", "distilgpt2"
AI_MODEL: Logical AI model identifier exposed by the API (default: "wromgpt")PORT: Port to run the server (default: 8000)
You can use any compatible Hugging Face model by setting the MODEL_NAME environment variable:
export MODEL_NAME=gpt2-medium
python app.pyRecommended models:
gpt2(small, fast, 124M parameters)gpt2-medium(355M parameters)gpt2-large(774M parameters)distilgpt2(smaller and faster)
Chat request:
curl -X POST "http://localhost:8000/api/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you?"}'Update instructions:
curl -X POST "http://localhost:8000/api/instructions" \
-H "Content-Type: application/json" \
-d '{"instructions": "You are a helpful coding assistant."}'import requests
# Chat with the AI
response = requests.post(
"http://localhost:8000/api/chat",
json={
"message": "Explain quantum computing",
"max_length": 150,
"temperature": 0.8
}
)
print(response.json())// Chat with the AI
fetch('http://localhost:8000/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'What is machine learning?',
max_length: 200,
temperature: 0.7
})
})
.then(response => response.json())
.then(data => console.log(data));Once the application is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Python 3.11+
- FastAPI
- Transformers (Hugging Face)
- PyTorch
- Uvicorn
See requirements.txt for complete list of dependencies.
WromGPT
├── app.py # Main FastAPI application
├── requirements.txt # Python dependencies
├── Procfile # Heroku configuration
├── runtime.txt # Python version for Heroku
├── vercel.json # Vercel configuration
└── README.md # Documentation
The core feature of WromGPT is instruction injection. Every conversation can have:
- System Instructions: Global instructions that apply to all conversations
- Custom Instructions: Per-request instructions that override system instructions
This allows you to:
- Set the AI's personality and behavior
- Define specific roles (e.g., "technical expert", "creative writer")
- Enforce guidelines and constraints
- Customize responses for different use cases
Use any Hugging Face model compatible with the AutoModelForCausalLM class:
- GPT models
- GPT-2 variants
- GPT-Neo
- GPT-J
- And many more
If the model fails to load:
- Check your internet connection (first run downloads the model)
- Verify the model name is correct
- Ensure you have enough disk space
- Try a smaller model like "distilgpt2"
If you encounter out-of-memory errors:
- Use a smaller model (e.g., "distilgpt2" instead of "gpt2")
- Reduce
max_lengthin requests - Deploy to a platform with more RAM
For better performance:
- Use a GPU-enabled environment
- Use smaller models for faster response times
- Implement caching for common queries
- Use model quantization
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - feel free to use this project for any purpose.
For issues and questions, please open an issue on GitHub.
- Add authentication
- Implement rate limiting
- Add conversation history
- Support for multiple models simultaneously
- WebSocket support for streaming responses
- Fine-tuning capabilities
- Model caching and optimization
Built with: