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=9&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 1567 results for "openai"(680ms)

faq_chatbotmain.tsx3 matches

@sunmade•Updated 6 days ago
172export default async function server(request: Request): Promise<Response> {
173 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
174 const { OpenAI } = await import("https://esm.town/v/std/openai");
175 const KEY = "faq_chatbot";
176 const SCHEMA_VERSION = 2;
191 if (new URL(request.url).pathname === "/chat") {
192 const body = await request.json();
193 const openai = new OpenAI();
194
195 const systemPrompt = `You are an AI assistant for TechyJaunt, an eduTech platform that trains Africans in tech skills.
199
200 try {
201 const completion = await openai.chat.completions.create({
202 model: "gpt-4o-mini",
203 messages: [

Val_Geomain.tsx4 matches

@DegVal•Updated 6 days ago
291export default async function server(request: Request): Promise<Response> {
292 if (request.method === "POST" && new URL(request.url).pathname === "/analyze") {
293 const { OpenAI } = await import("https://esm.town/v/std/openai");
294 const openai = new OpenAI();
295
296 const formData = await request.formData();
312
313 try {
314 const response = await openai.chat.completions.create({
315 model: "gpt-4o",
316 messages: [
361 );
362 } catch (error) {
363 console.error("OpenAI Analysis Error:", error);
364 return new Response(
365 JSON.stringify({

stevensDemo.cursorrules4 matches

@mcpolemic•Updated 6 days 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" },

OpenTowniesystem_prompt.txt4 matches

@yakuzadave•Updated 6 days 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" },

TrainingAssistantmain.tsx3 matches

@sach•Updated 6 days ago
418 if (request.method === 'POST' && new URL(request.url).pathname === '/generate-activity') {
419 try {
420 const { OpenAI } = await import("https://esm.town/v/std/openai");
421 const openai = new OpenAI();
422
423 const { teamSize, activityType } = await request.json();
433 name, description, minTeam, maxTeam`;
434
435 const completion = await openai.chat.completions.create({
436 messages: [{ role: "user", content: prompt }],
437 model: "gpt-4o-mini",

Flashcard_Generatormain.tsx3 matches

@dev_me•Updated 6 days ago
224 const { content } = await request.json();
225
226 const { OpenAI } = await import("https://esm.town/v/std/openai");
227 const openai = new OpenAI();
228
229 const completion = await openai.chat.completions.create({
230 messages: [
231 {

sbirmain.tsx16 matches

@salon•Updated 6 days ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3type LogFunction = (message: string) => void;
441}
442
443async function callOpenAI(
444 systemPrompt: string,
445 userMessage: string,
448): Promise<{ role: "assistant" | "system"; content: string }> {
449 const callId = Math.random().toString(36).substring(2, 8);
450 const logPrefix = "OpenAI Call [" + callId + "] (" + model + ", JSON: " + isJsonOutputRequired + ", Prompt Hash: "
451 + hashCode(systemPrompt) + ")";
452
453 try {
454 const openai = new OpenAI();
455 const response = await openai.chat.completions.create({
456 model: model,
457 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
461 const content = response.choices?.[0]?.message?.content;
462 if (!content) {
463 console.error(logPrefix + ": OpenAI API returned unexpected or empty response structure.");
464 throw new Error("Received invalid or empty response content from AI model.");
465 }
473
474 if (errorResponseData?.message) {
475 errorMessage = "OpenAI Error (" + (statusCode || "unknown status") + "): " + errorResponseData.message;
476 } else if (errorResponseData?.error?.message) {
477 errorMessage = "OpenAI Error (" + (statusCode || "unknown status") + "): " + errorResponseData.error.message;
478 } else if (error.message) {
479 errorMessage += " Details: " + error.message;
485 }
486 }
487 if (statusCode === 401) errorMessage += " (ACTION: Verify OpenAI API key is correct and active.)";
488 else if (statusCode === 429) errorMessage += " (ACTION: Rate limit or quota exceeded. Check OpenAI plan/usage.)";
489 else if (statusCode === 400)
490 errorMessage += " (ACTION: Bad request. Input/prompt might be malformed or violate policy. Check prompt/input.)";
491 else if (
492 error.code === "ENOTFOUND" || error.code === "ECONNREFUSED" || error.cause?.code === "UND_ERR_CONNECT_TIMEOUT"
493 ) errorMessage += " (ACTION: Network error connecting to OpenAI.)";
494 else if (statusCode >= 500) errorMessage += " (ACTION: OpenAI server issue. Try again later.)";
495
496 const escapedError = errorMessage.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
691
692 const analyzeSingleOpportunity = async (inputJson: string, sol: Solicitation): Promise<OpportunityAnalysis> => {
693 const result = await callOpenAI(opportunityAnalysisAgentSystemPrompt, inputJson, "gpt-4o-mini", true);
694 try {
695 const parsed = JSON.parse(result.content);
696
697 if (parsed.error && result.role === "system") {
698 log("[ERROR] Analysis Agent (" + sol.id + "): OpenAI communication failed: " + parsed.error);
699 return {
700 solicitation_id: sol.id || "unknown",
778 log("[INFO] Synthesis Input JSON Snippet: " + synthesisInput.substring(0, 500) + "...");
779
780 const synthesisResult = await callOpenAI(strategySynthesisAgentSystemPrompt, synthesisInput, "gpt-4o", true);
781
782 try {
784
785 if (parsedSynthesis.error && synthesisResult.role === "system") {
786 throw new Error("Synthesis Agent OpenAI Error: " + parsedSynthesis.error);
787 }
788

weatherBotmain.tsx7 matches

@benjaminoansah•Updated 6 days ago
2import { fetchWebpage } from "https://esm.town/v/jdan/fetchWebpage";
3import { weatherOfLatLon } from "https://esm.town/v/jdan/weatherOfLatLon";
4import { OpenAI } from "https://esm.town/v/std/openai?v=4";
5
6const openai = new OpenAI();
7
8const toolbox = {
9 "latLngOfCity": {
10 openAiTool: {
11 type: "function",
12 function: {
33 },
34 "weatherOfLatLon": {
35 openAiTool: {
36 type: "function",
37 function: {
60 },
61 "fetchWebpage": {
62 openAiTool: {
63 type: "function",
64 function: {
82};
83
84const tools = Object.values(toolbox).map(({ openAiTool }) => openAiTool);
85const transcript = [
86 { role: "user", content: "What's the weather in Hoboken, NJ? Do your best to follow URLs and summarize the weather instead of having the user do it." },
94
95async function runConversation() {
96 const response = await openai.chat.completions.create({
97 messages: transcript,
98 tools,

AI_generated_Picturesmain.tsx4 matches

@Shega•Updated 6 days ago
60export default async function server(request: Request): Promise<Response> {
61 // Dynamic imports for server-side modules
62 const { OpenAI } = await import("https://esm.town/v/std/openai");
63 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
64 const { blob } = await import("https://esm.town/v/std/blob");
96 const { prompt, language } = await request.json();
97
98 // Initialize OpenAI
99 const openai = new OpenAI();
100
101 // Generate image
102 const response = await openai.images.generate({
103 model: "dall-e-3",
104 prompt: prompt,

Marketingmain.tsx3 matches

@Reinner•Updated 6 days ago
186export default async function server(request: Request): Promise<Response> {
187 if (request.method === "POST") {
188 const { OpenAI } = await import("https://esm.town/v/std/openai");
189 const openai = new OpenAI();
190
191 const { campaignType, targetAudience } = await request.json();
199 Tone should be professional, confident, and friendly. Suitable for LinkedIn, Instagram, and TikTok.`;
200
201 const completion = await openai.chat.completions.create({
202 messages: [{ role: "user", content: prompt }],
203 model: "gpt-4o-mini",

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