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=46&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 1606 results for "openai"(1049ms)

campycardsmain.tsx9 matches

@find•Updated 1 month ago
567// --- Backend Server (Val Town) ---
568export default async function server(request: Request): Promise<Response> {
569 const { OpenAI } = await import("https://esm.town/v/std/openai");
570
571 if (request.method === "OPTIONS") {
590 if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") {
591 try {
592 // Check for OpenAI API Key in Val Town secrets
593 const openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in Val Town secrets
594 const { imageBase64 } = await request.json();
595 if (!imageBase64 || typeof imageBase64 !== "string") {
600 }
601
602 console.log("Received image data, preparing request to OpenAI...");
603
604 const modelChoice = "gpt-4o"; // Or "gpt-4o-mini"
605
606 // --- Construct the detailed prompt for OpenAI ---
607 const prompt = `
608 Alright, listen up, collector fam—here’s the no-BS, sharp-as-a-PSA-10 shorthand guide to grading and authenticating cards. No fluff, just gospel truths. Let’s get it:
727`;
728
729 const response = await openai.chat.completions.create({
730 model: modelChoice,
731 response_format: { type: "json_object" },
749 });
750
751 console.log("Received response from OpenAI.");
752
753 const jsonString = response.choices[0]?.message?.content;
754 if (!jsonString) {
755 throw new Error("OpenAI did not return valid response content.");
756 }
757
761 console.log("Successfully parsed JSON response.");
762 } catch (parseError) {
763 console.error("Failed to parse JSON from OpenAI:", jsonString);
764 throw new Error("AI returned improperly formatted JSON data.");
765 }

aircraftmain.tsx12 matches

@Learn•Updated 1 month ago
757// --- Backend Server (Val Town / Cloud Function) ---
758export default async function server(request: Request): Promise<Response> {
759 // Dynamically import OpenAI only when needed on the server
760 const { OpenAI } = await import("https://esm.town/v/std/openai");
761
762 // Standard CORS preflight handling
782 if (request.method === "POST" && new URL(request.url).pathname === "/analyze-aircraft") {
783 try {
784 // Check for OpenAI API Key in Val Town secrets (Val Town automatically injects process.env)
785 // The library handles finding the key from secrets/env vars.
786
787 const openai = new OpenAI(); // Instantiates with key from secrets
788
789 const { imageBase64 } = await request.json();
796 }
797
798 console.log("Received image data for aircraft analysis, preparing request to OpenAI...");
799
800 const modelChoice = "gpt-4o"; // Use the powerful vision model
801
802 // --- Construct the detailed prompt for OpenAI ---
803 // This prompt guides the AI to act as an aircraft maintenance analyzer.
804 const prompt = `
899`;
900
901 // --- Call OpenAI API ---
902 const response = await openai.chat.completions.create({
903 model: modelChoice,
904 response_format: { type: "json_object" }, // Enforce JSON output
926 });
927
928 console.log("Received response from OpenAI for aircraft analysis.");
929
930 const jsonString = response.choices[0]?.message?.content;
931 if (!jsonString) {
932 throw new Error("OpenAI did not return valid response content.");
933 }
934
936 try {
937 parsedResponse = JSON.parse(jsonString);
938 console.log("Successfully parsed JSON response from OpenAI.");
939 } catch (parseError) {
940 console.error("Failed to parse JSON from OpenAI:", jsonString);
941 // Try to provide the invalid JSON in the error for debugging
942 throw new Error(`AI returned improperly formatted JSON data. Received: ${jsonString.substring(0, 500)}...`);

adaptableJadeCrowmain.tsx3 matches

@Nxnxnxnxn•Updated 1 month ago
239
240async function fetchAIResponse(query: string): Promise<string> {
241 const { OpenAI } = await import("https://esm.town/v/std/openai");
242 const openai = new OpenAI();
243
244 const completion = await openai.chat.completions.create({
245 messages: [
246 { role: "system", content: "You are a helpful voice assistant. Keep responses concise and friendly." },

adeptCyanFireflymain.tsx3 matches

@Nxnxnxnxn•Updated 1 month ago
239
240async function fetchAIResponse(query: string): Promise<string> {
241 const { OpenAI } = await import("https://esm.town/v/std/openai");
242 const openai = new OpenAI();
243
244 const completion = await openai.chat.completions.create({
245 messages: [
246 { role: "system", content: "You are a helpful voice assistant. Keep responses concise and friendly." },

bhaavsynthlandipgpagemain.tsx2 matches

@prashamtrivedi•Updated 1 month ago
408 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
409 const { email: sendEmail } = await import("https://esm.town/v/std/email");
410 const { OpenAI } = await import("https://esm.town/v/std/openai");
411 const openai = new OpenAI();
412
413 const KEY = "bhaavsynthlandipgpage";

trAIderAgentagent.ts5 matches

@kamalnrf•Updated 1 month ago
1import { readFile } from "https://esm.town/v/std/utils@71-main/index.ts";
2import { createOpenAI } from "npm:@ai-sdk/openai";
3import { streamText, tool } from "npm:ai";
4import { z } from "npm:zod";
56});
57
58const openai = createOpenAI({
59 baseURL: "https://std-openaiproxy.web.val.run/v1",
60 apiKey: Deno.env.get("valtown"),
61 organization: undefined,
79 try {
80 const result = await streamText({
81 model: openai("gpt-4o-mini"),
82 messages,
83 tools: {
111 });
112 } catch (error) {
113 console.error("OpenAI API error:", error);
114 return new Response("An error occurred during the analysis.");
115 }

sentencesmain.tsx10 matches

@find•Updated 1 month ago
7// Import a deep cloning library for safe state updates
8import cloneDeep from "https://esm.sh/lodash-es@4.17.21/cloneDeep";
9// Use Val Town's std/openai as requested via example
10import { OpenAI } from "https://esm.town/v/std/openai";
11
12// --- TypeScript Interfaces: Defining the AI's Structured Output ---
396 console.log(`Analyzing: "${sentence.substring(0, 50)}..."`);
397
398 // --- OpenAI Setup using std/openai ---
399 // NOTE: Using std/openai as requested via example. API key handling might be managed by Val Town infrastructure.
400 // If issues occur, consider switching back to `npm:openai` and using API Key secret.
401 console.log("Using std/openai client");
402 const openai = new OpenAI(); // Assumes std/openai handles auth/key implicitly
403
404 // --- System Prompt for Structured Tree Output ---
407 `You are an AI language structuring expert... [PROMPT REMAINS THE SAME AS PREVIOUS VERSION - asking for AnalysisTree JSON with effects, IDs, options etc, using double quotes in JSON output] ... Output ONLY the raw, valid JSON object using double quotes for all JSON keys and string values.`;
408
409 console.log("Sending prompt to OpenAI (gpt-4o)...");
410 const response = await openai.chat.completions.create({
411 model: "gpt-4o",
412 messages: [{ role: "system", content: systemPrompt }],
415 max_tokens: 3000,
416 });
417 console.log(`OpenAI Response. Finish: ${response.choices[0]?.finish_reason}.`);
418
419 const aiResponseContent = response.choices[0]?.message?.content;

OpenTowniesystem_prompt.txt4 matches

@k7d•Updated 1 month ago
137Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
138
139### OpenAI
140```ts
141import { OpenAI } from "https://esm.town/v/std/openai";
142const openai = new OpenAI();
143const completion = await openai.chat.completions.create({
144 messages: [
145 { role: "user", content: "Say hello in a creative way" },

campycardsmain.tsx9 matches

@Learn•Updated 1 month ago
567// --- Backend Server (Val Town) ---
568export default async function server(request: Request): Promise<Response> {
569 const { OpenAI } = await import("https://esm.town/v/std/openai");
570
571 if (request.method === "OPTIONS") {
590 if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") {
591 try {
592 // Check for OpenAI API Key in Val Town secrets
593 const openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in Val Town secrets
594 const { imageBase64 } = await request.json();
595 if (!imageBase64 || typeof imageBase64 !== "string") {
600 }
601
602 console.log("Received image data, preparing request to OpenAI...");
603
604 const modelChoice = "gpt-4o"; // Or "gpt-4o-mini"
605
606 // --- Construct the detailed prompt for OpenAI ---
607 const prompt = `
608You are an expert collectible card grader simulating a PSA-style inspection based SOLELY on the provided image. Analyze the card image and provide a detailed N-point inspection report in JSON format.
662`;
663
664 const response = await openai.chat.completions.create({
665 model: modelChoice,
666 response_format: { type: "json_object" },
684 });
685
686 console.log("Received response from OpenAI.");
687
688 const jsonString = response.choices[0]?.message?.content;
689 if (!jsonString) {
690 throw new Error("OpenAI did not return valid response content.");
691 }
692
696 console.log("Successfully parsed JSON response.");
697 } catch (parseError) {
698 console.error("Failed to parse JSON from OpenAI:", jsonString);
699 throw new Error("AI returned improperly formatted JSON data.");
700 }

Cardvaluemain.tsx10 matches

@find•Updated 1 month ago
271// --- Backend Server (Val Town) ---
272export default async function server(request: Request): Promise<Response> {
273 const { OpenAI } = await import("https://esm.town/v/std/openai");
274
275 if (request.method === "OPTIONS") {
281 if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") {
282 try {
283 // Check for OpenAI API Key in Val Town secrets
284 const openai = new OpenAI();
285 const { imageBase64 } = await request.json();
286 if (!imageBase64 || typeof imageBase64 !== "string") {
288 }
289
290 console.log("Received image data, preparing request to OpenAI..."); // Log start
291
292 const modelChoice = "gpt-4o"; // Use GPT-4o for better vision capabilities. Use "gpt-4o-mini" for lower cost/speed, potentially less accuracy.
293
294 // --- Construct the detailed prompt for OpenAI ---
295 const prompt = `
296You are an expert collectible card grader simulating a PSA-style inspection based SOLELY on the provided image. Analyze the card image and provide a detailed N-point inspection report in JSON format.
346`;
347
348 const response = await openai.chat.completions.create({
349 model: modelChoice,
350 response_format: { type: "json_object" }, // Enforce JSON output
375 });
376
377 console.log("Received response from OpenAI."); // Log success
378
379 const jsonString = response.choices[0]?.message?.content;
380 if (!jsonString) {
381 throw new Error("OpenAI did not return valid response content.");
382 }
383
384 // Parse the JSON response from OpenAI
385 let parsedResponse;
386 try {
388 console.log("Successfully parsed JSON response.");
389 } catch (parseError) {
390 console.error("Failed to parse JSON from OpenAI:", jsonString);
391 throw new Error("AI returned improperly formatted JSON data.");
392 }

translateToEnglishWithOpenAI1 file match

@shlmt•Updated 2 days ago

testOpenAI1 file match

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