Search
oauthConcept
@pomdtr
// oauth middleware protect the val behind github oauth
HTTP
export default oauth({
scopes: ["read:user"],
client_id: Deno.env.get("GITHUB_CLIENT_ID"),
client_secret: Deno.env.get("GITHUB_CLIENT_SECRET"),
auth_url: "https://github.com/login/oauth/authorize",
token_url: "https://github.com/login/oauth/access_token",
OpenAI
@wangqiao1234
OpenAI - Docs ↗ Use OpenAI's chat completion API with std/openai . This integration enables access to OpenAI's language models without needing to acquire API keys. For free Val Town users, all calls are sent to gpt-3.5-turbo . Streaming is not yet supported. Upvote the HTTP response streaming feature request if you need it! Usage import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
],
model: "gpt-4",
max_tokens: 30,
});
console.log(completion.choices[0].message.content); Limits While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in mind: Usage Quota : We limit each user to 10 requests per minute. Features : Chat completions is the only endpoint available. If these limits are too low, let us know! You can also get around the limitation by using your own keys: Create your own API key on OpenAI's website Create an environment variable named OPENAI_API_KEY Use the OpenAI client from npm:openai : import { OpenAI } from "npm:openai";
const openai = new OpenAI(); 📝 Edit docs
HTTP
3. Use the `OpenAI` client from `npm:openai`:
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
private rawOpenAIClient: RawOpenAI;
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
return this.rawOpenAIClient.chat;
discordActivityClient
@neverstew
// Once setupDiscordSdk is complete, we can assert that "auth" is initialized
Script
await discordSdk.ready();
// Authorize with Discord Client
const { code } = await discordSdk.commands.authorize({
client_id: "1301388102966972468",
response_type: "code",
const { access_token } = await response.json();
// Authenticate with Discord client (using the access_token)
auth = await discordSdk.commands.authenticate({
saveToTana
@nbbaier
Save To Tana This val provides a function saveToTana allows the creation of nodes in Tana via their Input API . The parameters are as follows: Token: to access the Tana Input API, you must pass an API token to the function. Obtain an API token from the Tana app and save it as a secret in Val Town. Node: the node that is created within Tana is passed as the second argument and must conform to the shape of an Input API node (see the documentation on github for details. Target node: optionally, you can specify a specific target node by passing a node ID to the function as it's third argument. Example Usage One way to use this val is with a web endpoint that you can send data to to have parsed and submitted to Tana as a specific type of node. For example, this val import { saveToTana } from "https://esm.town/v/nbbaier/saveToTana";
import { APIPlainNode } from "https://esm.town/v/nbbaier/tanaTypes";
import { Hono } from "npm:hono";
const token = Deno.env.get("tanaInputAPI");
export const honoTanaEndpoint = async (req: Request) => {
const app = new Hono();
app.get("/", async c => {
let { text, url } = c.req.query();
const payload: APIPlainNode = {
name: text,
children: [
{
type: "field",
attributeId: "cwi23sOzRSh8",
children: [
{
dataType: "url",
name: url,
},
],
},
],
supertags: [],
};
const newNode = await saveToTana(token, payload);
return c.json({ newNode });
});
return app.fetch(req);
}; Combined with a Chrome extension like Rich URL , the above val allows one to send selected text on a page along with that pages URL to Tana via the val's public GET endpoint.
Script
node: APIPlainNode,
targetNodeId: string = tanaConstants.inboxNodeId,
const client = new TanaAPIHelper(token);
const createdNode = await client.createNode(node, targetNodeId);
return createdNode;
OpenAI
@pattysi
OpenAI - Docs ↗ Use OpenAI's chat completion API with std/openai . This integration enables access to OpenAI's language models without needing to acquire API keys. Streaming is not yet supported. Upvote the HTTP response streaming feature request if you need it! Usage import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
],
model: "gpt-4",
max_tokens: 30,
});
console.log(completion.choices[0].message.content); Limits While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in mind: Usage Quota : We limit each user to 10 requests per minute. Features : Chat completions is the only endpoint available. If these limits are too low, let us know! You can also get around the limitation by using your own keys: Create your own API key on OpenAI's website Create an environment variable named OPENAI_API_KEY Use the OpenAI client from npm:openai : import { OpenAI } from "npm:openai";
const openai = new OpenAI(); 📝 Edit docs
Script
3. Use the `OpenAI` client from `npm:openai`:
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
private rawOpenAIClient: RawOpenAI;
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
return this.rawOpenAIClient.chat;
unsplashF
@byrneml
An interactive, runnable TypeScript val by byrneml
Script
`https://api.unsplash.com/photos`,
headers: {
"Authorization": `Client-ID ${unsplashAccessToken}`,
add_to_notion_from_todoist
@nerdymomocat
Use todoist for quick notes to add to notion. Uses project to decide which project to fetch to add stuff to notion. Can add to page or database based on config below. Demarkation using sections in the todoist project. Extracts date for page blocks that are added as callouts.
Cron
import process from "node:process";
import { TodoistApi } from "npm:@doist/todoist-api-typescript";
import { Client } from "npm:@notionhq/client";
const TODOIST_API_KEY = process.env.TODOIST_API_KEY;
const todoistapi = new TodoistApi(TODOIST_API_KEY);
const NOTION_API_KEY = process.env.NOTION_API_KEY;
const notion = new Client({
auth: NOTION_API_KEY,
var add_to_notion_todoist_project_id = "PROJECT_ID_HERE";
instructorExample
@inkpotmonkey
Example copied https://instructor-ai.github.io/instructor-js/#usage into val.town You will need to fork this and properly set the apiKey and organisation for it to work.
Script
const oai = new OpenAI(openAISecrets);
const client = Instructor({
client: oai,
mode: "FUNCTIONS",
// User will be of type z.infer<typeof UserSchema>
const user = await client.chat.completions.create({
messages: [{ role: "user", content: "Jason Liu is 30 years old" }],
faunadb_test
@mattx
An interactive, runnable TypeScript val by mattx
Script
export const faunadb_test = (async () => {
const { faunadb } = await import("npm:faunadb");
const client = new faunadb.Client({
secret: process.env.fauna_key,
const { Get, Ref, Collection } = faunadb.query;
// from included sample data
const result = await client.query(Get(Ref(Collection("products"), "202")));
return result;
sqlite
@std
SQLite - Docs ↗ SQLite is a lightweight, standard database. Every Val Town account comes with its own private SQLite database that is accessible from any of your vals via std/sqlite . Val Town SQLite is powered by Turso . Usage Migrations ORMs We recommend these admin data viewers for managing your database – viewing or editing data or your database table schema: Outerbase Studio (recommended) - formely known as LibSQL Studio – see instructions here SQLite Explorer (built in Val Town) Limits You can store 10mb on the free plan and up to 1gb on the paid plan. Contact us if you need more space. 📝 Edit docs
Script
import { API_URL } from "https://esm.town/v/std/API_URL";
import { LibsqlError, type TransactionMode } from "npm:@libsql/client";
import { z } from "npm:zod";
* Every Val Town account comes with its own private
sqlitePublic
@pps
An interactive, runnable TypeScript val by pps
HTTP
import { createSqlite } from "https://esm.town/v/postpostscript/sqliteWasm";
import type { InStatement } from "https://esm.town/v/std/sqlite";
import { type ResultSet } from "npm:@libsql/client";
import { Hono } from "npm:hono";
const dumped = {};
http
@rlimit
* API Client for interfacing with the RateLimit API. Uses free tier rlimit.com credentials.
Script
type valOptions = Omit<Options, 'namespace' | 'subnamespace' | 'password' | 'baseURL'>
* API Client for interfacing with the RateLimit API. Uses free tier rlimit.com credentials.
export class RateLimit {
private client;
constructor(options: valOptions) {
this.client = new RawRateLimit({
baseURL: "https://rlimit-proxy.web.val.run",
async check(key: string, options?: valOptions): Promise<Result> {
return this.client.check(key, {
interval: options?.interval,
chatAgentWithCustomPrompt
@jacoblee93
An interactive, runnable TypeScript val by jacoblee93
Script
new Calculator(),
const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-zero-shot-react-description",
verbose: true,
agentArgs: {
generate_openapi_schema
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
import createClient from "https://esm.town/v/pomdtr/val_town_client";
import openapiTS from "npm:openapi-typescript";
const client = createClient({
token: Deno.env.get("valtown"),
const code = await openapiTS(new URL("https://pomdtr-val_town_openapi.web.val.run"));
const { data, error, response } = await client.PUT("/v1/vals", {
body: {
dailySlackStandup
@dnishiyama
// Depending on the day do one of these:
Cron
// Team member spotlight: Briefly highlight a different team member each day with an interesting fact about them.
// Joke or pun of the day: Include a work-appropriate joke or pun to start the day with a smile.
// Question of the day: Pose a thought-provoking or fun question for team members to consider answering during the standup.
// GIF or meme: If appropriate for your workplace, include a relevant and fun GIF or meme in the reminder.
// Progress tracker: Include a visual representation of project progress or team goals.
// return "Give me a fun, quick challenge for team members to complete before the standup (e.g., 'Find an object near you that starts with the letter 'S' to show during standup')";
// } else if (day === 3) { // Wednesday
// return "Pose a thought-provoking or fun question for team members to consider answering during the standup.";
// } else if (day === 4) { // Thursday
// } else if (day === 5) { // Friday