23/**
4* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
5*/
6export class OpenAI {
89/**
10* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
11*
12* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
14* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
17* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
18* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
19*/
20constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
21this.rawOpenAIClient = new RawOpenAI({
22...options,
23baseURL: "https://std-openaiproxy.web.val.run/v1",
24apiKey: Deno.env.get("valtown"),
25organization: null,
26});
1import { parse } from "https://deno.land/std@0.181.0/flags/mod.ts";
23const ALPHA_VANTAGE_API_KEY = "your_api_key_here"; // Replace with your actual API key
45async function fetchStockData(symbol: string) {
6const apiUrl =
7`https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=${ALPHA_VANTAGE_API_KEY}`;
8const response = await fetch(apiUrl);
9const data = await response.json();
10
renderPoemWidgetJsonmain.tsx2 matches
13timeZone,
14};
15const timeForApi = date.toLocaleTimeString("en-GB", {
16...baseTimeParams,
17hourCycle: "h23",
18});
19const poem = await getPoemForTime(timeForApi);
20const newState = { ...poemWidgetJson };
21newState.layouts.hello_small.layers[0].rows[0].cells[0].text.string = poem;
1This Val accepts a stock symbol and will return current price and intraday price change.
23example: `https://pete-stockapi.web.val.run/symbol=MSFT`
45It's currently using alphavantage free tier API so it's limited to only 25 requests/day. Fork and create your own premium API key for more request.
1// This val creates a publicly accessible kitten image generator using the Val Town image generation API.
2// It supports generating square images with a single dimension parameter or rectangular images with two dimension parameters.
3
FanFicScrapermain.tsx19 matches
11e.preventDefault();
12setLoading(true);
13console.log(`Submitting URL for scraping: ${url}`);
14try {
15const response = await fetch("/scrape", {
22setResult(data);
23} catch (error) {
24console.log(`Error occurred while scraping URL: ${url}. Error details: ${error.message}`);
25setResult({ error: error.message });
26}
40/>
41<button type="submit" disabled={loading}>
42{loading ? "Scraping..." : "Scrape"}
43</button>
44</form>
79async function scrapePage(url) {
80console.log(`Starting to scrape page: ${url}`);
81const apiKey = Deno.env.get("ScrapingBeeAPIkey");
82if (!apiKey) {
83console.log("ScrapingBee API key not found in environment variables");
84throw new Error("ScrapingBee API key not found in environment variables");
85}
86104};
105106console.log(`Sending request to ScrapingBee for URL: ${url} at ${new Date().toISOString()}`);
107const startTime = Date.now();
108try {
109const response = await fetch(
110`https://app.scrapingbee.com/api/v1/?api_key=${apiKey}&url=${
111encodeURIComponent(url)
112}&render_js=false&extract_rules=${encodeURIComponent(JSON.stringify(extractRules))}`,
114115const duration = Date.now() - startTime;
116console.log(`Received response from ScrapingBee at ${new Date().toISOString()}. Duration: ${duration}ms`);
117console.log(`Received response from ScrapingBee for URL: ${url}. Status: ${response.status}`);
118119if (!response.ok) {
120console.log(`Error response from ScrapingBee. Status: ${response.status}`);
121throw new Error(`HTTP error! status: ${response.status}`);
122}
156return result;
157} catch (error) {
158console.log(`Error occurred while scraping URL: ${url}`);
159console.log(`Error details: ${error.message}`);
160console.log(`Error stack: ${error.stack}`);
163}
164165async function getApiKey() {
166const apiKey = Deno.env.get("ScrapingBeeAPIkey");
167if (!apiKey) {
168console.log("ScrapingBee API key not found in environment variables");
169throw new Error("ScrapingBee API key not found in environment variables");
170}
171return apiKey;
172}
173
getBlobAndRenderAsImageREADME.md4 matches
89To easily upload an image to your blob storage, [fork this val](
10getBlobAndRenderAsImage), run it, and enter your API key in the password input.
1112## How it works
2122- The server function calls `blob.get("test.png")`.
23- This `blob.get()` method makes an HTTP request to the Val Town API.
24- The API returns a Response object containing the image data.
25266465- [Blob storage overview in Val Town docs](https://docs.val.town/std/blob/)
66- [Val Town REST API references for blobs](https://docs.val.town/openapi#tag/blobs)
67- [Val Town blob std lib source code](https://www.val.town/v/std/blob)
blob_adminREADME.md1 match
9[](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
1011It 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).
1213# TODO
891. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
redditSearchmain.tsx5 matches
11interface RedditSearchOptions {
12query: string;
13apiKey?: string;
14}
1517export async function redditSearch({
18query,
19apiKey = Deno.env.get("BROWSERBASE_API_KEY"),
20}: RedditSearchOptions): Promise<ThreadResult[]> {
21if (!apiKey) {
22throw new Error("BrowserBase API key is required");
23}
2425const puppeteer = new PuppeteerDeno({ productName: "chrome" });
26const browser = await puppeteer.connect({
27browserWSEndpoint: `wss://connect.browserbase.com?apiKey=${apiKey}&enableProxy=true`,
28ignoreHTTPSErrors: true,
29});