Avatar

wilt

Joined January 12, 2023
Likes
49
maxm avatar
maxm
emojiInstantSearch
HTTP
Forked from maxm/simpleWikipediaInstantSearch
2
karkowg avatar
karkowg
fav
HTTP
fav Turn an emoji into an SVG favicon. Inspired by Lea's tweet . Usage <link rel="icon" href="https://karkowg-fav.web.val.run?emoji=🧨" /> Alternatively, you can use Wes Bos' fav.farm .
1
dglazkov avatar
dglazkov
discordBot
Script
A simple Discord Bot scaffolding, a slight rev on the one in the valtown guide . The discordBot function takes in an object where each key is a Discord command and the value is a function to handle the command. If the function returns a Promise , it will be handled as a deferred interaction with a followup message . Usage: import { discordBot } from "https://esm.town/v/dglazkov/discordBot"; const echo = async (data) => { await new Promise((r) => setTimeout(r, 5000)); return { type: 4, data: { content: data.data.options[0].value, }, }; }; export default discordBot({ ping: () => ({ type: 4, data: { content: `Pong! It is ${new Date()}`, }, }) echo, });
2
jdan avatar
jdan
blobImages
HTTP
Forked from jdan/emojiGuessr
2
devonzuegel avatar
devonzuegel
isMyWebsiteDown
Cron
Forked from healeycodes/isMyWebsiteDown
1
jdan avatar
jdan
atlas
HTTP
An interactive, runnable TypeScript val by jdan
1
saolsen avatar
saolsen
connect4_site
HTTP
Play connect4. Write agents that play connect4. Battle your agents against other agents. It's fun.
3
stevekrouse avatar
stevekrouse
blob_admin
HTTP
Forked from stevekrouse/sqlite_admin
19
xkonti avatar
xkonti
gptMemoryManager
Script
A simple Rest API that allows for you GPT to save and recall snippets of data (memories). You can read my blog post explaining it in detail here: xkonti.tech Demonstration First conversation: What GPT sent do the API: { "name": "Life Essence and Biological Processes", "description": "Explore the role of life essence in enabling biological processes, with a focus on how dimensional interference, particularly from the Incorporeal dimension, facilitates the existence of these processes. This exploration should delve into the complex interplay between the Physical and Incorporeal dimensions, examining how life essence acts as a crucial element in the emergence and sustenance of life in the Physical dimension.", "summary": "Expanding on the role of life essence in biological processes, emphasizing the interaction between the Physical and Incorporeal dimensions.", "reason": "To deepen the understanding of how life essence, influenced by dimensional interference, is essential for biological processes in the novel's universe." } Separate conversation somewhere in the future: Setup There are several steps to set up the API: deploy and configure the API create the API key for your GPT add an action for the API in you GPT add prompt section to your GPT so that it can use it properly Deploying the API on Val Town Deploy your own memory API. You can fork the following Val to do it: https://www.val.town/v/xkonti/memoryApiExample In the code configure the appropriate values: apiName the name of your API - used in the Privacy Policy (eg. Memory API ) contactEmail - the email to provide for contact in the Privacy Policy (eg. some@email.com ) lastPolicyUpdate - the date the Privacy Policy was last updated (eg. 2023-11-28 ) blobKeyPrefix - the prefix for the blob storage keys used by your API - more info below (eg. gpt:memories: ) apiKeyPrefix - the prefix for you API Keys secrets - more info below (eg. GPTMEMORYAPI_KEY_ ) Create API keys The Memory API is designed to serve multiple GPTs at the same time. Each GPT should have it's own unique name and API key . The name is used for identifying the specific GPT and appended to both: blobKeyPrefix - to maintain separate memory storage from other GPTs apiKeyPrefix - to maintain separate API key for each GPT Please pick a unique alphanumeric name for your GPT. For example personaltrainer . Generate some alphanumeric API key for your GPT. For example Wrangle-Chapped-Monkhood4-Domain-Suspend Add a new secret to your Val.town secrets storage. The Key should be the picked name prefixed by apiKeyPrefix . Using the default it would be GPTMEMORYAPI_KEY_personaltrainer . The value of the secret should be the API key itself. The memories of the GPT will be stored in the blob storage under the key blobKeyPrefix + name , for example: gpt:memories:personaltrainer . Adding GPT action Add a new action in your GPT. Get the OpenAPI spefication by calling the /openapi endpoint of your API Change all <APIURL> instances within the specification to the url of your deployed API. For example https://xkonti-memoryapiexample.web.val.run Set the authentication method to basic and provide a base64 encoded version of the <name>:<apiKey> . For example: personaltrainer:Wrangle-Chapped-Monkhood4-Domain-Suspend -> cGVyc29uYWx0cmFpbmVyOldyYW5nbGUtQ2hhcHBlZC1Nb25raG9vZDQtRG9tYWluLVN1c3BlbmQ= Add the link to the privacy policy, which is the /privacy endpoint of your API. For example: https://xkonti-memoryapiexample.web.val.run/privacy Adding the prompt section To make your GPT understand the usage of your new action you should include usage instruction in your prompt. Here's an example of such instructions section: # Long-term memory At some point the user might ask you to do something with "memory". Things like "remember", "save to memory", "forget", "update memory", etc. Please use corresponding actions to achieve those tasks. User might also ask you to perform some task with the context of your "memory" - in that case fetch all memories before proceeding with the task. The memories should be formed in a clear and purely informative language, void of unnecessary adjectives or decorative language forms. An exception to that rule might be a case when the language itself is the integral part of information (snippet of writing to remember for later, examples of some specific language forms, quotes, etc.). Structure of a memory: - name - a simple name of the memory to give it context at a glance - description - a detailed description of the thing that should be remembered. There is no length limit. - summary - a short summary of the memory. This should be formed in a way that will allow for ease of understanding which memories to retrieve in full detail just by reading the list of summaries. If there are some simple facts that have to be remembered and are the main point of the memory they should be included in the summary. The summary should also be written in a compressed way with all unnecessary words skipped if possible (more like a set of keywords or a Google Search input). - reason - the reason for the remembering - this should give extra information about the situation in which the memory was requested to be saved. The memory accessed through those actions is a long-term memory persistent between various conversations with the user. You can assume that there already are many memories available for retrieval. In some situations you might want to save some information to your memory for future recall. Do it in situations where you expect that some important details of the conversation might be lost and should be preserved. Analogously you can retrieve memories at any point if the task at hand suggests the need or there isn't much information about the subject in your knowledge base.
3
tmcw avatar
tmcw
oldfashioned
HTTP
@jsxImportSource npm:hono/jsx
4
clayway avatar
clayway
callGoogleSheetsAPI
Script
Forked from mattx/gsheet_call
2
xkonti avatar
xkonti
ntfy
Script
Allows to publish a ntfy notification using a fluent builder configuration. Usage example import { ntfy } from "https://esm.town/v/xkonti/ntfy"; await ntfy() .toServer(Deno.env.get("ntfyServer")) .asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword")) .toTopic("testing") .withMessage("Hello there!") .withTitle("First test") .withViewAction("My website", "https://xkonti.tech") .withTags("package", "val-town") .withPriority("high") .publish(); ⚠️ For the notification to be sent it needs to be published ( publish function). Use helper Executes specified functions that can modify the notification. Can be used to streamline authentication, apply common operations, etc. import { ntfy } from "https://esm.town/v/xkonti/ntfy"; const toMyNtfyServer = (builder: ReturnType<typeof ntfy>) => { builder .toServer(Deno.env.get("ntfyServer")) .asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword")); }; await ntfy() .use(toMyNtfyServer) .toTopic('home-automation') .withMessage('You left the front door open') .publish(); You can pass it multiple functions. Functions toServer(url) - optional Specifies a server that the notification will be sent do. By default it's https://ntfy.sh . asUser(user, password) - optional Authenticates with the user and password. Please use ValTown's secrets for this. await ntfy() .asUser('user123', '12345') ... usingToken(token) - optional Authenticates using the provided token. Please use ValTown's secrets for this. await ntfy() .usingToken('some-token') ... toTopic(topic) - required Specifies which topic to publish the message to. await ntfy() .toTopic('home-automation') ... withMessage(message, markdown) - required Specifies the main message of the notification. You can also flag it as markdown by passing true as a second argument. By default markdown is false . await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') ... await ntfy() .toTopic('home-automation') .withMessage('Your garage is **flooding**!', true) ... withTitle(title) - optional Sets the title of the notification. await ntfy() .toTopic('home-automation') .withTitle('Garage') .withMessage('You left the front door open') ... withPriority(priority) - optional Sets the priority of the notification. Possible from lowest to highest priority: min , low , default , high , max await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withPriority('high') ... Alternatively you can use dedicated functions: .withMinPriority() , .withLowPriority() , .withDefaultPriority() , .withHighPriority() , .withMaxPriority() await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withHighPriority() ... withTags(...tags) - optional Sets tags of the notification. This overrides any previously existing tags. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withTags('door', 'safety') ... withDelay(delay) - optional Sets the delay for notification delivery. Read ntfy docs for more info. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withDelay('tomorrow, 10am') ... withViewAction(label, url, clear?) - optional Adds an action button that opens a website or app when tapped. label - Label of the action button in the notification url - URL to open when action is tapped clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withViewAction('View Val', 'https://www.val.town/v/xkonti/ntfy') ... withBroadcastAction(label, intent?, extras?, clear?) - optional Adds an action button that sends an Android broadcast intent when tapped. label - Label of the action button in the notification intent - Android intent name, default is io.heckel.ntfy.USER_ACTION extras - Android intent extras. clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withBroadcastAction('Selfie', 'Take picture', { 'cmd': 'pic' }) ... withHtmlAction(label, url, method?, headers?, body?, clear?) - optional Adds an action button that sends a HTTP request when tapped. label - Label of the action button in the notification url - URL to which the HTTP request will be sent method - HTTP method to use for request, default is POST headers - HTTP headers to pass in request. body - HTTP body as a string clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withHtmlAction( 'Self-destruct', 'https://self.destruct/initiate', 'POST', { 'Authentication': 'Bearer 123' }, '{"countdown":60}' ) ... withClickUrl(url) - optional Makes the notification open the specified URL when clicked (tapped). withRawAttachment(filename, filedata) - optional Attached a file to the notification. Only one file can be attached. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withRawAttachment('todo.txt', 'Nothing!') ... withUrlAttachment(url) - optional Attaches a file that is hosted elsewhere (URL). withIcon(url) - optional Sets an icon for the notification. viaEmail(email) - optional Sends the notification via email instead. viaPhoneCall(number) - optional Sends the notification via a phone call . The number defaults to yes , which makes it use the first phone number defined on your ntfy account. withoutCache() - optional Disables the cache for the notification. Read the docs on caching for more info. withoutFirebase() - optional Disables Firebase forwarding for the notification. Read the docs on Firebase for more info. withUnifiedPush() - optional Indicates intent of using the Unified Push for the notification. Read the docs on Unified Push for more info.
6
fil avatar
fil
beckerBarley
HTTP
Becker’s Barley trellis SSR chart with Observable Plot This chart is rendered server-side by val.town, using Observable Plot, from data loaded from the GitHub API. For a more complete example, see https://www.val.town/v/fil.earthquakes. For information on this chart, see https://observablehq.com/@observablehq/plot-barley-trellis.
6
fil avatar
fil
earthquakes
HTTP
Earthquake map 🌏 This val loads earthquake data from USGS, a topojson file for the land shape, and supporting libraries. It then creates a map and save it as a SVG string. The result is cached for a day. Note that we must strive to keep it under val.town’s limit of 100kB, hence the heavy simplification of the land shape. (For a simpler example, see becker barley .) | | | |-----|-----| | Web page | https://fil-earthquakes.web.val.run/ | | Observable Plot | https://observablehq.com/plot/ | | linkedom | https://github.com/WebReflection/linkedom | | topojson | https://github.com/topojson/topojson | | earthquakes | https://earthquake.usgs.gov | | world | https://observablehq.com/@visionscarto/world-atlas-topojson | | css | https://milligram.io/ |
6
karfau avatar
karfau
getRaw
Script
A helper to get the raw data of a val, using the very nice implementation from @pomdtr.raw . Usage: https://www.val.town/v/karfau.test_getRaw Also look at @karfau.rawUrl to just get the raw url of another val inside a val.
3
zackoverflow avatar
zackoverflow
minizod
Script
minizod Tiny Zod implementation. Why Zod is a dense library, and its module structure (or lack thereof) makes it difficult for bundlers to tree-shake unused modules . Additionally, using Zod in vals requires the await import syntax which means having to wrap every schema in a Promise and awaiting it. This is extremely annoying. So this is a lil-tiny-smol Zod meant for use in vals. A noteworthy use-case is using minizod to generate tyep-safe API calls to run vals outside of Val Town (such as client-side). Type-safe API call example We can use minizod to create type safe HTTP handlers and generate the corresponding code to call them using Val Town's API, all in a type-safe manner. First, create a schema for a function. The following example defines a schema for a function that takes a { name: string } parameter and returns a Promise<{ text: string }> . const minizodExampleSchema = () => @zackoverflow.minizod().chain((z) => z .func() .args(z.tuple().item(z.object({ name: z.string() }))) .ret(z.promise().return(z.object({ text: z.string() }))) ); With a function schema, you can then create an implementation and export it as a val: const minizodExample = @me.minizodExampleSchema().impl(async ( { name }, ) => ({ text: `Hello, ${name}!` })).json() In the above example, we call .impl() on a function schema and pass in a closure which implements the actual body of the function. Here, we simply return a greeting to the name passed in. We can call this val, and it will automatically parse and validate the args we give it: // Errors at compile time and runtime for us! const response = @me.minizodExample({ name: 420 }) Alternatively, we can use the .json() function to use it as a JSON HTTP handler: const minizodExample = @me.minizodExampleSchema().impl(async ( { name }, ) => ({ text: `Hello, ${name}!` })).json() // <-- this part We can now call minizodExample through Val Town's API. Since we defined a schema for it, we know exactly the types of its arguments and return, which means we can generate type-safe code to call the API: let generatedApiCode = @zackoverflow.minizodFunctionGenerateTypescript( // put your username here "zackoverflow", "minizodExample", // put your auth token here "my auth token", @me.minizodExampleSchema(), ); This generates the following the code: export const fetchMinizodExample = async ( ...args: [{ name: string }] ): Promise<Awaited<Promise<{ text: string }>>> => await fetch(`https://api.val.town/v1/run/zackoverflow.minizodExample`, { method: "POST", body: JSON.stringify({ args: [...args], }), headers: { Authorization: "Bearer ksafajslfkjal;kjf;laksjl;fajsdf", }, }).then((res) => res.json());
5