Townie
Townie is an AI assistant that can help you create and edit vals in Val Town. You can use Townie to create backend services, websites, and other vals that are deployed instantly to quickly iterate on an idea.
Get started
To create a new val based on your own prompts, navigate to Townie, type in a prompt, and hit submit. Once Townie has created a val, you’ll see a preview of the live code. You can continue the conversation to iterate on your val further or make manual edits to the code if needed.
HTTP val Template
Townie’s default system prompt includes a template that is used as a basis for vals created in Townie. The template is intended to work well for code that can run on the server or in a client-side context. By default, it’ll tend to use React to build front-end interfaces and the built-in SQLite storage for persisting data.
To change what libraries or approaches Townie uses, you can include instructions in the prompt. For example, you could say “Use Hono instead of React.”
Basic prompt-writing tips
- Saying something like “Make it better” can sometimes yield iterative improvements.
- Copying and pasting errors into the prompt can help Townie diagnose issues.
- Similarly, try asking Townie to brainstorm multiple approaches for comparison before writing code.
- Provide instructions as a numbered list to have Townie carry out tasks in a specific order.
Using a custom system prompt
Townie uses a system prompt to generate code that is appropriate for Val Town. If you’d like to adjust the prompt for a specific use-case, you can edit the default prompt used in Townie’s settings.
Troubleshooting
Diffs
You can ask Townie to “respond with a diff.” For small changes, this works well, but can be error prone on larger diffs or when Townie hallucinates. To disable this behavior, use a phrase like “Respond with the full code” in your prompt. If Townie is continuing to reply with the full code, but you’d prefer to switch back to diffs, use the phrase “Respond with a valid unified diff” in your prompt.
Checking for errors
If Townie produces code with errors, it attempts to catch these errors and recover from them. There are two places to check for errors in HTTP vals: in the val’s Requests log or in your browser’s console, depending on where the error occurs.
Recovering from errors
Sometimes Townie can make mistakes and cause errors. These can usually be recovered from by using specific prompts. If Townie omits parts of the code or a diff patch fails, try replying with a phrase like “Respond with the full code”.
Starting from scratch
When conversations grow in length, Townie may have a tendency to hallucinate or create errors. Starting a new chat thread on the same val can sometimes help.