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/$2?q=openai&page=3&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 1911 results for "openai"(1064ms)

token-servermain.ts3 matches

@kwhinnery_openai•Updated 1 day ago
1const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
2
3export async function handler(request: Request) {
4 const response = await fetch("https://api.openai.com/v1/realtime/sessions", {
5 method: "POST",
6 headers: {
7 "Content-Type": "application/json",
8 Authorization: `Bearer ${OPENAI_API_KEY}`,
9 },
10 body: JSON.stringify({

Towniesystem_prompt.txt4 matches

@charmaine•Updated 1 day ago
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },

Townie.cursorrules4 matches

@charmaine•Updated 1 day ago
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },

charmaineValSearch.cursorrules4 matches

@charmaine•Updated 1 day ago
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },

Realestate2main.tsx13 matches

@Get•Updated 1 day ago
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { z } from "npm:zod";
4
635}
636
637async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Promise<string | null> {
638 log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
639 try { // @ts-ignore
640 const oai = new OpenAI();
641 const comp = await oai.chat.completions.create({
642 model: "gpt-4o-mini", // Consider gpt-4o for more complex tasks if budget allows
648 const usg = comp.usage;
649 if (!resT) {
650 log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
651 return null;
652 }
653 log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
654 return resT.trim();
655 } catch (err: any) {
663 st: err.status,
664 };
665 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
666 throw new Error(
667 `OpenAI API Call Failed: ${err.message}`
668 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
669 );
985 const filledUserPrompt = Utils.fillPromptTemplate(userPrompt, params);
986
987 const rawOpenAIResponse = await callOpenAI(systemPrompt, filledUserPrompt, mid, tid, logFn);
988 if (!rawOpenAIResponse) {
989 logFn("WN", agentConfig.name, `OpenAI call returned no content, tid=${tid}.`, {}, mid, tid);
990 return { mid, cid: tid, p: {} as TOD, e: `${agentConfig.name} Error: AI returned no content.` };
991 }
992 let outputData: TOD;
993 try {
994 outputData = agentConfig.outputParser(rawOpenAIResponse);
995 }
996 catch (parseError: any) {
999 agentConfig.name,
1000 `Output parsing failed, tid=${tid}. M: ${parseError.message}`,
1001 { rawResponsePreview: rawOpenAIResponse.slice(0, 500) },
1002 mid,
1003 tid,

mech2mainLogic.ts13 matches

@join•Updated 1 day ago
17} from "https://esm.town/v/join/mech2/src/coreTypes.ts";
18import { Utils } from "https://esm.town/v/join/mech2/src/utils.ts";
19import { OpenAI } from "https://esm.town/v/std/openai";
20
21export class LogAgent {
69}
70
71export async function callOpenAI(
72 sysP: string,
73 userP: string,
76 log: LogFn,
77): Promise<string | null> {
78 log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
79 try {
80 const oai = new OpenAI();
81 const comp = await oai.chat.completions.create({
82 model: "gpt-4o-mini",
88 const usg = comp.usage;
89 if (!resT) {
90 log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
91 return null;
92 }
93 log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
94 return resT.trim();
95 } catch (err: any) {
103 st: err.status,
104 };
105 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
106 throw new Error(
107 `OpenAI API Call Failed: ${err.message}`
108 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
109 );
375 }
376 const filledUserPrompt = Utils.fillPromptTemplate(userPrompt, params);
377 const rawOpenAIResponse = await callOpenAI(systemPrompt, filledUserPrompt, mid, tid, logFn);
378 if (!rawOpenAIResponse) {
379 logFn("WN", agentConfig.name, `OpenAI no content tid=${tid}.`, {}, mid, tid);
380 return { mid, cid: tid, p: {} as TOD, e: `${agentConfig.name} Err:AI no content.` };
381 }
382 let outputData: TOD;
383 try {
384 outputData = agentConfig.outputParser(rawOpenAIResponse);
385 } catch (parseError: any) {
386 logFn(
388 agentConfig.name,
389 `ParseFail tid=${tid}. M:${parseError.message}`,
390 { rRPrev: rawOpenAIResponse.slice(0, 500) },
391 mid,
392 tid,

realestatemain.tsx13 matches

@join•Updated 2 days ago
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { z } from "npm:zod";
4
517}
518
519async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Promise<string | null> {
520 log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
521 try { // @ts-ignore
522 const oai = new OpenAI();
523 const comp = await oai.chat.completions.create({
524 model: "gpt-4o-mini", // Consider gpt-4o for more complex real estate tasks if needed
530 const usg = comp.usage;
531 if (!resT) {
532 log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
533 return null;
534 }
535 log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
536 return resT.trim();
537 } catch (err: any) {
545 st: err.status,
546 };
547 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
548 throw new Error(
549 `OpenAI API Call Failed: ${err.message}`
550 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
551 );
893 const filledUserPrompt = Utils.fillPromptTemplate(userPrompt, params);
894
895 const rawOpenAIResponse = await callOpenAI(systemPrompt, filledUserPrompt, mid, tid, logFn);
896 if (!rawOpenAIResponse) {
897 logFn("WN", agentConfig.name, `OpenAI call returned no content, tid=${tid}.`, {}, mid, tid);
898 return { mid, cid: tid, p: {} as TOD, e: `${agentConfig.name} Error: AI returned no content.` };
899 }
900 let outputData: TOD;
901 try {
902 outputData = agentConfig.outputParser(rawOpenAIResponse);
903 }
904 catch (parseError: any) {
907 agentConfig.name,
908 `Output parsing failed, tid=${tid}. M: ${parseError.message}`,
909 { rawResponsePreview: rawOpenAIResponse.slice(0, 500) },
910 mid,
911 tid,

poolmain.tsx13 matches

@join•Updated 2 days ago
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { z } from "npm:zod";
4
433}
434
435async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Promise<string | null> {
436 log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
437 try { // @ts-ignore
438 const oai = new OpenAI();
439 const comp = await oai.chat.completions.create({
440 model: "gpt-4o-mini",
446 const usg = comp.usage;
447 if (!resT) {
448 log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
449 return null;
450 }
451 log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_reason }, mid, tid);
452 return resT.trim();
453 } catch (err: any) {
461 st: err.status,
462 };
463 log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
464 throw new Error(
465 `OpenAI API Call Failed: ${err.message}`
466 + (err.code ? ` (Code:${err.code}, Status:${err.status})` : (err.status ? ` (Status:${err.status})` : "")),
467 );
765 }
766 const filledUserPrompt = Utils.fillPromptTemplate(userPrompt, params);
767 const rawOpenAIResponse = await callOpenAI(systemPrompt, filledUserPrompt, mid, tid, logFn);
768 if (!rawOpenAIResponse) {
769 logFn("WN", agentConfig.name, `OpenAI call returned no content, tid=${tid}.`, {}, mid, tid);
770 return { mid, cid: tid, p: {} as TOD, e: `${agentConfig.name} Error: AI returned no content.` };
771 }
772 let outputData: TOD;
773 try {
774 outputData = agentConfig.outputParser(rawOpenAIResponse);
775 } catch (parseError: any) {
776 logFn(
778 agentConfig.name,
779 `Output parsing failed, tid=${tid}. M: ${parseError.message}`,
780 { rawResponsePreview: rawOpenAIResponse.slice(0, 500) },
781 mid,
782 tid,

automated-email-quotesquote-system.tsx9 matches

@mannydsz•Updated 2 days ago
6export async function emailValHandler(receivedEmail) {
7 const llmApiUrl = "https://api.anthropic.com/v1/messages";
8 const apiKey = Deno.env.get("ANTHROPIC_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 = "claude-opus-4-20250514";
10
35 const prompt = generatePrompt(receivedEmail, pdfTexts, emailText);
36
37 // step 4: send prompt to openai
38 const aiResponse = await sendRequestToAI(prompt, llmApiUrl, apiKey, model);
39
40 // log the openai response
41 console.log("openai response:", aiResponse);
42
43 // step 5: send the response back via email
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 sendRequestToAI(prompt, llmApiUrl, apiKey, model) {
125 try {
126 // prepare the openai messages payload
127 const messages = [
128 {
148 };
149
150 // send the request to openai
151 const response = await fetch(llmApiUrl, {
152 method: "POST",
161 const data = await response.json();
162 console.log(data);
163 return data.choices[0]?.message?.content || "no response from openai.";
164 } catch (err) {
165 console.error("error in sendRequestToAI:", err);

aiEmailAssistantREADME.md2 matches

@mannydsz•Updated 2 days 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)

openaiproxy2 file matches

@skutaans•Updated 11 hours ago

token-server1 file match

@kwhinnery_openai•Updated 1 day ago
Mint tokens to use with the OpenAI Realtime API for WebRTC
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai"; import { sqlite } from "https://esm.town/v/stevekrouse/sqlite"; /** * Practical Implementation of Collective Content Intelligence * Bridging advanced AI with collaborative content creation */ exp
kwhinnery_openai