246 try {
247 const tokens = await github.validateAuthorizationCode(code);
248 const githubUserResponse = await fetch("https://api.github.com/user", {
249 headers: {
250 Authorization: `Bearer ${tokens.accessToken}`
345 const code = c.req.query("code");
346
347 // https://yawnxyz-hncloneluciaoauth.web.val.run/auth/google/callback?state=e1ntsxqPFLaBZe9tXQ7SwwGHJ5Cr2nAvwNtWtQNtRVk&code=4%2F0AQlEd8yAzO8cETotI28YAdDu7kMaWfwsBY6mBLtA3Mz0dO0-REGYfsHQcNsQzw1bE1mNyA&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent
348
349 // verify state
365
366 console.log('trying to get the user info: ', tokens)
367 const userInfoResponse = await fetch("https://openidconnect.googleapis.com/v1/userinfo", {
368 headers: {
369 Authorization: `Bearer ${tokens.accessToken}`
99
100 // Configuration
101 const API_CONFIG = {
102 url: "https://willthereader-openaidefiner.web.val.run",
103 method: "POST",
236 };
237
238 // API response handling
239 async function processApiResponse(response) {
240 const reader = response.body.getReader();
241
278
279 try {
280 console.time("makeApiRequest");
281 const response = await makeApiRequest(selectedText);
282 console.timeEnd("makeApiRequest");
283
284 console.time("processApiResponse");
285 await processApiResponse(response);
286 console.timeEnd("processApiResponse");
287 } catch (error) {
288 store.dispatch({ type: "ERROR", payload: error.message });
463 }
464
465 async function makeApiRequest(text) {
466 console.log(`Preparing to send fetch request for text: "${text}"`);
467 try {
468 const response = await fetch(API_CONFIG.url, {
469 ...API_CONFIG,
470 body: JSON.stringify({ selection: text }),
471 });
477 return response;
478 } catch (error) {
479 console.error("Error making API request:", error);
480 throw new Error("Failed to fetch definition from the server. Please try again.");
481 }
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
6 const { OpenAI } = await import("https://esm.town/v/std/openai");
7 return new OpenAI();
21 const model = await builder();
22 const input = await prompt.format({
23 question: "What is the capital of France?",
24 });
25 const response = await model.call(input);
32// "*",
33// unkey({
34// apiId: "rlns_2AMjVgwwMksmssLVb56LVmkpB56C",
35// }),
36// );
1// This cron emails Hacker News stories from its API every 3 days.
2
3import { email } from "https://esm.town/v/std/email";
9[](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
12
13# TODO
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 />
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"/>