128</div>
129<div class="border rounded-lg p-4">
130<h3 class="font-semibold text-orange-600 mb-2">🤖 OpenAI</h3>
131<ul class="text-sm text-gray-600 space-y-1">
132<li>• openai_chat</li>
133</ul>
134</div>
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
my-first-valai-analysis.ts7 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
2import type { AnalysisResponse } from "../../shared/types.ts";
34const openai = new OpenAI();
56export async function analyzeImage(imageData: string, fileName: string): Promise<AnalysisResponse> {
9const base64Data = imageData.replace(/^data:image\/[a-z]+;base64,/, '');
10
11const response = await openai.chat.completions.create({
12model: "gpt-4o-mini",
13messages: [
88const audioFile = new File([audioBlob], fileName, { type: 'audio/wav' });
89
90const transcription = await openai.audio.transcriptions.create({
91file: audioFile,
92model: "whisper-1",
96
97// Analyze the transcribed text
98const textAnalysis = await openai.chat.completions.create({
99model: "gpt-4o-mini",
100messages: [
160// In practice, you'd need to extract frames from the video
161
162const response = await openai.chat.completions.create({
163model: "gpt-4o-mini",
164messages: [
212export async function generateSearchSuggestions(query: string): Promise<string[]> {
213try {
214const response = await openai.chat.completions.create({
215model: "gpt-4o-mini",
216messages: [
my-first-valREADME.md4 matches
8- **Multi-Media Support**: Image, video, and audio recognition
9- **Real-time Capture**: In-browser media capture capabilities
10- **AI Analysis**: Powered by OpenAI's vision and audio models
11- **Intelligent Search**: Find similar content based on descriptions
12- **Secure Storage**: User data and media metadata stored securely
42## Technology Stack
4344- **Backend**: Hono, SQLite, OpenAI API
45- **Frontend**: React, TailwindCSS
46- **AI/ML**: OpenAI GPT-4 Vision, Whisper
47- **Storage**: Val Town Blob storage
48- **Authentication**: JWT-based sessions
51521. Set up environment variables:
53- `OPENAI_API_KEY`: Your OpenAI API key
54- `JWT_SECRET`: Secret for JWT token signing
55
blog-3get-old-posts.ts5 matches
198},
199{
200"title": "An Introduction to OpenAI fine-tuning",
201"slug": "an-introduction-to-openai-fine-tuning",
202"link": "/blog/an-introduction-to-openai-fine-tuning",
203"description": "How to customize OpenAI to your liking",
204"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205"author": "Steve Krouse",
417"slug": "val-town-newsletter-16",
418"link": "/blog/val-town-newsletter-16",
419"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421"author": "Steve Krouse",
1516// Get your API key from Val.town environment variables
17const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
18const ASSISTANT_ID = Deno.env.get("ASSISTANT_ID");
1920if (!OPENAI_API_KEY || !ASSISTANT_ID) {
21throw new Error(
22"Missing API key or Assistant ID in environment variables. Please set OPENAI_API_KEY and ASSISTANT_ID.",
23);
24}
29if (!threadId || threadId === "") {
30console.log("Creating new thread...");
31const threadResponse = await fetch("https://api.openai.com/v1/threads", {
32method: "POST",
33headers: {
34"Authorization": `Bearer ${OPENAI_API_KEY}`,
35"Content-Type": "application/json",
36"OpenAI-Beta": "assistants=v2",
37},
38body: JSON.stringify({}),
51// Add message and run assistant
52console.log("Running assistant...");
53const runResponse = await fetch(`https://api.openai.com/v1/threads/${threadId}/runs`, {
54method: "POST",
55headers: {
56"Authorization": `Bearer ${OPENAI_API_KEY}`,
57"Content-Type": "application/json",
58"OpenAI-Beta": "assistants=v2",
59},
60body: JSON.stringify({
8788const statusResponse = await fetch(
89`https://api.openai.com/v1/threads/${threadId}/runs/${runId}`,
90{
91headers: {
92"Authorization": `Bearer ${OPENAI_API_KEY}`,
93"OpenAI-Beta": "assistants=v2",
94},
95},
114console.log("Getting messages...");
115const messagesResponse = await fetch(
116`https://api.openai.com/v1/threads/${threadId}/messages?order=desc&limit=1`,
117{
118headers: {
119"Authorization": `Bearer ${OPENAI_API_KEY}`,
120"OpenAI-Beta": "assistants=v2",
121},
122},
Glancer3Remix.cursorrules4 matches
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
9596### OpenAI
9798```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102messages: [
103{ role: "user", content: "Say hello in a creative way" },
regexToBrainrotmain.tsx4 matches
300{ getRandomRegexExplanation, saveRegexExplanation, getRegexExplanationById },
301ReactMarkdown,
302{ OpenAI },
303{ renderToString },
304{ jsx, jsxs, Fragment },
306import("https://esm.town/v/stainless_em/brainrotdb"),
307import("npm:react-markdown@7"),
308import("https://esm.town/v/std/openai"),
309import("npm:react-dom@19/server.browser"),
310import("npm:react@19/jsx-runtime"),
336}
337338const openai = new OpenAI();
339340const abortController = new AbortController();
341const completion = await openai.chat.completions.create({
342messages: [
343{
untitled-7610main.tsx25 matches
6* Users input their birth details, a sign to focus on, and a life domain.
7* The backend then uses the "Astrologer Prompt" (a detailed system prompt)
8* to query an OpenAI model, which generates a comprehensive astrological report.
9*
10* Core Logic:
13* 2. Backend (Deno Val Function):
14* - Receives these inputs.
15* - Constructs a user message for the OpenAI API. This message includes
16* the raw birth details, focus sign, domain, etc.
17* - Uses the **ENTIRE** "Astrologer Prompt" (with {{sign}} and {{domain}}
18* placeholders filled) as the system prompt for an OpenAI API call.
19* - Calls a powerful OpenAI model (e.g., gpt-4o).
20* - Receives the structured JSON astrological report from OpenAI.
21* - Sends this report back to the client for display.
22*
30* May 28, 2025. The LLM primed by it is assumed to have access to or
31* knowledge of transit data for this date.
32* - OpenAI API Key: An `OPENAI_API_KEY` environment variable must be available
33* in the Val Town environment for `std/openai` to work.
34*
35* Inspired by the structure of the "Goal-Oriented Multi-Agent Stock Analysis Val".
3940// --- Imports ---
41import { OpenAI } from "https://esm.town/v/std/openai";
42// NOTE: Deno.env is used directly for environment variables.
4355}
5657// --- THE ASTROLOGER PROMPT (System Prompt for OpenAI) ---
58// This will be used by the backend to instruct the AI.
59// Placeholders {{sign}} and {{domain}} will be replaced dynamically.
411}
412413// --- Helper Function: Call OpenAI API (Adapted - Robust error handling retained) ---
414async function callOpenAI(
415systemPrompt: string,
416userMessage: string,
422// Simple hash for prompt might not be as useful if {{placeholders}} change content significantly.
423// Consider logging snippet of system prompt if needed for debugging.
424const logPrefix = `OpenAI Call [${callId}] (${model}, JSON: ${isJsonOutputRequired})`;
425log(
426`[INFO] ${logPrefix}: Initiating... System prompt (template used). User message snippet: ${
430431try {
432const openai = new OpenAI(); // API Key from environment
433const response = await openai.chat.completions.create({
434model: model,
435messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
439const content = response.choices?.[0]?.message?.content;
440if (!content) {
441log(`[ERROR] ${logPrefix}: OpenAI API returned unexpected or empty response structure.`);
442throw new Error("Received invalid or empty response content from AI model.");
443}
444log(`[SUCCESS] ${logPrefix}: OpenAI call successful.`);
445return { role: "assistant", content: content };
446} catch (error) {
452453if (errorResponseData?.message) {
454errorMessage = `OpenAI Error (${statusCode || "unknown status"}): ${errorResponseData.message}`;
455} else if (errorResponseData?.error?.message) {
456errorMessage = `OpenAI Error (${statusCode || "unknown status"}): ${errorResponseData.error.message}`;
457}
458// ... (retain other specific error message constructions from original Val)
486.replace(new RegExp("{{domain}}", "g"), inputs.focusDomain);
487488// 2. Construct the User Message for the OpenAI API call
489// The Astrologer Prompt expects `birth_chart_data`. We will pass raw birth details
490// and let the LLM (primed with Astrologer Prompt) handle interpretation.
509);
510511// 3. Call OpenAI
512log("[STEP] Calling OpenAI with Astrologer Prompt...");
513// Using gpt-4o as it's capable and the astrological prompt is complex.
514// The ASTROLOGER_SYSTEM_PROMPT_TEMPLATE implies the model should generate JSON.
515const aiResponse = await callOpenAI(populatedSystemPrompt, userMessageJson, "gpt-4o", true, log);
516517// 4. Parse and Return Result
522// (e.g., if the AI itself couldn't perform the analysis and returned an error structure as per its instructions)
523// The ASTROLOGER_SYSTEM_PROMPT_TEMPLATE does not explicitly define an error structure from the AI side,
524// but callOpenAI returns its own {"error": "..."} if the call itself failed.
525if (parsedAiResponse.error && aiResponse.role === "system") { // Error from callOpenAI wrapper
526log(`[ERROR] OpenAI call wrapper reported an error: ${parsedAiResponse.error}`);
527return { error: "Failed to get report from Astrologer AI.", details: parsedAiResponse.error };
528}
personalShopper.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },