27 <head>
28 <title>SQLite Explorer</title>
29 <link rel="preconnect" href="https://fonts.googleapis.com" />
30
31 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32 <link
33 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34 rel="stylesheet"
35 />
1/**
2 * This code creates a geocoder widget similar to the Google Maps API search widget.
3 * It uses React for the frontend, the Cerebras API for LLM-based geocoding,
4 * and Leaflet for displaying the map.
5 */
124 const { query } = await request.json();
125
126 const prompt = `You are a geocoding API. Return up to 5 possible matches.
127 Respond with only the completions, separated by newlines.`;
128
129 try {
130 const response = await fetch("https://api.cerebras.ai/v1/chat/completions", {
131 method: "POST",
132 headers: {
133 "Content-Type": "application/json",
134 "Authorization": `Bearer ${Deno.env.get("CEREBRAS_API_KEY")}`,
135 },
136 body: JSON.stringify({
146
147 if (!response.ok) {
148 throw new Error("Failed to fetch from Cerebras API");
149 }
150
157 });
158 } catch (error) {
159 console.error("Error calling Cerebras API:", error);
160 return new Response(JSON.stringify({ error: "Failed to fetch suggestions" }), {
161 status: 500,
63 const fetchStories = async () => {
64 try {
65 const response = await fetch("/api/stories");
66 if (!response.ok) throw new Error("Failed to fetch dates");
67 const data = await response.json();
77 try {
78 dispatch({ type: "loading", value: true });
79 const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
80 if (!response.ok) throw new Error("Failed to fetch comments");
81 const data = await response.json();
360export default async function(req: Request): Promise<Response> {
361 const url = new URL(req.url);
362 if (url.pathname === "/api/stories") {
363 const storySearch = await hnSearch({
364 search_by_date: true,
381 }
382
383 if (url.pathname === "/api/comments") {
384 const params = url.searchParams;
385 const query = params.get("query") || "";
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
159};
160
161// Google Maps API Key
162const GOOGLE_MAPS_API_KEY = 'AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw';
163
164// Utility Functions
322
323 const script = document.createElement('script');
324 script.src = `https://maps.googleapis.com/maps/api/js?key=${GOOGLE_MAPS_API_KEY}&libraries=places`;
325 script.async = true;
326 script.defer = true;
522 style={{...styles.button, width: '48%', backgroundColor: theme.colors.accent.blue}}
523 onClick={() => {
524 const mapsUrl = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(vet.address + ', Algérie')}`;
525 window.open(mapsUrl, '_blank');
526 }}
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
27 <head>
28 <title>SQLite Explorer</title>
29 <link rel="preconnect" href="https://fonts.googleapis.com" />
30
31 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32 <link
33 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34 rel="stylesheet"
35 />
1* Fork this val to your own profile.
2* 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.
3
38 model: openai("gpt-4o", {
39 baseURL: "https://std-openaiproxy.web.val.run/v1",
40 apiKey: Deno.env.get("valtown"),
41 } as any),
42 messages: [
1/** @jsxImportSource npm:hono@3/jsx */
2import { Unkey } from "npm:@unkey/api@0.26.1";
3import { Ratelimit } from "npm:@unkey/ratelimit@0.4.4";
4import type { Duration } from "npm:@unkey/ratelimit@0.4.4";