API generates
Haikus flow like autumn leaves
OpenAI bridge
A lightweight Flask API that bridges to OpenAI's Chat API for haiku generation. Designed to be used as a backend service for applications needing creative text.
- RESTful API endpoint for haiku generation
- CORS enabled for cross-origin requests
- OpenAI Chat API integration (gpt-3.5-turbo)
- Simple JSON request/response format
- Error handling and logging
- Clone the repository
- Create a
.envfile with your OpenAI API key:OPENAI_API_KEY=your_key_here - Install dependencies:
pip install -r requirements.txt
- Run the server:
python3 app.py
Endpoint: POST http://127.0.0.1:8000/generate-haiku
Request:
{
"prompt": "Write a haiku about nature"
}Response:
{
"haiku": "Soft breeze rustles leaves\nMorning dew glistens brightly\nNature's gentle song"
}A simple HTML test page (index.html) is included for manual testing.
- Backend: Flask, OpenAI API
- Environment: Python 3.x
MIT