An AI-powered prompt optimization tool built on Val Town that iteratively improves prompts using multiple specialized AI workers.
- Multi-stage Optimization: Uses three specialized workers (Clarifier, Condenser, Includer) to improve prompts
- Iterative Refinement: Processes prompts through multiple cycles until optimal results are achieved
- Final Organization: Applies a final organization pass to structure the improved prompt
- Modern UI: Clean, responsive interface built with TailwindCSS
- Val Town Integration: Fully compatible with Val Town's serverless platform
The application consists of:
- Main HTTP Handler (
backend/index.http.ts): Serves the frontend and API endpoint - Worker Functions: Three specialized prompt improvement functions
- Clarifier: Makes prompts clearer and more specific
- Condenser: Removes redundancy while maintaining meaning
- Includer: Adds missing context and relevant details
- Frontend: Single-page application with real-time prompt improvement
- Val Town account (paid subscription recommended for API features)
- OpenAI API key configured in Val Town environment variables
- Go to Val Town
- Create a new HTTP val named
prompt_improver - Copy the contents of
backend/index.http.tsto your val - Save and deploy
In your Val Town settings, ensure you have:
OPENAI_API_KEY- Your OpenAI API keyvaltownorVAL_TOWN_API_KEY- Automatically set by Val Town
Your application will be available at:
https://[your-username]-prompt-improver.web.val.run
POST https://[your-username]-prompt-improver.web.val.run/api/improve
{ "prompt": "Your prompt to improve" }
{ "result": "The improved prompt", "steps": 5, "history": [ { "step": 1, "worker": "Clarifier", "prompt": "Clarified version..." } ] }
- Install Deno
- Run the application:
deno run --allow-net --allow-env backend/index.http.ts
- Open http://localhost:8000
Create a .env file:
OPENAI_API_KEY=your_openai_api_key
VAL_TOWN_API_KEY=your_valtown_api_key
- Input: User provides a prompt to improve
- Processing: The prompt goes through multiple optimization cycles:
- Each cycle applies three workers in sequence (Clarifier → Condenser → Includer)
- Process continues until the prompt stabilizes or reaches maximum iterations
- Organization: A final pass organizes the improved prompt for clarity
- Output: Returns the optimized prompt with processing statistics
The MAX_STEPS constant in the backend controls the maximum number of optimization cycles (default: 10).
The application uses OpenAI's gpt-4o-mini model by default. You can change this in the worker functions.
Each worker has different temperature settings optimized for its task:
- Clarifier: 0.3 (more focused)
- Condenser: 0.2 (very focused)
- Includer: 0.4 (slightly creative)
- Organizer: 0 (deterministic)
-
"Failed to improve prompt" error
- Check your OpenAI API key is correctly configured
- Ensure you have API credits available
- Check Val Town logs for detailed error messages
-
Val not found errors
- Ensure the val is deployed with the correct name
- Check that your Val Town account has the necessary permissions
-
CORS errors
- The application includes CORS headers by default
- If issues persist, check your browser's security settings
Enable detailed logging by checking the Val Town logs:
- Go to your val's page on Val Town
- Click on the "Logs" tab
- Review any error messages or console outputs
Feel free to fork this project and submit improvements. Key areas for enhancement:
- Additional worker types
- Support for different AI models
- Batch processing capabilities
- Prompt history and favorites
MIT License - Feel free to use and modify as needed.
For issues or questions:
- Create an issue in this repository
- Contact through Val Town community forums
- Check Val Town documentation at https://docs.val.town