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/$%7Bart_info.art.src%7D?q=openai&page=85&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 1621 results for "openai"(856ms)

r1README.md1 match

@sboesen•Updated 3 months ago
141. Copy this Val and save it as an Email Val (choose Val type in top-right corner of editor)
15
162. Add your Fireworks (or openai API compatible) 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)

cerebrasTemplatemain.tsx2 matches

@stevekrouse•Updated 3 months ago
83 const { messages } = await request.json();
84
85 const { OpenAI } = await import("https://esm.sh/openai");
86 // Cerebras Inference
87 // Very important: do not change this
88 // Keep these comments so we remember not to change this
89 const client = new OpenAI({
90 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
91 baseURL: "https://api.cerebras.ai/v1",

victoriousGreenLynxmain.tsx4 matches

@stevekrouse•Updated 3 months ago
93 const { messages } = await request.json();
94
95 const { OpenAI } = await import("https://esm.town/v/std/openai");
96 const openai = new OpenAI();
97
98 try {
99 const response = await openai.chat.completions.create({
100 model: "gpt-4o-mini",
101 messages: [
109 return Response.json({ message: generatedMessage });
110 } catch (error) {
111 console.error("Error calling OpenAI API:", error);
112
113 if (error.status === 429) {

victoriousGreenLynxREADME.md2 matches

@stevekrouse•Updated 3 months ago
29Use Cerebras for AI on the backend like so:
30
31const { OpenAI } = await import("https://esm.sh/openai");
32const client = new OpenAI({
33 apiKey: "YOUR_CEREBRAS_API_KEY",
34 baseURL: "https://api.cerebras.ai/v1"

masterfulPeachHookwormmain.tsx2 matches

@stevekrouse•Updated 3 months ago
83 const { messages, sassy } = await request.json();
84
85 const { OpenAI } = await import("https://esm.sh/openai");
86 const client = new OpenAI({
87 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
88 baseURL: "https://api.cerebras.ai/v1",

masterfulPeachHookwormREADME.md2 matches

@stevekrouse•Updated 3 months ago
29Use Cerebras for AI on the backend like so:
30
31const { OpenAI } = await import("https://esm.sh/openai");
32const client = new OpenAI({
33 apiKey: "YOUR_CEREBRAS_API_KEY",
34 baseURL: "https://api.cerebras.ai/v1"

knowledgeableTomatoCrawdadREADME.md2 matches

@stevekrouse•Updated 3 months ago
29Use Cerebras for AI on the backend like so:
30
31const { OpenAI } = await import("https://esm.sh/openai");
32const client = new OpenAI({
33 apiKey: "YOUR_CEREBRAS_API_KEY",
34 baseURL: "https://api.cerebras.ai/v1"

knowledgeableTomatoCrawdadmain.tsx2 matches

@stevekrouse•Updated 3 months ago
91 const { messages } = await request.json();
92
93 const { OpenAI } = await import("https://esm.sh/openai");
94 const client = new OpenAI({
95 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
96 baseURL: "https://api.cerebras.ai/v1"

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)

translateToEnglishWithOpenAI1 file match

@shlmt•Updated 4 days ago

testOpenAI1 file match

@stevekrouse•Updated 6 days 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": "*",