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=22&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 1578 results for "openai"(1268ms)

openaiPricingopenAiPricing2 matches

@nbbaierUpdated 2 weeks ago
10});
11
12interface OpenAiPricing {
13 textPricing: {
14 [key: string]: {
29}
30
31export const openAiPricing: OpenAiPricing = {
32 textPricing: {
33 "gpt-3.5-turbo-16k-0613": createPricing(3000, 4000),

openaiPricingfetchAndStoreOpenAiUsage24 matches

@nbbaierUpdated 2 weeks ago
1import { createDayTotal } from "./createDayTotal";
2import { cronEvalLogger as logger } from "https://esm.town/v/nbbaier/cronLogger";
3import { fetchOpenAiUsageData } from "./fetchOpenAiUsageData";
4import { updateBlobUsageDB } from "./updateBlobUsageDB";
5import { blob } from "https://esm.town/v/std/blob?v=11";
7import { DateTime } from "npm:luxon";
8
9const fetchAndStoreOpenAiUsage = async (interval: Interval) => {
10 const timeZone = "America/Chicago";
11 const date = DateTime.now();
15
16 try {
17 const { data, whisper_api_data, dalle_api_data } = await fetchOpenAiUsageData(today);
18
19 const day_total = await createDayTotal(data, whisper_api_data, dalle_api_data);
27};
28
29export default logger(fetchAndStoreOpenAiUsage);
IcarusBot

IcarusBot.cursorrules4 matches

@wittiestUpdated 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" },

familyAI3 matches

@meltedfireUpdated 2 weeks ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function anthropicCompletion(
4 prompt: string,
5) {
6 const openai = new OpenAI();
7
8 try {
9 const completion = await openai.chat.completions.create({
10 messages: [
11 { role: "user", content: prompt },

my-first-val04_email.tsx4 matches

@stevetestprojUpdated 2 weeks ago
3
4import { email } from "https://esm.town/v/std/email";
5import { OpenAI } from "https://esm.town/v/std/OpenAI";
6
7// ------------------------------ Email Address ------------------------------
19 console.log(e);
20
21 // Use OpenAI provided by Val Town to reply to the email
22 const openai = new OpenAI();
23 let chatCompletion = await openai.chat.completions.create({
24 messages: [{
25 role: "user",

my-first-val03_cron.tsx5 matches

@stevetestprojUpdated 2 weeks ago
5// ---------------- Val Town Standard Library ----------------
6// Val Town provides limited free hosted services, including
7// functions for sending emails and using OpenAI
8import { email } from "https://esm.town/v/std/email";
9import { OpenAI } from "https://esm.town/v/std/OpenAI";
10
11// --------------------- Get weather data --------------------
22
23export default async function() {
24 // Use OpenAI provided by Val Town to get weather reccomendation
25 // Experiment with changing the prompt
26 const openai = new OpenAI();
27 let chatCompletion = await openai.chat.completions.create({
28 messages: [{
29 role: "user",

Thinkingmain.tsx16 matches

@GetUpdated 2 weeks ago
5 * Allows users to specify hat sequence (e.g., "W,R,B,Y,G,B") or use default.
6 * Simulates workflow visualization via structured text logs.
7 * Uses OpenAI via @std/openai for agent responses.
8 * Based on previous multi-agent simulation structures.
9 *
334// --- Main Request Handler (Server Code for ThinkingFlow MVP) ---
335export default async function(req: Request) {
336 // Dynamic Import of OpenAI Library
337 const { OpenAI } = await import("https://esm.town/v/std/openai");
338
339 // --- OpenAI API Call Helper (Reused) ---
340 async function callOpenAI(
341 systemPrompt: string,
342 userMessage: string, // Can be query or intermediate context
344 ): Promise<{ role: "assistant" | "system"; content: string }> {
345 try {
346 const openai = new OpenAI();
347
348 const response = await openai.chat.completions.create({
349 model: model,
350 messages: [
356
357 if (!response.choices?.[0]?.message?.content) {
358 console.error("OpenAI API returned unexpected structure:", JSON.stringify(response));
359 throw new Error("Received invalid or empty response from AI model.");
360 }
361 return { role: "assistant", content: response.choices[0].message.content };
362 } catch (error) {
363 console.error(`OpenAI API call failed for model ${model}. Error:`, error.message, error.response?.data);
364 let errorMessage = `Error with AI model (${model}).`;
365 let statusCode = error.status || error.response?.status;
366 if (statusCode === 401) errorMessage = "OpenAI Auth Error (401). Check Val Town 'openai' secret.";
367 else if (statusCode === 429) errorMessage = "OpenAI Rate Limit/Quota Error (429). Check OpenAI plan.";
368 else if (statusCode === 400) errorMessage = `OpenAI Bad Request (400). Details: ${error.message}`;
369 else if (statusCode >= 500) errorMessage = `OpenAI Server Error (${statusCode}). Try again later.`;
370 else if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED")
371 errorMessage = `Network Error (${error.code}). Cannot connect to OpenAI.`;
372 else if (error.message.includes("secret")) errorMessage = error.message;
373 else errorMessage += ` Details: ${error.message}`;
464 currentPrompt = currentPrompt.replace("{{CONTEXT}}", ""); // No inter-hat context for MVP
465
466 const hatResponse = await callOpenAI(currentPrompt, trimmedQuery); // Pass original query as user message
467
468 // Log response or error
495 .replace("{{COLLECTED_OUTPUTS}}", outputsText);
496
497 const summaryResponse = await callOpenAI(finalPrompt, "Synthesize the collected outputs.");
498
499 conversationLog.push({ agent: "Blue Hat", message: summaryResponse.content }); // Log summary or error

Lifesyncmain.tsx20 matches

@GetUpdated 2 weeks ago
5 * User queries are routed, analyzed collaboratively, and synthesized into holistic advice.
6 * Based on the Multi-Agent AI Support Simulation structure.
7 * Uses OpenAI via /v/std/openai.
8 *
9 * Last Updated: 2025-04-18
171 <p class="description">
172 Your Personal Life Operating System. Integrate goals, wellness, career, finances, relationships, and creativity.
173 <br>How can LifeSync help you synchronize your life today? (Using OpenAI via <code>/v/std/openai</code>)
174 <br>Current Date: ${currentDate}
175 </p>
322// Includes LifeSync agent flow
323export default async function(req: Request) {
324 const { OpenAI } = await import("https://esm.town/v/std/openai");
325
326 // --- Helper Function: Call OpenAI API ---
327 // (Mostly unchanged, but updated the JSON mode check)
328 async function callOpenAI(
329 systemPrompt: string,
330 userMessage: string,
332 ): Promise<{ role: "assistant" | "system"; content: string }> {
333 try {
334 // Ensure OPENAI_API_KEY is set in Val Town secrets (environment variable)
335 const openai = new OpenAI();
336
337 const response = await openai.chat.completions.create({
338 model: model,
339 messages: [
347
348 if (!response.choices?.[0]?.message?.content) {
349 console.error("OpenAI API returned an unexpected or empty response structure:", JSON.stringify(response));
350 throw new Error("Received invalid or empty response from AI model.");
351 }
357 } catch (error) {
358 console.error(
359 `OpenAI API call failed for model ${model}. System Prompt: ${systemPrompt.substring(0, 80)}... Error:`,
360 error,
361 );
365 let statusCode = error.status || (error.response ? error.response.status : null);
366 if (error.response && error.response.data && error.response.data.error) {
367 errorMessage = `OpenAI Error (${statusCode || "unknown status"}): ${
368 error.response.data.error.message || JSON.stringify(error.response.data.error)
369 }`;
372 }
373 if (statusCode === 401)
374 errorMessage = "OpenAI API Error (401): Authentication failed. Verify API key secret ('openai').";
375 else if (statusCode === 429) errorMessage = "OpenAI API Error (429): Rate limit or quota exceeded.";
376 else if (statusCode === 400) errorMessage = `OpenAI API Error (400): Bad Request. ${error.message || ""}`;
377 else if (statusCode >= 500) errorMessage = `OpenAI Server Error (${statusCode}): Issue on OpenAI's side.`;
378 else if (error.code === "ENOTFOUND" || error.code === "ECONNREFUSED")
379 errorMessage = `Network Error (${error.code}): Cannot connect to OpenAI API.`;
380
381 // Return error: JSON for Routing agent, plain text for others
442 // --- 1. Routing Step ---
443 conversationLog.push({ agent: "⚙️ System", message: "Contacting Query Routing Agent..." });
444 const routingResponse = await callOpenAI(routingAgentSystemPrompt, trimmedQuery);
445
446 let relevantDomains: string[] = ["GENERAL"]; // Default
449 let routingLogMessage = "";
450
451 if (routingResponse.role === "system") { // Error from callOpenAI
452 routingLogMessage = routingResponse.content; // Log the system error
453 routingFailed = true;
525
526 // Pass the summary from the routing agent to the specialist agent
527 const specialistResponse = await callOpenAI(agentDetails.prompt, summary);
528
529 if (specialistResponse.role === "system") {
573
574 // Use a potentially stronger model for synthesis if needed
575 const synthesisResponse = await callOpenAI(
576 synthesisInput,
577 "Synthesize the above into a cohesive response for the user.",

stevensDemo.cursorrules4 matches

@jedUpdated 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

@leroygUpdated 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" },

testOpenAI1 file match

@stevekrouseUpdated 1 day ago

testOpenAI1 file match

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