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=6&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 1569 results for "openai"(1086ms)

discord-botREADME.md3 matches

@boucher•Updated 3 days ago
25- Node.js 16+ and npm
26- Discord account with Bot token
27- OpenAI API key (for AI-powered queries)
28- Val.town account (for deployment)
29
51 - `DISCORD_USER_ID`: Your Discord user ID
52 - `SPOUSE_USER_ID`: Your partner's Discord user ID
53 - `OPENAI_API_KEY`: Your OpenAI API key
54
555. Initialize the database
146
147- Discord.js for Discord API integration
148- OpenAI for AI-powered querying
149- Val.town for hosting and scheduling
150- Better-SQLite3 for database management

discord-bot.cursorrules4 matches

@boucher•Updated 3 days 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" },

discord-botDISCORD_BOT_SETUP.md3 matches

@boucher•Updated 3 days ago
57 ```
58
59## 7. Get OpenAI API Key
60
611. Go to [OpenAI's website](https://platform.openai.com/)
622. Sign up or log in
633. Navigate to the API keys section
666. Add it to your `.env` file:
67 ```
68 OPENAI_API_KEY=your_openai_api_key_here
69 ```
70

Projectmain.tsx15 matches

@Get•Updated 3 days ago
6 * Uses 'npm:pdf.js-extract' for direct PDF text extraction.
7 * Serves HTML UI & API endpoint from the same Val.
8 * OpenAI import is dynamically done inside the main server function.
9 *
10 * Based on structure from multi-agent support simulation example.
11 * Assumes 'openai' secret is set in Val Town environment variables.
12 *
13 * Last Updated: 2025-05-01 (Dashboard UI, Localization, Animation Integration)
950export default async function(req: Request) {
951 // --- Dynamic Imports (Inside Handler) ---
952 const { OpenAI } = await import("https://esm.town/v/std/openai");
953 const { z } = await import("npm:zod");
954 const { fetch } = await import("https://esm.town/v/std/fetch");
990 }
991
992 // --- Helper Function: Call OpenAI API (Unchanged) ---
993 async function callOpenAI(
994 openai: OpenAI,
995 systemPrompt: string,
996 userMessage: string,
999 ): Promise<{ role: "assistant" | "system"; content: string | object }> {
1000 try {
1001 const response = await openai.chat.completions.create({
1002 model: model,
1003 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
1011 return { role: "assistant", content: JSON.parse(content) };
1012 } catch (parseError) {
1013 console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content);
1014 throw new Error(`AI response was not valid JSON. Raw: ${content.substring(0, 150)}...`);
1015 }
1016 } else { return { role: "assistant", content: content }; }
1017 } catch (error) {
1018 console.error(`OpenAI API call failed. ExpectJSON: ${expectJson}. Error:`, error);
1019 let errorMessage = "Error communicating with AI model.";
1020 if (error.message) { errorMessage += ` Details: ${error.message}`; }
1021 // Check for specific error types if needed (e.g., rate limits, auth)
1022 if (error.status === 401) errorMessage = "Authentication error with OpenAI API. Check your secret key.";
1023 if (error.status === 429) errorMessage = "OpenAI API rate limit exceeded. Please try again later.";
1024
1025 return { role: "system", content: errorMessage };
1112 log: LogEntry[],
1113 ): Promise<LogEntry[]> { // Returns the completed log array
1114 const openai = new OpenAI(); // Assumes API key is in environment variables
1115
1116 log.push({ agent: "System", type: "step", message: "Starting analysis workflow." });
1217 // --- 2. Content Analysis ---
1218 log.push({ agent: "System", type: "step", message: "Starting Content Analysis..." });
1219 const analysisResponse = await callOpenAI(openai, contentAnalysisSystemPrompt, truncatedText, "gpt-4o", true); // Use gpt-4o
1220 let analysisResult: AnalysisResult | null = null;
1221 if (analysisResponse.role === "assistant" && typeof analysisResponse.content === "object") {
1237 // --- 3. Citation Extraction ---
1238 log.push({ agent: "System", type: "step", message: "Starting Citation Extraction..." });
1239 const citationResponse = await callOpenAI(openai, citationExtractionSystemPrompt, truncatedText, "gpt-4o", true); // Use gpt-4o
1240 let extractedCitations: Citation[] = [];
1241 if (
1267 message: \`AI response was not the expected JSON format. Received: \${JSON.stringify(citationResponse.content).substring(0, 200)}...\`,
1268 });
1269 } else { // System error from callOpenAI
1270 log.push({ agent: "Citation Extraction Agent", type: "error", message: citationResponse.content });
1271 }

myanythingmain.tsx3 matches

@yassinreg•Updated 3 days ago
125 if (request.method === 'POST') {
126 try {
127 const { OpenAI } = await import("https://esm.town/v/std/openai");
128 const openai = new OpenAI();
129
130 const formData = await request.formData();
138 const cvText = new TextDecoder().decode(cvBuffer);
139
140 const completion = await openai.chat.completions.create({
141 messages: [
142 {

myeverythingmain.tsx3 matches

@yassinreg•Updated 3 days ago
125 if (request.method === "POST") {
126 try {
127 const { OpenAI } = await import("https://esm.town/v/std/openai");
128 const openai = new OpenAI();
129
130 const formData = await request.formData();
138 const cvText = new TextDecoder().decode(cvBuffer);
139
140 const completion = await openai.chat.completions.create({
141 messages: [
142 {

feedbackmain.tsx3 matches

@yassinreg•Updated 3 days ago
125 if (request.method === "POST") {
126 try {
127 const { OpenAI } = await import("https://esm.town/v/std/openai");
128 const openai = new OpenAI();
129
130 const formData = await request.formData();
138 const cvText = new TextDecoder().decode(cvBuffer);
139
140 const completion = await openai.chat.completions.create({
141 messages: [
142 {

speechmain.tsx5 matches

@salon•Updated 3 days ago
197 const [isInitialized, setIsInitialized] = useState(false);
198
199 // --- OpenAI Interaction (Unchanged) ---
200 // !!! IMPORTANT SECURITY WARNING & Val Town Note !!!
201 // ... (same as before)
205 if (!text) return;
206 setStatus("Sending to AI...");
207 console.log("Sending to OpenAI:", text);
208 setAiResponse(""); // Clear previous response
209 setError(null);
213 try {
214 // ---- START: Replace this block in Val Town ----
215 const response = await fetch("https://api.openai.com/v1/chat/completions", {
216 method: "POST",
217 headers: {
226 const errorData = await response.json().catch(() => ({})); // Try to get JSON error details
227 throw new Error(
228 `OpenAI API Error: ${response.status} ${response.statusText} - ${
229 errorData?.error?.message ?? "Check API key or usage limits."
230 }`,
240 speakText(reply);
241 } catch (err: any) {
242 console.error("OpenAI call failed:", err);
243 const errMsg = `AI Error: ${err.message}`;
244 setError(errMsg);

FixItWandgenerate.ts6 matches

@wolf•Updated 3 days ago
1import OpenAI from "https://esm.sh/openai@4.96.0";
2import { search } from "./locations/mod.ts";
3
4const openai = new OpenAI();
5
6/**
39 const audioFile = new File([audioBlob], "a.mp3", { type: "audio/mp3" });
40
41 transcription = await openai.audio.transcriptions.create({
42 file: audioFile,
43 model: "whisper-1",
50 if (transcription) {
51 // Detect possible location references in the transcription
52 const locationDetectionResponse = await openai.chat.completions.create({
53 model: "gpt-4o-mini",
54 messages: [
149 });
150
151 const chatResponse = await openai.chat.completions.create({
152 model: "gpt-4o",
153 messages: messages as any, // Type assertion to fix any TypeScript issues
166`;
167
168 const subjectResponse = await openai.chat.completions.create({
169 model: "gpt-4o-mini",
170 messages: [

OpenTownie_jacksonsystem_prompt.txt4 matches

@stevekrouse•Updated 3 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" },

testOpenAI1 file match

@stevekrouse•Updated 31 mins ago

testOpenAI1 file match

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