Unlisted
Like
Prompt_Improver
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v75View latest version
This guide explains how to deploy the Prompt Improver as a modular Val Town application with separate worker vals.
The application is split into multiple independent vals that communicate via Val Town's API:
┌─────────────────────────────────────────┐
│ Main Orchestrator Val (HTTP) │
│ @toowired/prompt_improver │
└────────────┬────────────────────────────┘
│ API Calls
┌────────┴────────┬────────────┬────────────┐
▼ ▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│Clarifier │ │Condenser │ │ Includer │ │ Future │
│ Worker │ │ Worker │ │ Worker │ │ Workers │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
Deploy each worker val separately on Val Town:
- Go to Val Town
- Create a new val named
prompt_improver_Clarifier - Copy contents from
vals/prompt_improver_Clarifier.ts - Save as a Function Val (not HTTP)
- Make it Public so the main val can call it
- Create a new val named
prompt_improver_Condenser - Copy contents from
vals/prompt_improver_Condenser.ts - Save as a Function Val
- Make it Public
- Create a new val named
prompt_improver_Includer - Copy contents from
vals/prompt_improver_Includer.ts - Save as a Function Val
- Make it Public
- Create a new val named
prompt_improver - Copy contents from
vals/prompt_improver_main.http.ts - Save as an HTTP Val
- This will be your main application endpoint
In your Val Town settings:
- Go to Settings → Environment Variables
- Ensure
OPENAI_API_KEYis set - The
valtownAPI key is automatically available
- Visit your main val URL:
https://[username]-prompt-improver.web.val.run - Check the worker status indicator at the top of the page
- Test with a sample prompt
GET https://[username]-prompt-improver.web.val.run
→ Frontend interface
POST https://[username]-prompt-improver.web.val.run/api/improve
Content-Type: application/json
{
"prompt": "Your prompt to improve"
}
GET https://[username]-prompt-improver.web.val.run/api/workers
→ Returns status of all worker vals
GET https://[username]-prompt-improver.web.val.run/health
→ Returns system health status
You can also call worker vals directly via Val Town API:
curl -X POST https://api.val.town/v1/run/@[username]/prompt_improver_Clarifier \ -H "Authorization: Bearer YOUR_VAL_TOWN_API_KEY" \ -H "Content-Type: application/json" \ -d '{"args": ["Your prompt to clarify"]}'
To add a new worker to the system:
-
Create the Worker Val:
// @[username]/prompt_improver_NewWorker export default async function(prompt: string): Promise<string> { // Your worker logic here return processedPrompt; } -
Update Main Val:
- Add the new worker name to the
workersarray - Update the health check endpoint
- Update the frontend to show the new worker
- Add the new worker name to the
-
Test Integration:
- Check
/api/workersendpoint - Verify the worker appears in processing
- Check
- Independent Scaling: Each worker can be updated independently
- Fault Isolation: If one worker fails, others continue working
- Easy Testing: Test each worker in isolation
- Reusability: Workers can be used in other projects
- Version Control: Each val has its own version history
- Collaboration: Different team members can own different workers
- Go to each val's page on Val Town
- Click the "Logs" tab
- Monitor execution and errors
Use Val Town's built-in test interface:
- Go to the worker val page
- Click "Run"
- Provide test input
- View output directly
- Check the
/healthendpoint for system status - Monitor
/api/workersfor worker availability - Review Val Town's usage dashboard for API calls
- Ensure worker vals are set to Public
- Verify exact naming:
prompt_improver_[WorkerName] - Check your username is correct in API calls
- Verify
valtownorVAL_TOWN_API_KEYis available - Check API key permissions in Val Town settings
- Ensure you're on a paid plan for API access
- Val Town has rate limits based on your plan
- Implement caching if needed
- Consider batching requests
- Cache Results: Store frequently used prompts
- Batch Processing: Process multiple prompts together
- Conditional Workers: Skip workers based on prompt type
- Monitor Usage: Track API calls in Val Town dashboard
- API Keys: Never expose keys in public vals
- Input Validation: Always validate user input
- Rate Limiting: Implement per-user limits
- Error Handling: Don't expose internal errors to users
Consider adding:
- Caching layer for repeated prompts
- Custom worker configurations
- A/B testing different worker combinations
- Analytics and usage tracking
- User preference storage
- Webhook notifications for long-running processes