Search
valleGetValsContextWindow
@roadlabs
An interactive, runnable TypeScript val by roadlabs
Script
export default async function getValsContextWindow(model: any) {
prompt: "Write a val that uses OpenAI",
code: `import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
export default async function(req: Request) {
function tsResponse(code) {
Our Blob SDK also includes some utility functions to make working with blobs easier.
"\n```ts\nexport default async function (req: Request): Promise<Response> {\n return Response.json(\"Hello world\")\n}\n```",
"\n```ts\nexport default async function(req: Request): Promise<Response> {\n const query = new URL(req.url).searchParams;\n\n // Read name from the querystring or body. Defaults to \"you\" if not present.\n const name = query.get(\"name\") || (await req.json().catch(() => ({}))).name || \"you\";\n\n // Returns the HTML response\n return new Response(`<h1>Hi ${name}!</h1>`, {\n headers: { \"Content-Type\": \"text/html\" },\n });\n}\n```",
systemsDevModule
@ethtang
// Fetches a random joke.
Script
import { email } from "https://esm.town/v/std/email?v=9";
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",

pollVotingJob
@pranjaldotdev
An interactive, runnable TypeScript val by pranjaldotdev
Cron
let { successCount } = await import("https://esm.town/v/pranjaldotdev/successCount");
export async function pollVotingJob({ lastRunAt }: Interval) {
console.log("Last run was ", lastRunAt);
function sleep(ms: number) {
return new Promise((resolve) =>
}, ms)
async function doVote(): Promise<boolean> {
try {
return false;
async function fireRequests() {
console.log("Script booting up 🚀");
fetchJSON
@dvergin
An interactive, runnable TypeScript val by dvergin
Script
export let fetchJSON = async (url: string, options?: any) => {
//url must return a JSON in string form
//this function parses that string into a javascript object
let f = await fetch(url, {
...options,

increaseinnerfeelingscounter
@politelyinvinciblepointer
An interactive, runnable TypeScript val by politelyinvinciblepointer
Script
let { innerfeelingscounter } = await import("https://esm.town/v/politelyinvinciblepointer/innerfeelingscounter");
export function increaseinnerfeelingscounter() {
innerfeelingscounter++;
duckAndWaffle
@dot
An interactive, runnable TypeScript val by dot
Script
import { fetch } from "https://esm.town/v/std/fetch";
export async function duckAndWaffle() {
let venue = "duckandwaffle";
let start_date = "02-14-2023";
CS1200
@donnyle
// Fetches a random joke.
Cron
import { email } from "https://esm.town/v/std/email?v=9";
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",

myApi
@blainandsimple
An interactive, runnable TypeScript val by blainandsimple
Script
export function myApi(name: string = "Anonymous") {
const now = new Date();
const day = now.getDate();
valle_tmp_32286234407113518840440547453902
@janpaul123
// Respond with a HTML page with silly gradients and crazy CSS
HTTP
// Respond with a HTML page with silly gradients and crazy CSS
export default async function (req: Request): Promise<Response> {
const htmlContent = `
<!DOCTYPE html>

welcomingSapphireRoundworm
@stevekrouse
@jsxImportSource https://esm.sh/react
HTTP
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
const [query, setQuery] = useState("");
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
client();
export default async function server(req: Request): Promise<Response> {
if (req.method === "POST") {
measureValTownE2e
@tmcw
// E.g. from a user's perspective (not the real execution time!)
Script
userFuncTimes.push(Date.now() - start);
console.log(
`average e2e user function time: ${(
userFuncTimes.reduce((a, b) => a + b, 0) / count
).toFixed(0)}ms (fastest was ${userFuncTimes
hnFollowPollJob
@sina
An interactive, runnable TypeScript val by sina
Script
import { hackerNewsAuthors } from "https://esm.town/v/sina/hackerNewsAuthors";
import { hnLatestPosts } from "https://esm.town/v/stevekrouse/hnLatestPosts?v=18";
export async function hnFollowPollJob({ lastRunAt }) {
let posts = await hnLatestPosts({
authors: hackerNewsAuthors,

stockAPI
@pete
This Val accepts a stock symbol and will return current price and intraday price change. example: https://pete-stockapi.web.val.run/symbol=MSFT It's currently using alphavantage free tier API so it's limited to only 25 requests/day. Fork and create your own premium API key for more request.
HTTP
const ALPHA_VANTAGE_API_KEY = "your_api_key_here"; // Replace with your actual API key
async function fetchStockData(symbol: string) {
const apiUrl =
`https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=${ALPHA_VANTAGE_API_KEY}`;
const response = await fetch(apiUrl);
// This is the default export for Val Town
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);

serveCommand
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
* if `false`, the arguments will be empty.
args?: string[] | boolean;
export function serveCommand(
params: ServeCommandParams,
): (req: Request) => Response | Promise<Response> {
lotterymahaGame
@funjo
@jsxImportSource https://esm.sh/react@18.2.0
HTTP
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
function WalletApp() {
const [mode, setMode] = useState('login');
</div>
function client() {
createRoot(document.getElementById("root")).render(<WalletApp />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");