Search

Results include substring matches and semantically similar vals. Learn more
taowen avatar
npmExample
@taowen
An interactive, runnable TypeScript val by taowen
Script
export let npmExample = (async () => {
const { HUMAN_PROMPT, AI_PROMPT, Client } = await import(
"npm:@anthropic-ai/sdk"
); // The Lodash library exported as ES modules.
const client = new Client(
"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"
const prompt = `${HUMAN_PROMPT}
当你的女朋友说“滚, 不要拿AI跟我对话.”。你应该如何安慰她?
${AI_PROMPT}`;
console.log("size of prompt", prompt.length);
pomdtr avatar
ask_ai_example
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
import { askAI } from "https://esm.town/v/pomdtr/ask_ai";
await askAI("Send me an email with a random joke");
yawnxyz avatar
exa
@yawnxyz
// console.log(await search('banana'))
Script
const exa = new Exa(Deno.env.get("EXA_API_KEY"));
export const exaSearch = async ({ query, type, useAutoprompt, numResults, text, summary=true, highlights }) => {
const result = await exa.searchAndContents(
query,
type: type || "auto" || "neural",
useAutoprompt: useAutoprompt || true,
numResults: 10,
highlights: highlights || {
numSentences: 3,
highlightsPerUrl: 1,
kora avatar
aiBasicExample
@kora
Using Vercel AI SDK
Script
Using Vercel AI SDK
import { ModelProvider, modelProvider } from "https://esm.town/v/yawnxyz/ai";
// basic text generation
let response = await modelProvider.gen({
prompt: "hello, who am I speaking to?",
provider: "google",
} as any);
console.log("res:", response);
backspaces avatar
hello
@backspaces
An interactive, runnable TypeScript val by backspaces
Script
import * as util from "https://code.agentscript.org/src/utils.js";
const model = new Model();
await model.startup();
model.setup();
console.log("Running for 500 steps.");
util.repeat(500, model.step);
const sample = util.sampleModel(model);
console.log(sample);
nbbaier avatar
mockToApi
@nbbaier
This val demonstrates the creation of an API with a programmatically generated set of data instead of an existing Val Town lowdb instance.
HTTP
This val demonstrates the [creation of an API](https://www.val.town/v/nbbaier/dbToAPI) with a programmatically generated set
const mock = () => {
const data = { users: [], posts: [], random: {} };
for (let i = 0; i < 25; i++) {
const user: string = faker.person.fullName(); // Rowan Nikolaus
const userSplit: string[] = user.split(" ");
const email: string = userSplit[0].endsWith(".")
? userSplit[1].toLowerCase() + "." + userSplit[2].toLowerCase() + "@"
+ faker.internet.domainName()
: userSplit[0].toLowerCase() + "." + user.split(" ")[1].toLowerCase() + "@"
jeffreyyoung avatar
generativeFill
@jeffreyyoung
An interactive, runnable TypeScript val by jeffreyyoung
HTTP
const replicate = new Replicate({
auth: Deno.env.get("REPLICATE_API_KEY"),
export default serve({
async *handleMessage(req) {
const lastMsg = req.query.at(-1);
if (lastMsg && lastMsg.attachments.length !== 2) {
yield events.replace("No image recieved");
yield html;
yield events.done();
return;
burkaygur avatar
emeraldCrocodile
@burkaygur
An interactive, runnable TypeScript val by burkaygur
Script
import * as fal from "npm:@fal-ai/serverless-client";
fal.config({
// Can also be auto-configured using environment variables:
credentials: Deno.env.get("FAL_KEY"),
const prompt = "a cute and happy dog";
const result: any = await fal.run("fal-ai/fast-lightning-sdxl", { input: { prompt } });
console.log(result.images[0].url);
jeffreyyoung avatar
daringBronzeSnail
@jeffreyyoung
An interactive, runnable TypeScript val by jeffreyyoung
HTTP
export default serve({
async *handleMessage(req) {
yield "hello";
await sleep(1000);
yield events.replace("goodbye");
await sleep(1000);
yield events.error({
allow_retry: true,
text: "ooops!",
yield events.done();
alexdphan avatar
testplaywright
@alexdphan
// Import Playwright using the Deno-compatible URL
Script
// Import Playwright using the Deno-compatible URL
// import { chromium } from "https://esm.sh/playwright-core";
console.info("Launching browser...");
// Use Deno.env to get the API key
const apiKey = Deno.env.get("BROWSERBASE_API_KEY");
if (!apiKey) {
console.error("BROWSERBASE_API_KEY environment variable is not set");
Deno.exit(1);
try {
const browser = await chromium.connectOverCDP(
deblina avatar
arenaApiExample
@deblina
Are.na API Example of using the are.na API to get the contents of an Are.na board - specifically my fun board that showcases websites with that "glossy black style." All you need is fetch to make this happen!
Script
# Are.na API
Example of using the [are.na](https://dev.are.na/documentation/channels#Block43472) API to get the contents of an Are.na boar
All you need is [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make this happen!
import { fetch } from "https://esm.town/v/std/fetch";
export let arenaApiExample = (async () => {
const resp = await fetch(
"http://api.are.na/v2/channels/project-logs",
const json = await resp.json();
console.log(json);
return json;
vlad avatar
tempsimplegptexample
@vlad
// Example of action that doesn't accept any input, but returns something
HTTP
* INITIALIZE API
const api = new GptApi({
url: "https://vlad-tempsimplegptexample.web.val.run",
title: "Some API",
description: "API for something",
version: "1.0.0",
// Example of action that doesn't accept any input, but returns something
const ResponseCommandSchema = z.object({
feedback: z.string().describe("Feedback regarding submitted action"),
data: z.string().optional().describe("Additional data related to the given command"),
stevekrouse avatar
oak_demo
@stevekrouse
Oak Server Example
HTTP
# Oak Server Example
import { Application } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello Val Town!";
export default app.fetch;
tmcw avatar
arenaApiExample
@tmcw
Are.na API Example of using the are.na API to get the contents of an Are.na board - specifically my fun board that showcases websites with that "glossy black style." All you need is fetch to make this happen!
Script
# Are.na API
Example of using the [are.na](https://dev.are.na/documentation/channels#Block43472) API to get the contents of an Are.na boar
All you need is [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make this happen!
import { fetch } from "https://esm.town/v/std/fetch";
export let arenaApiExample = (async () => {
const resp = await fetch(
"http://api.are.na/v2/channels/that-glassy-dark-design-style",
const json = await resp.json();
return json;
nbbaier avatar
tanaSave
@nbbaier
An interactive, runnable TypeScript val by nbbaier
Script
const token = Deno.env.get("tanaInputAPI");
export const tanaSave = async (req: Request) => {
const app = new Hono();
app.get("/save", async c => {
let { text, url } = c.req.query();
const payload: APIPlainNode = {
name: text,
children: [
{ name: "child 1" },
{ type: "field", attributeId: "cwi23sOzRSh8" },