3import { zip } from "npm:lodash-es";
4
5export async function dateMeRSS(req: Request) {
6 let { columns, rows } = await sqlite.execute(`select * from datemedocs order by LastUpdated desc limit 20`);
7 const profiles = rows.map(row =>
2import { valTownBlogJSON } from "https://esm.town/v/stevekrouse/valTownBlogJSON";
3
4export async function valTownBlogRSS() {
5 const json = await valTownBlogJSON();
6 return new Response(dataToRSS(
4import stripAnsi from "npm:strip-ansi";
5
6export default async function() {
7 const res = await db.execute(
8 "SELECT author_username, COUNT(*) AS val_count FROM vals GROUP BY author_username ORDER BY 2 DESC LIMIT 10",
3// # New Val Town User (on Clerk) -> Val Town Discord notification
4// Translates one kind of webhook (Clerk) into another (Discord)
5export async function handleDiscordNewUser(req: Request) {
6 // check custom auth secret sent from clerk
7 if (req.headers.get("auth") !== Deno.env.get("clerkNonSensitive"))
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
2
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
12}
13
14function startChat(chatOptions: Omit<ChatCompletionCreateParamsNonStreaming, "messages"> & { system: string } = {
15 max_tokens: 30,
16 model: "gpt-3.5-turbo",
19 const { system, ...options } = chatOptions;
20
21 return async function gpt(strings, ...values) {
22 const openai = await getOpenAI();
23
40}
41
42// Initialize the gpt function with the system message
43const gpt = startChat({ system: "You are New Yorker cartoonist", max_tokens: 200, model: "gpt-4" });
44const answer = await gpt`Draw me cartoon depicting https://www.val.town user in their fighting TypeScript a-ha moment`;
2import { sqlite } from "https://esm.town/v/std/sqlite";
3
4function generateInsertStatements(
5 tableName: string,
6 columns: string[],
20}
21
22export async function sqliteDump(
23 tables?: string[],
24 callback?: (result: string) => string | void | Promise<void>,
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
2
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
14/**
15 * Initiates a chat conversation with OpenAI's GPT model and retrieves the content of the first response.
16 * This function can handle both single string inputs and arrays of message objects.
17 * It supports various GPT models, allowing for flexibility in choosing the model based on the application's needs.
18 *
21 * @returns {Promise<string>} A promise that resolves to the content of the first response from the completion.
22 */
23export async function chat(
24 input: string | Message[],
25 options: Omit<ChatCompletionCreateParamsNonStreaming, "messages"> = {
1# OpenAI ChatGPT helper function
2
3This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
3import { css } from "https://esm.town/v/stevekrouse/sqlite_admin_css";
4
5export async function blob_admin_home() {
6 let blobs = await blob.list();
7 return (
2import { email } from "https://esm.town/v/std/email";
3
4export async function testEmail2(e: {
5 from: string;
6 to: string[];
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",