1# OpenAI Proxy
2
3This OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openai
2
3// Send a pushover message.
4// token, user, and other opts are as specified at https://pushover.net/api
5export async function pushover({ token, user, message, title, device, ...opts }) {
6 try {
14 });
15
16 const response = await fetch("https://api.pushover.net/1/messages.json", {
17 method: "POST",
18 headers: {
24 if (!response.ok) {
25 const errorData = await response.json();
26 console.error("Pushover API Error:", errorData);
27 throw new Error(`HTTP error! status: ${response.status}`);
28 }
3export async function ShopifyProductSearch(brokerId, first = 20) {
4 // The GraphQL endpoint you're going to query
5 const url = "https://shop.app/web/api/graphql";
6
7 // The GraphQL query
217 };
218
219 // Headers can include things like `Content-Type` and any authorization tokens required by the API
220 const headers = {
221 "Content-Type": "application/json",
2
3/**
4 * API Client for interfacing with the OpenAI API. Uses Val Town credentials.
5 */
6export class OpenAI {
8
9 /**
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 */
20 constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
21 this.rawOpenAIClient = new RawOpenAI({
22 ...options,
23 baseURL: "https://std-openaiproxy.web.val.run/v1",
24 apiKey: Deno.env.get("valtown"),
25 organization: null,
26 });
1# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
2
3Use OpenAI's chat completion API with [`std/openai`](https://www.val.town/v/std/openai). This integration enables access to OpenAI's language models without needing to acquire API keys.
4
5Streaming is not yet supported. Upvote the [HTTP response streaming feature request](https://github.com/val-town/val-town-product/discussions/14) if you need it!
32If these limits are too low, let us know! You can also get around the limitation by using your own keys:
33
341. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
352. Create an [environment variable](https://www.val.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
363. Use the `OpenAI` client from `npm:openai`:
37
1/** @jsxImportSource https://esm.sh/hono@3.9.2/jsx **/
2import { api } from "https://esm.town/v/pomdtr/api";
3import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
4import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
36
37app.get("/", async c => {
38 const { data: vals } = await api(`/v1/search/vals?query=${encodeURIComponent("#bookmarklet")}`);
39
40 const bookmarklets = await Promise.all(
85app.get("/v/:author/:name", async c => {
86 const { author, name } = c.req.param();
87 const { privacy } = await api(`/v1/alias/${author}/${name}`);
88 if (privacy === "private") {
89 return c.notFound();
3const USERNAME = "yieldray"; // <--- Replace with your Github username
4
5const gistList: Array<Gist> = await fetch(`https://api.github.com/users/${USERNAME}/gists`).then((res) => res.json());
6
7app.get("/", (req) => {
5
6const app = new Hono();
7const openai = new OpenAI(Deno.env.get("OPENAI_API_KEY_VOICE"));
8
9class TranscriptionService {
18 return transcription;
19 } catch (error) {
20 console.error('OpenAI API error:', error);
21 throw error;
22 }
368 return c.text(translation);
369 } catch (error) {
370 console.error('OpenAI API error:', error);
371 return c.text('Error occurred during translation', 500);
372 }
395 });
396 } catch (error) {
397 console.error('OpenAI API error:', error);
398 return c.text('Error occurred during speech generation', 500);
399 }
3The app is set up so you can easily have a conversation between two people. The app will translate between the two selected languages, in each voice, as the speakers talk.
4
5Add your OpenAI API Key, and make sure to open in a separate window for Mic to work.
6
7Migrated from folder: Projects/VoiceTranslator/translator
14export async function pipes(sql: string): Promise<Result> {
15 const origin = "https://pipes.turbot.com";
16 const pathname = `/api/latest/user/${user}/workspace/${workspace}/query`;
17
18 const resp = await fetch(`${origin}${pathname}?sql=${encodeURIComponent(sql)}`, {