1export function albhed(text, reverse) {
2 const englishSet = "abcdefghijklmnopqrstuvwxyz";
3 const albhedSet = "ypltavkrezgmshubxncdijfqow";
4 function translate(text, from, to) {
5 return [...text]
6 .map((c) => {
10 .join("");
11 }
12 function englishToAlbhed(text) {
13 return translate(
14 translate(text, englishSet.toUpperCase(), albhedSet.toUpperCase()),
17 );
18 }
19 function albhedToEnglish(text) {
20 return translate(
21 translate(text, albhedSet.toUpperCase(), englishSet.toUpperCase()),
3
4// https://api.val.town/v1/express/zzz.ListenTo?val=stevekrouse.whatIsValTown
5export async function ListenTo(req, res) {
6 const { val = "zzz.demoOpenAIGPT4Summary" } = req.query;
7 const url = `https://api.val.town/v1/run/${val.replace("@", "")}`
28 }
29 }
30 async function loadModel(modelName: Model) {
31 if (!_init) {
32 // Initialize the wasm via discussion in https://github.com/dqbd/tiktoken/issues/22
42 return await load((registry as Registry)[models[modelName]]);
43 }
44 async function buildEncoder(modelName: Model) {
45 const model = await loadModel(modelName);
46 return new Tiktoken(model.bpe_ranks, model.special_tokens, model.pat_str);
47 }
48 async function tokenize(text: string, modelName?: Model) {
49 modelName = modelName ?? "gpt-3.5-turbo";
50 const encoder = await buildEncoder(modelName);
1export function pipe<T>(seed: T) {
2 return (...ops: Array<(state: T) => T>) =>
3 ops.reduce((state, action) => action(state), seed);
1import { moveBody } from "https://esm.town/v/adamgonda/moveBody";
2
3export function moveSnake(state) {
4 const { snake } = state;
5 return {
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function postHogAPICapture({ key, event, properties, distinct_id }: {
4 key: string;
5 event: string;
3export let fetchJSON = async (url: string, options?: any) => {
4 //url must return a JSON in string form
5 //this function parses that string into a javascript object
6 let f = await fetch(url, {
7 ...options,
1export function myApi(name) {
2 return "hi " + name;
3}
3// not working yet, didn't manage to affect dynamic value to @me.__state
4
5export const state = function (
6 id: string,
7 defaultValue: { [key: string]: any }
18 return [
19 __state[id],
20 function (newState) {
21 const newStore = {
22 ...__state,
22
23```js
24function updateFeedback(ref) {
25 let feedback = [...document.getElementsByTagName('a')].find(e => e.innerText == 'Feedback')
26 feedback.setAttribute('href', "https://stevekrouse-docfeedbackform.web.val.run/?ref=" + ref)
30```
31
32Finally, you may be wondering why I queue up feedback in `@stevekrouse.docsFeedback`, a private JSON val, and then process it via [`@stevekrouse.formFeedbackAlert`](https://www.val.town/v/stevekrouse.formFeedbackAlert) instead of sending it along to Discord directly in this val. I [tried that originally](https://www.val.town/v/stevekrouse.docFeedbackForm?v=61) but it felt too slow to wait for the API call to Discord before returning the "Thanks for your feedback" message. This is where the `context.waitUntil` method (that Cloudflare workers and Vercel Edge Functions support) would really come in handy – those allow you to return a Response, and then continue to compute. Currently Val Town requires you to stop all compute with the returning of your Response, so the only way to compute afterwards is to queue it up for another val to take over, and that's what I'm doing here.
33
34