19 <title>Hello World</title>
20 <style>
21 @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600&display=swap');
22
23 body {
1// This HTTP val responds with "Hello, world!" in JSON format.
2// It leverages the Web API which provides Request and Response objects.
3// No external libraries or other dependencies are necessary.
4
1Find comments on HN (powered by [Algolia](https://hn.algolia.com/api)), extract content and return a streaming markdown summary (powered by [Substrate](https://substrate.run)).
2
3The RAG portion of this is 34 lines of Substrate code. Twitter thread walkthrough: https://x.com/vprtwn/status/1812844236401762513
4
5🪩 To fork, [sign up for Substrate](https://substrate.run/signin) to get your own API key and $50 free credits.
5import { zodToJsonSchema } from "npm:zod-to-json-schema";
6
7const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
8
9// search for HN comments using https://hn.algolia.com/api
10const query = "langchain";
11const searchResults = await hnSearch({
28 new ComputeJSON({
29 prompt: `Summarize this comment and how it relates to the topic: ${query}
30 Use "negative" sentiment for posts about API, abstraction, documentation, tutorial, general quality, slowness, or performance issues.
31 COMMENT: ${JSON.stringify(hit)}`,
32 json_schema: zodToJsonSchema(commentInfo),
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
11
12<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
5import { zodToJsonSchema } from "npm:zod-to-json-schema";
6
7const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
8
9// search for HN comments using https://hn.algolia.com/api
10const query = "rust";
11const searchResults = await hnSearch({
32 new ComputeJSON({
33 prompt: `Summarize this comment and how it relates to the topic: ${query}
34 Use "negative" sentiment for posts about API, abstraction, documentation, tutorial, general quality, slowness, or performance issues.
35 COMMENT: ${JSON.stringify(hit)}`,
36 json_schema: zodToJsonSchema(commentInfo),
1Find comments on HN (powered by [Algolia](https://hn.algolia.com/api)), extract content and return a streaming markdown summary (powered by [Substrate](https://substrate.run)).
2
3The RAG portion of this is 34 lines of Substrate code. Twitter thread walkthrough: https://x.com/vprtwn/status/1812844236401762513
4
5🪩 To fork, [sign up for Substrate](https://substrate.run/signin) to get your own API key and $50 free credits.
147 role: "system",
148 content:
149 `Act as an expert software engineer. Always use best practices. Your response should start with \`\`\`ts and end with \`\`\`. Start your response with a comment explaining how your approach will work, what libraries or API calls you will use, and any tradeoffs you're making. Then write the code in a consise way, the simplest way to achieve the goal, though you can add some inline comments to explain your reasoning (not for every line, but for major groups of lines). Don't use any environment variables unless strictly necessary, for example use APIs that don't require a key, prefer internal function imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno functions where possible. The val should create a "export default async function main() {" which is the main function that gets executed, without any arguments. Don't return a Response object, just return a plain Javascript object, array, or string. Unless specified, don't add error handling, make sure that errors bubble up to the caller.`,
150 },
151 {
4const app = new Hono();
5
6const WEATHER_API_KEY = Deno.env.get('WEATHER_API_KEY'); // Replace with your actual weather API key
7const BASE_URL = "https://api.openweathermap.org/data/2.5/weather";
8
9app.get("/", async (c) => {
10 const response = await fetch(
11 `${BASE_URL}?q=Brooklyn&units=metric&appid=${WEATHER_API_KEY}`
12 );
13 const weatherData = await response.json();
13## Authentication
14
15Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
16
17## Todos / Plans