Search

3,341 results found for openai (1783ms)

Code
3,246

join/shine/main.tsx
12 matches
import { Hono } from "npm:hono@4.4.12";
import type { Context } from "npm:hono@4.4.12";
import { OpenAI } from "npm:openai@4.52.7";
// --- TYPE DEFINITIONS ---
if (!industry) return c.json({ error: "Industry is a required field." }, 400);
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: DYNAMIC_LIST_GENERATOR_PROMPT }, {
if (!occupation) return c.json({ error: "Occupation is a required field." }, 400);
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: DYNAMIC_LIST_GENERATOR_PROMPT }, {
const userInput = `Occupation: ${occupation_title}, Task: ${task}`;
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: PROMPT_REFINER_SYSTEM_PROMPT }, { role: "user", cont
if (!refined_prompt) return c.json({ error: "refined_prompt is required" }, 400);
try {
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: INPUT_EXTRACTOR_SYSTEM_PROMPT }, {
try {
const openai = new OpenAI();
const agentCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: finalUserPrompt }, {
if (!agentOutput) throw new Error("The agent returned no content.");
const htmlCompletion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: HTML_FORMATTER_SYSTEM_PROMPT }, { role: "user", cont
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
import { Hono } from "npm:hono@4.4.12";
// --- BACKEND LOGIC ---
const app = new Hono();
const openai = new OpenAI();
async function generatePersonaPrompt(occupation: string, task: string) {
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
error: "Quota Exceeded",
message:
"The application's OpenAI quota has been exceeded. Please check the account dashboard on
}, 429);
}
const { image } = await c.req.json();
if (!image) return c.json({ error: "Image is required." }, 400);
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
}
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: history,
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
import { Hono } from "npm:hono@4.4.12";
// @ts-ignore
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
// --- META-PROMPTS: The Engine's Core Logic ---
// --- BACKEND: The Hono API ---
const app = new Hono();
const openai = new OpenAI();
async function getOpenAIResponse(systemPrompt, userMessages, jsonResponse = false) {
try {
const response = await openai.chat.completions.create({
model: "gpt-4-turbo",
messages: [
return response.choices[0].message.content;
} catch (e) {
console.error("OpenAI API error:", e.message);
throw new Error("Failed to get response from AI model.");
}
}
async function getOpenAIStream(systemPrompt, luggage) {
let finalPrompt = systemPrompt;
for (const key in luggage) {
}
return openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "system", content: finalPrompt }],
const plannerPrompt = fillPrompt(META_PROMPTS.ROUTE_PLANNER, { goal });
try {
let itineraryJson = await getOpenAIResponse(plannerPrompt, [], true);
let itinerary = JSON.parse(itineraryJson);
if (!itinerary.stops || itinerary.stops.length === 0 || itinerary.stops.length > 5) {
const retryPrompt = fillPrompt(META_PROMPTS.ROUTE_PLANNER_RETRY, { goal });
itineraryJson = await getOpenAIResponse(retryPrompt, [], true);
itinerary = JSON.parse(itineraryJson);
}
// 1. Get the task specification from STOP_ARCHITECT
const specPrompt = fillPrompt(META_PROMPTS.STOP_ARCHITECT, { context, task });
const specJson = await getOpenAIResponse(specPrompt, [], true);
const spec = JSON.parse(specJson);
if (spec.inputs && spec.inputs.length > 0) {
const uiPrompt = fillPrompt(META_PROMPTS.UI_BUILDER, { spec: specJson });
const uiSchemaJson = await getOpenAIResponse(uiPrompt, [], true);
uiSchema = JSON.parse(uiSchemaJson);
}
// 3. Get the final execution prompt from LOGIC_WEAVER
const logicPrompt = fillPrompt(META_PROMPTS.LOGIC_WEAVER, { context, spec: specJson });
const prompt = await getOpenAIResponse(logicPrompt, []);
return c.json({ spec, uiSchema, prompt });
const { prompt, luggage } = await c.req.json();
try {
const stream = await getOpenAIStream(prompt, luggage);
return new Response(stream.toReadableStream(), {
headers: { "Content-Type": "text/event-stream" },
}
const { OpenAI } = await import("https://esm.town/v/std/openai");
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
const openai = new OpenAI();
const KEY = new URL(import.meta.url).pathname.split("/").at(-1);
const prompt = `You are an emoji summarizer. Respond with exactly ${count} emojis that summa
const res = await openai.chat.completions.create({
model: "gpt-4-mini",
messages: [
url: "https://dcm31--8f68e410697611f092f30224a6c84d84.web.val.run"
author: "dcm31"
tags: ["emoji", "openai", "val-town", "api"]
---
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
## ✨ Features
-**AI-Powered Conversion**: Uses OpenAI GPT-4o-mini to intelligently convert questions
-**Smart Caching**: Stores results to avoid redundant API calls
-**Rate Limiting**: Respects Val Town's OpenAI API limits (50 requests/minute)
-**TypeScript SDK**: Clean, typed interface for easy integration
-**Batch Processing**: Convert multiple questions with built-in rate limiting
## ⚡ Rate Limiting
The API includes intelligent rate limiting to respect Val Town's OpenAI API limits:
- **50 requests per minute** maximum
## 🔧 Technical Details
- **AI Model**: OpenAI GPT-4o-mini (via Val Town's built-in OpenAI integration)
- **Database**: SQLite for caching (via Val Town's SQLite integration)
- **Framework**: Hono for the web API
import { Hono } from "npm:hono";
import { cors } from "npm:hono/cors";
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
let requestCount = 0;
let resetTime = Date.now() + 60000; // Reset every minute
const RATE_LIMIT = 50; // Conservative limit per minute for OpenAI
async function checkRateLimit(): Promise<boolean> {
}
const openai = new OpenAI();
const prompt = `Convert this "when will" question into a declarative statement suitable for a
try {
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-4o-mini",
return statement;
} catch (error) {
console.error("OpenAI API error:", error);
throw new Error("Failed to convert question to statement");
}