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=16&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 1572 results for "openai"(401ms)

stevensDemo.cursorrules4 matches

@natebarksdale•Updated 2 weeks 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" },

stevensDemo.cursorrules4 matches

@garyj•Updated 2 weeks 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" },
142 }
143
144 // Dynamically import OpenAI
145 const { OpenAI } = await import("https://esm.town/v/std/openai");
146
147 // Initialize OpenAI for potential AI processing
148 const openai = new OpenAI();
149
150 // Process and potentially trigger AI agent
151 const aiResponse = await openai.chat.completions.create({
152 messages: [
153 {

messageReceiverAppmain.tsx3 matches

@bgtgtgfgvbtgvgb•Updated 2 weeks ago
159export default async function server(request: Request): Promise<Response> {
160 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
161 const { OpenAI } = await import("https://esm.town/v/std/openai");
162
163 const KEY = "messageReceiverApp";
249 // Process with AI if destinations exist
250 if (aiDestinations.rows.length > 0) {
251 const openai = new OpenAI();
252
253 for (const destination of aiDestinations.rows) {
254 try {
255 const aiResponse = await openai.chat.completions.create({
256 messages: [{
257 role: "user",

dazzlingCoffeeOctopusmain.tsx3 matches

@bgtgtgfgvbtgvgb•Updated 2 weeks ago
152export default async function server(request: Request): Promise<Response> {
153 if (request.method === 'POST' && new URL(request.url).pathname === '/chat') {
154 const { OpenAI } = await import("https://esm.town/v/std/openai");
155 const openai = new OpenAI();
156
157 const body = await request.json();
159
160 try {
161 const completion = await openai.chat.completions.create({
162 messages: messages,
163 model: "gpt-4o-mini",

speedOfMasterymain.tsx3 matches

@bgtgtgfgvbtgvgb•Updated 2 weeks ago
166export default async function server(request: Request): Promise<Response> {
167 if (request.method === 'POST' && new URL(request.url).pathname === '/chat') {
168 const { OpenAI } = await import("https://esm.town/v/std/openai");
169 const openai = new OpenAI();
170
171 const body = await request.json();
173
174 try {
175 const completion = await openai.chat.completions.create({
176 messages: messages,
177 model: "gpt-4o-mini",

stevensDemo.cursorrules4 matches

@forafish•Updated 2 weeks 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" },

stevensDemo.cursorrules4 matches

@ivkan•Updated 2 weeks 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" },

stevensDemo.cursorrules4 matches

@niksod•Updated 2 weeks 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" },

jsonmain.tsx27 matches

@Get•Updated 2 weeks ago
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
4import { OpenAI } from "https://esm.town/v/std/openai";
5
6// ========================================================================
600 }
601
602 const openai = new OpenAI();
603
604 // --- Centralized OpenAI Call Function ---
605 async function callOpenAI(
606 systemPrompt: string,
607 userMessage: string,
611 ): Promise<{ role: "assistant" | "system"; content: string } | ReadableStream<Uint8Array>> {
612 try {
613 serverLog("INFO", "Calling OpenAI", {
614 model,
615 promptStart: systemPrompt.substring(0, 50).replace(/\s+/g, " ") + "...",
618 });
619
620 const response = await openai.chat.completions.create({
621 model: model,
622 response_format: expectJson && !isStreaming ? { type: "json_object" } : undefined,
630
631 if (isStreaming) {
632 serverLog("INFO", "OpenAI call initiated (Streaming)");
633 if (response instanceof ReadableStream) {
634 return response;
641 if (done) {
642 controller.close();
643 serverLog("INFO", "OpenAI Stream finished.");
644 } else {
645 const content = value?.choices?.[0]?.delta?.content || "";
649 }
650 } catch (err) {
651 serverLog("ERROR", "Error reading from OpenAI stream iterator", { error: (err as Error).message });
652 controller.error(err);
653 }
655 });
656 } else {
657 throw new Error("OpenAI response is not a readable stream or async iterator when streaming was expected.");
658 }
659 } else {
660 const content = (response as any).choices?.[0]?.message?.content;
661 if (!content) {
662 serverLog("ERROR", "OpenAI API returned empty content (non-streaming)", { response });
663 throw new Error("Received invalid or empty response from AI model.");
664 }
667 try {
668 JSON.parse(content);
669 serverLog("INFO", "OpenAI call successful (JSON validated)");
670 return { role: "assistant", content };
671 } catch (jsonError) {
672 serverLog("ERROR", "OpenAI response is not valid JSON", {
673 contentPreview: content.substring(0, 200) + "...",
674 error: (jsonError as Error).message,
680 }
681 } else {
682 serverLog("INFO", "OpenAI call successful (Text)");
683 return { role: "assistant", content };
684 }
687 const errorMessageString = error instanceof Error ? error.message : String(error);
688 const errorStatus = error instanceof Error ? (error as any).status ?? (error as any).response?.status : undefined;
689 serverLog("ERROR", "OpenAI API call failed", {
690 model,
691 error: errorMessageString,
698 const statusCode = errorStatus;
699
700 if (statusCode === 401) userFriendlyErrorMessage = "OpenAI Auth Error (401). Check Val Town 'openai' secret.";
701 else if (statusCode === 429)
702 userFriendlyErrorMessage = "OpenAI Rate Limit/Quota Error (429). Check OpenAI plan/usage or try again later.";
703 else if (statusCode === 400)
704 userFriendlyErrorMessage = "OpenAI Bad Request (400). Possible issue with request or content filter. Details: "
705 + errorMessageString;
706 else if (errorMessageString?.includes("maximum context length"))
707 userFriendlyErrorMessage = "OpenAI Context Length Error (400). The request is too long.";
708 else if (statusCode >= 500)
709 userFriendlyErrorMessage = "OpenAI Server Error (" + statusCode
710 + "). OpenAI might be having issues. Try again later.";
711 else if (error instanceof Error && (error as any).code === "ENOTFOUND")
712 userFriendlyErrorMessage = "Network Error (ENOTFOUND). Cannot resolve OpenAI API address.";
713 else if (error instanceof Error && (error as any).code === "ECONNREFUSED")
714 userFriendlyErrorMessage = "Network Error (ECONNREFUSED). Cannot connect to OpenAI API.";
715 else if (errorMessageString?.includes("secret")) userFriendlyErrorMessage = errorMessageString;
716 else userFriendlyErrorMessage = userFriendlyErrorMessage + " Details: " + errorMessageString;
830 }
831
832 const response = await callOpenAI(systemPrompt, userMessageContent, "gpt-4o-mini", agent.expectJson, false);
833
834 if (typeof response === "string" || response instanceof ReadableStream) {
1287
1288 if (shouldStream) {
1289 const stream = await callOpenAI(agentAPrompt, lastUserMessageContent, "gpt-4o-mini", true, true);
1290 if (!(stream instanceof ReadableStream)) throw new Error("Expected ReadableStream for streaming.");
1291
1311 });
1312 } else {
1313 const agentAResponse = await callOpenAI(agentAPrompt, lastUserMessageContent, "gpt-4o-mini", true, false);
1314 if (typeof agentAResponse === "string" || agentAResponse instanceof ReadableStream)
1315 throw new Error("Expected structured response for non-streaming.");
1363 + "Output ONLY raw JSON.";
1364
1365 const agentBResponse = await callOpenAI(agentBPrompt, toolRequest.query, "gpt-4o-mini", true, false);
1366 if (typeof agentBResponse === "string" || agentBResponse instanceof ReadableStream)
1367 throw new Error("Expected structured response for tool.");

testOpenAI1 file match

@stevekrouse•Updated 4 hours ago

testOpenAI1 file match

@shouser•Updated 2 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": "*",