23
24// UTILS
25function generateJWT(userId: string) {
26 return new SignJWT({ userId }).setProtectedHeader({ alg: "HS256" }).sign(SECRET);
27}
28function verifyJWT(token: string) {
29 return jwtVerify(token, SECRET);
30}
31function generateRandomString() {
32 return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
33}
1// View at https://andreterron-htmlExample.web.val.run?name=Andre
2export default async function(req: Request): Promise<Response> {
3 const query = new URL(req.url).searchParams;
4
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.
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">,
22 });
23 };
24 async function getFilms() {
25 const totalPages = await getTotalPages();
26 const films = [];
1// View at https://andreterron-htmlExample.web.val.run?name=Andre
2export default async function(req: Request): Promise<Response> {
3 const query = new URL(req.url).searchParams;
4
6import ValtownDriver from "https://esm.town/v/pomdtr/libsqlstudio_driver";
7
8function App() {
9 const driver = useMemo(() => {
10 return new ValtownDriver();
8} from "https://esm.sh/@libsqlstudio/gui/driver";
9
10export function transformRawResult(raw: ResultSet): DatabaseResultSet {
11 const headerSet = new Set();
12
1import { capturePostHogEvent } from "https://esm.town/v/ianvph/capturePostHogEvent";
2
3export default async function(req: Request): Promise<Response> {
4 if (req.method !== "POST") {
5 return Response.json({ ok: "only post request" });
7 const body = await response.text();
8 const $ = cheerio.load(body);
9 const boeingElements = $("h5").filter(function() {
10 return $(this).text().includes("Boeing");
11 });
12 let aircraft = [];
13 boeingElements.each(function() {
14 aircraft.push($(this).text());
15 });
17};
18
19async function getFormData(req: Request) {
20 const data = await req.formData();
21 const aircraft = ("" + data.get("aircraft")).replace(" ", "");
34}
35
36function displayPlaneName(formData) {
37 if (formData && formData.boeingAircraft && formData.boeingAircraft.length > 0) {
38 return "💀 " + formData.boeingAircraft[0] + " 📉";
41}
42
43export default async function(req: Request) {
44 return new Response(
45 render(
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": "*",