5
6const MODELS = ["llama3.1-8b", "llama3.1-70b"];
7function App() {
8 const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
9 const [edits, setEdits] = useState<Array<{ id: number; content: string }>>(
125}
126
127function client() {
128 createRoot(document.getElementById("root")).render(<App />);
129}
133}
134
135async function server(request: Request): Promise<Response> {
136 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
137 const { messages, model } = await request.json();
5const MODEL = "claude-3-sonnet-20240229";
6
7function applyDiffs(html, diffs) {
8 console.log("Applying diffs. Initial HTML:", html);
9 console.log("Diffs to apply:", diffs);
54}
55
56function parseHTMLFromResponse(content) {
57 const htmlMatch = content.match(/```html\s*([\s\S]*?)\s*```/);
58 console.log("Parsed HTML from response:", htmlMatch && htmlMatch[1] ? htmlMatch[1].trim() : null);
60}
61
62function parseDiffsFromResponse(content) {
63 try {
64 const jsonMatch = content.match(/\{[\s\S]*\}/);
72
73
74function App() {
75 const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
76 const [edits, setEdits] = useState<Array<{ id: number; content: string }>>([]);
200}
201
202function client() {
203 createRoot(document.getElementById("root")).render(<App />);
204}
208}
209
210async function server(request: Request): Promise<Response> {
211 if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
212 const { Anthropic } = await import("https://esm.sh/@anthropic-ai/sdk@0.17.1");
6import { JSDOM } from 'npm:jsdom';
7
8// Function to fetch HTML from a URL and remove <style> and <script> tags
9export async function fetchHtml(url, removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
10 try {
11 const response = await fetch(url);
22}
23
24// Function to use Cheerio to select text from the html, and attempts to clean it a bit
25export function selectHtml(html, selector = "h1", removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
26 const $ = cheerio.load(html); // Load the cleaned HTML into Cheerio
27 $(removeSelectors).remove(); // Remove unwanted tags
37}
38
39// Function to convert HTML to Pug using html2pug
40export function convertHtmlToPug(html, options = { tabs: true }) {
41 const pug = html2pug(html, options);
42 return pug;
59}
60
61export function convertHtmlToMarkdown(htmlStr: string, options?: ConversionOptions): string {
62 const dom = new JSDOM(htmlStr);
63 const markdown = semanticMarkdown(htmlStr, { ...options, overrideDOMParser: new dom.window.DOMParser() });
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3
4export async function dailyDadJoke() {
5 let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6 return email({
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "ZΓΌrich, Schweiz"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
16const FOODS = ["π", "π", "π₯", "π", "π£"];
17
18function App() {
19 const [pet, setPet] = useState(null);
20 const [loading, setLoading] = useState(true);
77}
78
79function client() {
80 createRoot(document.getElementById("root")).render(<App />);
81}
85}
86
87async function server(request: Request): Promise<Response> {
88 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
89 const SCHEMA_VERSION = 1;
138}
139
140async function getPet() {
141 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
142 const SCHEMA_VERSION = 1;
164}
165
166async function updatePet(action) {
167 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
168 const SCHEMA_VERSION = 1;
1import { sqlite as valtown_sqlite } from "https://esm.town/v/std/sqlite";
2
3export async function migrate(
4 sqlite: typeof valtown_sqlite,
5 key: string,
69};
70
71function App() {
72 const [grid, setGrid] = useState(initialGrid);
73 const [moves, setMoves] = useState([]);
354}
355
356function client() {
357 createRoot(document.getElementById("root")).render(<App />);
358}
359if (typeof document !== "undefined") { client(); }
360
361async function server(request: Request): Promise<Response> {
362 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
363 const SCHEMA_VERSION = 1
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export async function getWeather(location: string): Promise<WeatherResponse> {
4 return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}
1## Get Weather
2
3Simple function to get weather data from the free [wttr.in](https://wttr.in/:help) service.
4
5```ts