1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function openaiUploadFile({ key, data, filename = "data.json", purpose = "assistants" }: {
4 key: string;
5 data: any;
1export default function(req) {
2 const url = new URL(req.url);
3 if (url.pathname == "/val-town") {
7 * @param val Define which val should open. Defaults to the root reference.
8 */
9export function modifyResponse(
10 res: Response,
11 { val, style }: { val?: ValRef; style?: string } = {},
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const SAMPLE_JOKE = {
6 "setup": "What do you call a group of disorganized cats?",
3import { TocGroup, TocItem } from "https://esm.town/v/pomdtr/val_town_by_example_toc";
4
5export function IndexItem(props: { item: TocItem }) {
6 return (
7 <li>
17}
18
19export function IndexGroup(props: { group: TocGroup }) {
20 return (
21 <li class="md:w-1/4">
30}
31
32export function Example({ example }: { example: Example }) {
33 return (
34 <div>
96}
97
98export function Snippet(props: {
99 firstOfFile: boolean;
100 lastOfFile: boolean;
6const username = "ccorcos";
7
8export default async function(interval: Interval) {
9 const url = "https://news.ycombinator.com/threads?id=" + username;
10 const html = await fetchText(url);
6};
7
8export function extractDependencies(code: string) {
9 const esmUrlRegex = /https:\/\/esm\.town\/v\/([a-zA-Z_$][0-9a-zA-Z_$]*)\/([a-zA-Z_$][0-9a-zA-Z_$]*)/g;
10
21}
22
23export async function searchReferences(val: ValRef) {
24 const esmUrl = `https://esm.town/v/${val.author}/${val.name}`;
25 const { data: vals } = await api(`/v1/search/vals?query=${encodeURIComponent(esmUrl)}`, {
3import { openaiUploadFile } from "https://esm.town/v/stevekrouse/openaiUploadFile?v=15";
4
5export async function openaiFineTuneData({ key, data, model }: {
6 key: string;
7 data: any;
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function openaiUploadFile({ key, data, purpose = "assistants" }: {
4 key: string;
5 data: any;
26}
27
28export function extractSnippets(content: string): ExampleSnippet[] {
29 // Separate the code into snippets.
30 const snippets: ExampleSnippet[] = [];
86}
87
88export async function parseExample(author: string, name: string): Promise<Example> {
89 let { code } = await api<{ code: string }>(`/v1/alias/${author}/${name}`);
90 // Substitute $std/ with the full import url
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": "*",