Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Burl%7D?q=openai&page=89&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=openai

Returns an array of strings in format "username" or "username/projectName"

Found 1653 results for "openai"(1555ms)

emailValHandlermain.tsx16 matches

@charmaine•Updated 3 months ago
5// main controller function
6export async function emailValHandler(receivedEmail) {
7 const openaiUrl = "https://api.openai.com/v1/chat/completions";
8 const apiKey = Deno.env.get("OPENAI_API_KEY"); // replace this entire line with your OpenAI API key as a string, e.g., "sk-123..." or use environment variable: https://docs.val.town/reference/environment-variables/
9 const model = "gpt-4o-mini";
10
11 if (!apiKey) {
12 throw new Error(
13 "OPENAI_KEY environment variable is not set. Please set it or replace this line with your API key.",
14 );
15 }
35 const prompt = generatePrompt(receivedEmail, pdfTexts, emailText);
36
37 // step 4: send prompt to openai
38 const openaiResponse = await sendRequestToOpenAI(prompt, openaiUrl, apiKey, model);
39
40 // log the openai response
41 console.log("openai response:", openaiResponse);
42
43 // step 5: send the response back via email
44 await sendResponseByEmail(receivedEmail.from, openaiResponse);
45
46 console.log("response email sent.");
97}
98
99// helper function to generate a prompt for openai
100function generatePrompt(email, pdfTexts, emailText) {
101 // extract the first name from the 'from' field if it exists
121}
122
123// helper function to send a request to openai
124async function sendRequestToOpenAI(prompt, openaiUrl, apiKey, model) {
125 try {
126 // prepare the openai messages payload
127 const messages = [
128 {
142 };
143
144 // send the request to openai
145 const response = await fetch(openaiUrl, {
146 method: "POST",
147 body: JSON.stringify(body),
154 // parse the response
155 const data = await response.json();
156 return data.choices[0]?.message?.content || "no response from openai.";
157 } catch (err) {
158 console.error("error in sendRequestToOpenAI:", err);
159 return "error processing your request.";
160 }

emailValHandlerREADME.md2 matches

@charmaine•Updated 3 months ago
6
7This script allows you to:
8- Send emails to OpenAI. The text will be treated as the prompt
9- Parse PDF attachments and include their contents in the AI's analysis.
10- Get response directly to your inbox.
141. Copy this Val and save it as an Email Val (choose Val type in top-right corner of editor)
15
162. Add your OpenAI API key to line 8 (or use an environment variable: https://docs.val.town/reference/environment-variables/)
17
183. Copy the email address of the Val (click 3 dots in top-right > Copy > Copy email address)

cerebrasTemplateREADME.md2 matches

@stevekrouse•Updated 3 months ago
35Use Cerebras for AI on the backend like so:
36
37const { OpenAI } = await import("https://esm.sh/openai");
38const client = new OpenAI({
39 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
40 baseURL: "https://api.cerebras.ai/v1"

emailValHandlerREADME.md1 match

@martinbowling•Updated 3 months ago
19
202. Set up the required environment variables:
21 - OPENAI_API_KEY: Your OpenAI API key
22 - MD_API_KEY: Your API key for the markdown extraction service (optional)
23

ALPHANUMERIC_TEXT_TOO_LONGmain.tsx3 matches

@roysarajit143•Updated 3 months ago
71 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
72 try {
73 const { OpenAI } = await import("https://esm.town/v/std/openai");
74 const openai = new OpenAI();
75
76 const { messages } = await request.json();
77
78 const completion = await openai.chat.completions.create({
79 messages: messages,
80 model: "gpt-4o-mini",

aiEmailAssistantmain.tsx16 matches

@simplescraper•Updated 3 months ago
5// main controller function
6export async function emailValHandler(receivedEmail) {
7 const openaiUrl = "https://api.openai.com/v1/chat/completions";
8 const apiKey = Deno.env.get("OPENAI_KEY"); // replace this entire line with your OpenAI API key as a string, e.g., "sk-123..." or use environment variable: https://docs.val.town/reference/environment-variables/
9 const model = "gpt-4o-mini";
10
11 if (!apiKey) {
12 throw new Error(
13 "OPENAI_KEY environment variable is not set. Please set it or replace this line with your API key.",
14 );
15 }
35 const prompt = generatePrompt(receivedEmail, pdfTexts, emailText);
36
37 // step 4: send prompt to openai
38 const openaiResponse = await sendRequestToOpenAI(prompt, openaiUrl, apiKey, model);
39
40 // log the openai response
41 console.log("openai response:", openaiResponse);
42
43 // step 5: send the response back via email
44 await sendResponseByEmail(receivedEmail.from, openaiResponse);
45
46 console.log("response email sent.");
97}
98
99// helper function to generate a prompt for openai
100function generatePrompt(email, pdfTexts, emailText) {
101 // extract the first name from the 'from' field if it exists
121}
122
123// helper function to send a request to openai
124async function sendRequestToOpenAI(prompt, openaiUrl, apiKey, model) {
125 try {
126 // prepare the openai messages payload
127 const messages = [
128 {
142 };
143
144 // send the request to openai
145 const response = await fetch(openaiUrl, {
146 method: "POST",
147 body: JSON.stringify(body),
154 // parse the response
155 const data = await response.json();
156 return data.choices[0]?.message?.content || "no response from openai.";
157 } catch (err) {
158 console.error("error in sendRequestToOpenAI:", err);
159 return "error processing your request.";
160 }

aiEmailAssistantREADME.md2 matches

@simplescraper•Updated 3 months ago
6
7This script allows you to:
8- Send emails to OpenAI. The text will be treated as the prompt
9- Parse PDF attachments and include their contents in the AI's analysis.
10- Get response directly to your inbox.
141. Copy this Val and save it as an Email Val (choose Val type in top-right corner of editor)
15
162. Add your OpenAI API key to line 8 (or use an environment variable: https://docs.val.town/reference/environment-variables/)
17
183. Copy the email address of the Val (click 3 dots in top-right > Copy > Copy email address)

openaiproxyREADME.md2 matches

@charmaine•Updated 3 months ago
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
4
5# Usage Note

openaiproxymain.tsx8 matches

@charmaine•Updated 3 months ago
1import { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";
2import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
3import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";
4import { RateLimit } from "npm:@rlimit/http";
5const client = new OpenAIUsage();
6
7const allowedPathnames = [
42
43 // Proxy the request
44 const url = new URL("." + pathname, "https://api.openai.com");
45 url.search = search;
46
47 const headers = new Headers(req.headers);
48 headers.set("Host", url.hostname);
49 headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`);
50 headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG"));
51
52 const modifiedBody = await limitFreeModel(req, user);
63 });
64
65 const openAIRes = await fetch(url, {
66 method: req.method,
67 headers,
71
72 // Remove internal header
73 const res = new Response(openAIRes.body, openAIRes);
74 res.headers.delete("openai-organization");
75 return res;
76}

easyAQIREADME.md1 match

@svbasi•Updated 3 months ago
126. Uses EPA's ranking to classify the severity of the score (ie "Unhealthy for Sensitive Groups")
13
14It uses blob storage to cache the openai location id for your location string to skip a couple steps for the next time.
15
16## Example usage

translateToEnglishWithOpenAI1 file match

@shlmt•Updated 1 week ago

testOpenAI1 file match

@stevekrouse•Updated 1 week ago
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",