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/$%7Bsuccess?q=openai&page=84&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 1616 results for "openai"(1095ms)

emailValHandlermain.tsx22 matches

@martinbowling•Updated 3 months ago
20
212. Set up the required environment variables:
22 - OPENAI_API_KEY: Your OpenAI API key
23 - MD_API_KEY: Your API key for the markdown extraction service (optional)
24
60// Main controller function
61export default async function emailValHandler(receivedEmail) {
62 const openaiUrl = "https://api.openai.com/v1/chat/completions";
63 const openaiKey = Deno.env.get("OPENAI_API_KEY");
64 const mdApiKey = Deno.env.get("MD_API_KEY");
65 const model = "o1-2024-12-17";
66
67 if (!openaiKey) {
68 throw new Error("OPENAI_KEY environment variable is not set.");
69 }
70
76
77 // Step 2: Transform the email prompt using the prompt transformer
78 const transformedPrompt = await transformPrompt(receivedEmail.text, openaiUrl, openaiKey, model);
79
80 // Step 3: Process different types of content
81 const { pdfTexts, imageAnalysis } = await processAttachments(attachments, openaiKey, transformedPrompt);
82 const websiteMarkdown = await extractWebsiteMarkdown(links, mdApiKey);
83
91 );
92
93 // Step 5: Send to OpenAI and get response
94 const openaiResponse = await sendRequestToOpenAI(finalPrompt, transformedPrompt, openaiUrl, openaiKey, model);
95
96 // Step 6: Send response email
97 await sendResponseByEmail(receivedEmail.from, openaiResponse);
98 console.log("Response email sent.");
99}
179async function analyzeImage(imageAttachment, apiKey, transformedPrompt) {
180 try {
181 const response = await fetch("https://api.openai.com/v1/chat/completions", {
182 method: "POST",
183 headers: {
221
222// Transform the original prompt using the prompt transformer
223async function transformPrompt(emailText, openaiUrl, apiKey, model) {
224 const promptTransformerText =
225 `You are an AI assistant tasked with transforming user queries into structured research or information requests. Your goal is to take a simple query and expand it into a comprehensive research objective with specific formatting requirements.
290 };
291
292 const response = await fetch(openaiUrl, {
293 method: "POST",
294 body: JSON.stringify(body),
301 const data = await response.json();
302 if (data.error) {
303 throw new Error(`OpenAI API Error: ${data.error.message}`);
304 }
305 return data.choices[0]?.message?.content || emailText;
387}
388
389// Helper function to send a request to OpenAI
390async function sendRequestToOpenAI(prompt, transformedPrompt, openaiUrl, apiKey, model) {
391 try {
392 // Debug logging for the prompt and transformed prompt
396 console.log(prompt);
397
398 // Prepare the OpenAI messages payload
399 const messages = [
400 {
417 };
418
419 // Send the request to OpenAI
420 const response = await fetch(openaiUrl, {
421 method: "POST",
422 body: JSON.stringify(body),
430 const data = await response.json();
431 if (data.error) {
432 throw new Error(`OpenAI API Error: ${data.error.message}`);
433 }
434 return data.choices[0]?.message?.content || "No response from OpenAI.";
435 } catch (err) {
436 console.error("Error in sendRequestToOpenAI:", err);
437 return "Error processing your request. Please try again later.";
438 }

emailValHandlerNomain.tsx22 matches

@martinbowling•Updated 3 months ago
20
212. Set up the required environment variable:
22 - OPENAI_API_KEY: Your OpenAI API key
23
24 Optional environment variable:
62// Main controller function
63export default async function emailValHandler(receivedEmail) {
64 const openaiUrl = "https://api.openai.com/v1/chat/completions";
65 const openaiKey = Deno.env.get("OPENAI_API_KEY");
66 const mdApiKey = Deno.env.get("MD_API_KEY");
67 const model = "o1-2024-12-17";
68
69 if (!openaiKey) {
70 throw new Error("OPENAI_KEY environment variable is not set.");
71 }
72
78
79 // Step 2: Transform the email prompt using the prompt transformer
80 const transformedPrompt = await transformPrompt(receivedEmail.text, openaiUrl, openaiKey, model);
81
82 // Step 3: Process different types of content
83 const { pdfTexts, imageAnalysis } = await processAttachments(attachments, openaiKey, transformedPrompt);
84 const websiteMarkdown = await extractWebsiteMarkdown(links, mdApiKey);
85
93 );
94
95 // Step 5: Send to OpenAI and get response
96 const openaiResponse = await sendRequestToOpenAI(finalPrompt, transformedPrompt, openaiUrl, openaiKey, model);
97
98 // Step 6: Send response email
99 await sendResponseByEmail(receivedEmail.from, openaiResponse);
100 console.log("Response email sent.");
101}
172async function analyzeImage(imageAttachment, apiKey, transformedPrompt) {
173 try {
174 const response = await fetch("https://api.openai.com/v1/chat/completions", {
175 method: "POST",
176 headers: {
214
215// Transform the original prompt using the prompt transformer
216async function transformPrompt(emailText, openaiUrl, apiKey, model) {
217 const promptTransformerText =
218 `You are an AI assistant tasked with transforming user queries into structured research or information requests. Your goal is to take a simple query and expand it into a comprehensive research objective with specific formatting requirements.
283 };
284
285 const response = await fetch(openaiUrl, {
286 method: "POST",
287 body: JSON.stringify(body),
294 const data = await response.json();
295 if (data.error) {
296 throw new Error(`OpenAI API Error: ${data.error.message}`);
297 }
298 return data.choices[0]?.message?.content || emailText;
382}
383
384// Helper function to send a request to OpenAI
385async function sendRequestToOpenAI(prompt, transformedPrompt, openaiUrl, apiKey, model) {
386 try {
387 // Debug logging for the prompt and transformed prompt
391 console.log(prompt);
392
393 // Prepare the OpenAI messages payload
394 const messages = [
395 {
412 };
413
414 // Send the request to OpenAI
415 const response = await fetch(openaiUrl, {
416 method: "POST",
417 body: JSON.stringify(body),
425 const data = await response.json();
426 if (data.error) {
427 throw new Error(`OpenAI API Error: ${data.error.message}`);
428 }
429 return data.choices[0]?.message?.content || "No response from OpenAI.";
430 } catch (err) {
431 console.error("Error in sendRequestToOpenAI:", err);
432 return "Error processing your request. Please try again later.";
433 }

emailValHandlerNoREADME.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
23

preciseScarletHerringmain.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",

preciseScarletHerringREADME.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: "YOUR_CEREBRAS_API_KEY",
40 baseURL: "https://api.cerebras.ai/v1"

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",

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": "*",