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/...?q=openai&page=30&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 2265 results for "openai"(1399ms)

untitled-7672main.tsx11 matches

@join•Updated 2 weeks ago
922export default async function(req: Request) {
923 // --- Dynamic Imports ---
924 const { OpenAI } = await import("https://esm.town/v/std/openai"); // Updated import path
925 const { z } = await import("npm:zod"); // For input validation
926
927 // --- Helper Function: Call OpenAI API ---
928 async function callOpenAIForCrux(
929 openai: OpenAI, // Instance passed in
930 systemPrompt: string,
931 userMessage: string,
932 ): Promise<object | ErrorResponse> { // Returns parsed JSON object or an ErrorResponse
933 try {
934 const response = await openai.chat.completions.create({
935 model: "gpt-4o", // Or your preferred model
936 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
943 return JSON.parse(content) as CruxAnalysisResponse; // Assume it's the correct type
944 } catch (parseError) {
945 console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content);
946 return { error: `AI response was not valid JSON. Raw: ${content.substring(0, 200)}...` };
947 }
948 } catch (error) {
949 console.error("OpenAI API call failed:", error);
950 return { error: "Error communicating with AI model.", details: error.message };
951 }
956 userInstruction: string,
957 ): Promise<object | ErrorResponse> {
958 const openai = new OpenAI(); // Initialize with key
959
960 console.log(`Analyzing instruction: "${userInstruction}"`);
961 const result = await callOpenAIForCrux(openai, cruxSystemPrompt, userInstruction);
962 // Basic validation of the result structure (can be enhanced with Zod on server side too)
963 if ("error" in result) {
965 }
966 if (!result || typeof result !== "object" || !("original_instruction" in result) || !("crux_points" in result)) {
967 console.error("Invalid structure from OpenAI:", result);
968 return { error: "AI returned an unexpected data structure.", details: result };
969 }
1015 return new Response(JSON.stringify(cruxDataOrError), {
1016 status: (cruxDataOrError.error.includes("Server configuration error")
1017 || cruxDataOrError.error.includes("OpenAI API Key"))
1018 ? 500
1019 : 400, // Internal or Bad Request

ffffindex.ts4 matches

@hard•Updated 2 weeks ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import type { PoemRequest, PoemResponse } from "../shared/types.ts";
30 }
31
32 const openai = new OpenAI();
33
34 // Create a detailed prompt for poem generation
45 Format your response as JSON with "title" and "poem" fields.`;
46
47 const completion = await openai.chat.completions.create({
48 messages: [
49 {
60 const content = completion.choices[0]?.message?.content;
61 if (!content) {
62 throw new Error("No response from OpenAI");
63 }
64

ffffREADME.md2 matches

@hard•Updated 2 weeks ago
5## Features
6
7- AI-powered poem generation using OpenAI
8- Subtle abstract art backgrounds that complement the text
9- Responsive design with elegant typography
28## Environment Variables
29
30- `OPENAI_API_KEY` - Required for poem generation

ContentGenREADME.md2 matches

@Ermd33s•Updated 2 weeks ago
1# Jeropay Social Media Caption Generator
2
3A beautiful web application that generates creative social media captions for the Jeropay team using OpenAI's GPT-4o-mini model.
4
5## Features
66
67- **Frontend**: React 18.2.0 with TypeScript
68- **Backend**: Hono framework with OpenAI integration
69- **Styling**: TailwindCSS with custom glass morphism effects
70- **AI Model**: GPT-4o-mini (free tier)

ContentGenindex.ts5 matches

@Ermd33s•Updated 2 weeks ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4
29 }
30
31 const openai = new OpenAI();
32
33 const systemPrompt = `You're a creative content writer working with the Jeropay team on a social media campaign for the month of June. Based on the following topic, generate 5 short, catchy, and audience-friendly captions or content ideas. The tone should be helpful, positive, and aligned with young professionals and creatives. Avoid generic phrases, and focus on engaging hooks or action-oriented copy.`;
35 const userPrompt = `Topic: ${topic}\n\nCaptions:`;
36
37 const completion = await openai.chat.completions.create({
38 model: "gpt-4o-mini",
39 messages: [
64 }
65
66 const openai = new OpenAI();
67
68 const systemPrompt = `You're a creative content writer working with the Jeropay team on a social media campaign for the month of June. Based on the following topic, generate 5 short, catchy, and audience-friendly captions or content ideas. The tone should be helpful, positive, and aligned with young professionals and creatives. Avoid generic phrases, and focus on engaging hooks or action-oriented copy.`;
70 const userPrompt = `Topic: ${topic}\n\nCaptions:`;
71
72 const completion = await openai.chat.completions.create({
73 model: "gpt-4o-mini",
74 messages: [

openaiproxyREADME.md3 matches

@MM05•Updated 2 weeks ago
1# OpenAI Proxy
2
3This OpenAI API proxy injects Val Town's API keys. For usage documentation, check out https://www.val.town/v/std/openai
4
5Migrated from folder: openai/openaiproxy

openaiproxymain.tsx8 matches

@MM05•Updated 2 weeks ago
1import { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";
2import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
3import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";
4import { RateLimit } from "npm:@rlimit/http";
5const client = new OpenAIUsage();
6
7const allowedPathnames = [
43
44 // Proxy the request
45 const url = new URL("." + pathname, "https://api.openai.com");
46 url.search = search;
47
48 const headers = new Headers(req.headers);
49 headers.set("Host", url.hostname);
50 headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`);
51 headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG"));
52
53 const modifiedBody = await limitFreeModel(req, user);
64 });
65
66 const openAIRes = await fetch(url, {
67 method: req.method,
68 headers,
72
73 // Remove internal header
74 const res = new Response(openAIRes.body, openAIRes);
75 res.headers.delete("openai-organization");
76 return res;
77}

Valod.cursorrules4 matches

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

untitled-4336main.tsx12 matches

@Get•Updated 2 weeks ago
2// This is your detailed system prompt that instructs the AI on how to identify crux points
3
4import { OpenAI } from "https://esm.town/v/std/openai";
5
6// and structure the output JSON.
802export default async function(req: Request) {
803 // --- Dynamic Imports ---
804 const { OpenAI } = await import("https://esm.town/v/std/openai"); // Updated import path
805 const { z } = await import("npm:zod"); // For input validation
806
807 // --- Helper Function: Call OpenAI API ---
808 async function callOpenAIForCrux(
809 openai: OpenAI, // Instance passed in
810 systemPrompt: string,
811 userMessage: string,
812 ): Promise<object | ErrorResponse> { // Returns parsed JSON object or an ErrorResponse
813 try {
814 const response = await openai.chat.completions.create({
815 model: "gpt-4o", // Or your preferred model
816 messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
823 return JSON.parse(content) as CruxAnalysisResponse; // Assume it's the correct type
824 } catch (parseError) {
825 console.error("OpenAI JSON Parse Error:", parseError, "Raw Content:", content);
826 return { error: `AI response was not valid JSON. Raw: ${content.substring(0, 200)}...` };
827 }
828 } catch (error) {
829 console.error("OpenAI API call failed:", error);
830 return { error: "Error communicating with AI model.", details: error.message };
831 }
837 ): Promise<object | ErrorResponse>
838 {
839 const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // Initialize with key
840
841 console.log(`Analyzing instruction: "${userInstruction}"`);
842 const result = await callOpenAIForCrux(openai, cruxSystemPrompt, userInstruction);
843 // Basic validation of the result structure (can be enhanced with Zod on server side too)
844 if ("error" in result) {
846 }
847 if (!result || typeof result !== "object" || !("original_instruction" in result) || !("crux_points" in result)) {
848 console.error("Invalid structure from OpenAI:", result);
849 return { error: "AI returned an unexpected data structure.", details: result };
850 }
896 return new Response(JSON.stringify(cruxDataOrError), {
897 status: (cruxDataOrError.error.includes("Server configuration error")
898 || cruxDataOrError.error.includes("OpenAI API Key"))
899 ? 500
900 : 400, // Internal or Bad Request

VA-TASK-BRAINindex.ts4 matches

@aishatyy•Updated 2 weeks ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import type { TaskAnalysis, AnalyzeRequest } from "../shared/types.ts";
11});
12
13const openai = new OpenAI();
14
15// Serve static files
63}`;
64
65 const completion = await openai.chat.completions.create({
66 messages: [
67 { role: "system", content: "You are a helpful virtual assistant consultant who provides clear, actionable advice. Always respond with valid JSON only." },
76 const responseText = completion.choices[0]?.message?.content;
77 if (!responseText) {
78 throw new Error("No response from OpenAI");
79 }
80

openai-client4 file matches

@cricks_unmixed4u•Updated 17 hours ago

openai_enrichment6 file matches

@stevekrouse•Updated 1 week ago
kwhinnery_openai
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai"; import { sqlite } from "https://esm.town/v/stevekrouse/sqlite"; /** * Practical Implementation of Collective Content Intelligence * Bridging advanced AI with collaborative content creation */ exp