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=1&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 1535 results for "openai"(663ms)

maine-bills-taxsummarize.ts3 matches

@cmknz•Updated 2 hours ago
1import { ChatCompletion, SearchResult } from "https://esm.town/v/cmknz/maine-bills-tax/types.ts";
2import { OpenAI } from "https://esm.town/v/std/openai";
3
4const openai = new OpenAI();
5
6const prompt =
24
25 // Prompt request
26 const chatPromise: Promise<ChatCompletion> = openai.chat.completions.create({
27 messages: [
28 { role: "user", content: prompt + ": " + extractImportantInfo },

guide2main.tsx17 matches

@salon•Updated 12 hours ago
4// SERVER-SIDE LOGIC (TypeScript)
5// =============================================================================
6import { OpenAI } from "https://esm.town/v/std/openai";
7
8// --- Configuration ---
23 maskSrc?: string; // Used for holo mask layer
24}
25interface OpenAIResponse {
26 races: RaceInfo[];
27}
96];
97
98// --- OpenAI Generation Function ---
99// <<< No changes needed in OpenAI function logic itself >>>
100async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
101 const openai = new OpenAI();
102 const numToRequest = Math.max(1, NUM_CARDS_TO_GENERATE);
103 const prompt =
112Return STRICTLY as a single JSON object: { "races": [ { race1 }, { race2 }, ... ] }. No introductory text or explanations outside the JSON structure.`;
113 try {
114 console.info(`Requesting ${numToRequest} race data generation from OpenAI...`);
115 const completion = await openai.chat.completions.create({
116 model: "gpt-4o",
117 messages: [{ role: "user", content: prompt }],
120 });
121 const rawContent = completion.choices[0]?.message?.content;
122 if (!rawContent) throw new Error("OpenAI returned an empty response message.");
123
124 let parsedJson;
126 parsedJson = JSON.parse(rawContent);
127 } catch (parseError) {
128 console.error("Failed to parse OpenAI JSON response:", parseError);
129 console.error("Raw OpenAI response:", rawContent);
130 throw new Error(`JSON Parsing Error: ${parseError.message}`);
131 }
147 ) {
148 console.warn(
149 `OpenAI response JSON failed validation for ${numToRequest} races:`,
150 JSON.stringify(parsedJson, null, 2),
151 );
152 throw new Error(
153 "OpenAI response JSON structure, count, data types, color format, hint value, or mask URL invalid.",
154 );
155 }
156 // --- End Validation ---
157
158 const generatedData = (parsedJson as OpenAIResponse).races.map(race => ({
159 ...race,
160 borderAnimationHint: race.borderAnimationHint || "none",
161 // No need to override maskSrc here, default is handled in client script
162 }));
163 console.info(`Successfully generated and validated ${generatedData.length} races from OpenAI.`);
164 return generatedData;
165 } catch (error) {
166 console.error("Error fetching or processing data from OpenAI:", error);
167 console.warn("Using fallback race data due to the error.");
168 return fallbackRaceData.slice(0, numToRequest).map(race => ({
175// --- Main HTTP Handler (Val Town Entry Point) ---
176export default async function server(request: Request): Promise<Response> {
177 const activeRaceData = await generateRaceDataWithOpenAI();
178
179 // Define CSS Styles

lite-britelitebrite.ts4 matches

@defunkt•Updated 19 hours ago
1// liteBriteGPTHTTP.val.ts
2// Set OPENAI_API_KEY as a secret on Val Town first.
3
4import OpenAI from "npm:openai"; // works in Deno/Val Town
5const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY")! });
6
7const WIDTH = 60, HEIGHT = 40;
67 if (pathname === "/draw") {
68 const idea = searchParams.get("prompt") ?? "smiley face";
69 const chat = await openai.chat.completions.create({
70 model: "gpt-4o-mini",
71 temperature: 0.7,

stevensDemo.cursorrules4 matches

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

GitHub-trending-summarysummarize-to-email3 matches

@buzz_code•Updated 23 hours ago
1import { email } from "https://esm.town/v/std/email";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { JSDOM } from "npm:jsdom";
4import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from "npm:node-html-markdown";
16);
17
18const openai = new OpenAI();
19console.log(trendingMarkdown);
20
21const completion = await openai.chat.completions.create({
22 messages: [
23 {

remote-evalparameters.eval.ts3 matches

@edenh•Updated 1 day ago
1import { Levenshtein } from "npm:autoevals";
2import { Eval, initDataset, wrapOpenAI } from "npm:braintrust";
3import OpenAI from "npm:openai";
4import { z } from "npm:zod";
5
6const client = wrapOpenAI(new OpenAI());
7
8Eval("Simple eval", {

stevensDemo.cursorrules4 matches

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

testOpenAInew-file-2085.tsx3 matches

@shouser•Updated 1 day ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const openai = new OpenAI();
4
5const completion = await openai.chat.completions.create({
6 messages: [
7 { role: "user", content: "Say hello in a creative way" },

testOpenAInew-file-2085.tsx3 matches

@stevekrouse•Updated 1 day ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const openai = new OpenAI();
4
5const completion = await openai.chat.completions.create({
6 messages: [
7 { role: "user", content: "Say hello in a creative way" },

stevensDemogenerateFunFacts.ts6 matches

@Shmully•Updated 1 day ago
2import { nanoid } from "https://esm.sh/nanoid@5.0.5";
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4import OpenAI from "npm:openai@4.24.1";
5
6const TABLE_NAME = `memories`;
78 try {
79 // Get API key from environment
80 const apiKey = Deno.env.get("OPENAI_API_KEY");
81 if (!apiKey) {
82 console.error("OpenAI API key is not configured.");
83 return null;
84 }
85
86 // Initialize OpenAI client
87 const openai = new OpenAI({ apiKey });
88
89 // Format previous facts for the prompt
139 console.log({ message });
140
141 const response = await openai.chat.completions.create({
142 model: "gpt-4",
143 max_tokens: 1000,

testOpenAI1 file match

@shouser•Updated 1 day ago

testOpenAI1 file match

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