Search

4,104 results found for β€œopenai” (1215ms)

Code
3,998

import { Hono } from "npm:hono@4.4.8";
import { streamSSE } from "npm:hono@4.4.8/streaming";
import { createOpenAI } from "npm:@ai-sdk/openai@latest";
import { createAnthropic } from "npm:@ai-sdk/anthropic@latest";
import { createGoogleGenerativeAI } from "npm:@ai-sdk/google@latest";
// Default columns to show on load (provider and model pairs)
defaultColumns: [
{ provider: "openai", model: "gpt-5.2" },
{ provider: "anthropic", model: "claude-opus-4-5-20251101" },
{ provider: "google", model: "gemini-3-pro-preview" },
// Provider configurations
const providers = {
openai: () => createOpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") || "" }),
anthropic: () =>
createAnthropic({ apiKey: Deno.env.get("ANTHROPIC_API_KEY") || "" }),
{ id: string; name: string; icon: string }[]
> = {
openai: [
{ id: "gpt-5.2", name: "GPT-5.2", icon: "πŸš€" },
{ id: "o3", name: "o3 (Reasoning)", icon: "🧠" },
}
> = {
openai: {
name: "OpenAI",
color: "#10a37f",
gradient: "from-emerald-400 via-teal-500 to-cyan-600",
opacity: 0.8;
}
.accent-line.openai { background: linear-gradient(90deg, transparent, #10a37f, transparent);
.accent-line.anthropic { background: linear-gradient(90deg, transparent, #f97316, transparen
.accent-line.google { background: linear-gradient(90deg, transparent, #6366f1, transparent);
}
function createColumn(defaultProvider = 'openai', defaultModel = 'gpt-4o') {
const id = columnId++;
const column = {
class="select-modern w-full bg-zinc-800/80 border border-zinc-700/50 rounded
>
<option value="openai" \${defaultProvider === 'openai' ? 'selected' : ''}>Op
<option value="anthropic" \${defaultProvider === 'anthropic' ? 'selected' :
<option value="google" \${defaultProvider === 'google' ? 'selected' : ''}>Go
// Update card class
const columnEl = document.getElementById(\`column-\${id}\`);
columnEl.classList.remove('openai', 'anthropic', 'google');
columnEl.classList.add(provider);
// Update accent line
const accentLine = columnEl.querySelector('.accent-line');
accentLine.classList.remove('openai', 'anthropic', 'google');
accentLine.classList.add(provider);
function addColumn() {
const providers = ['openai', 'anthropic', 'google'];
const existingProviders = Array.from(columns.values()).map(c => c.provider);
let newProvider = providers.find(p => !existingProviders.includes(p)) || providers[columns
switch (provider) {
case "openai":
aiModel = providers.openai()(model);
break;
case "anthropic":
// Val Town stdlib
import { sqlite } from "https://esm.town/v/std/sqlite";
import { OpenAI } from "https://esm.town/v/std/openai";
import {
listFiles,
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ database.ts # SQLite schema & queries (user-scoped)
β”‚ β”œβ”€β”€ ai.ts # OpenAI tag generation
β”‚ └── youtube.ts # YouTube Data API v3 calls
β”œβ”€β”€ frontend/
- Save YouTube URLs (paste, drag-drop, or input)
- Automatic video metadata fetching (title, channel, thumbnail)
- AI-powered auto-tagging (category, subcategory, tags) using OpenAI
- Edit video details (title, category, subcategory, tags, rating, watched
status)
1. fix: `TypeError
TypeError: Class constructor OpenAI cannot be invoked without 'new'
at https://esm.town/v/arfan/yt_drop_v2@33-main/backend/ai.ts:7:16`
### Planner Response
I can see the issue! At line 7, you're calling `OpenAI()` without the `new` keyword. The error m
*Searched web for Val Town std openai usage example*
### Planner Response
Let me get more details on the actual implementation:
*Read URL content from /v/std/openai *
*Viewed content chunk*
### Planner Response
rding to the Val Town documentation, you need to use `new OpenAI()` instead of just `OpenAI()`.
*Edited relevant file*
## βœ… Fixed!
The issue was on **line 7** where you were calling `OpenAI()` without the `new` keyword. The `Op
**What I changed:**
```diff
- const openai = OpenAI();
+ const openai = new OpenAI();
```
This is the correct way to use Val Town's OpenAI wrapper, as shown in their [official documentat
*User accepted the command `vt push && for i in {2..1}; do echo -ne "\rWaiting: $i seconds...";
## βœ… Fixed: File System Error
I've resolved the `TypeError: Class constructor OpenAI cannot be invoked without 'new'` error an
### Changes Made:
1. **Fixed OpenAI instantiation** ([backend/ai.ts](cci:7://file:///Users/clock2/Developer/vt/yt_
- Changed `const openai = OpenAI();` to `const openai = new OpenAI();`
2. **Fixed file serving** ([app.http.ts](cci:7://file:///Users/clock2/Developer/vt/yt_drop_v2/ap
The error in the logs was `Error: Invalid ESM Town URL format: ./frontend/index.html` because I
/Developer/vt/yt_drop_v2/AGENTS.md:0:0-0:0) confirms `new OpenAI()` is the correct way (line 100
Let's fix [app.http.ts](cci:7://file:///Users/clock2/Developer/vt/yt_drop_v2/app.http.ts:0:0-0:0
I will update the prompt to include:
- `new OpenAI()`
- Correct `serveFile` and `readFile` usage.
- The `/api/user` endpoint pattern instead of `window.__HYDRATED_EMAIL__` if we want to avoid in
### Key Updates to the Prompt:
1. **OpenAI**: Explicitly specify the use of `new OpenAI()` to avoid constructor errors.
2. **File Serving**: Updated all `serveFile` and `readFile` examples to use the correct signatu
3. **Hono Context**: Added proper TypeScript generic types for Hono variables (`new Hono<{ Vari
### Summary of Fixes:
1. **OpenAI Constructor Fix**: Resolved the `TypeError` by properly instantiating the OpenAI cl
2. **File System & Serving Fix**: Resolved the "No such file or directory" and "Invalid ESM Tow
* Using the correct Val Town utility patterns: `serveFile(c.req.path, import.meta.url)` an
I've significantly updated [_docs/SONNET_4.5_PROMPT.md](cci:7://file:///Users/clock2/Developer/v
* The correct **OpenAI constructor** syntax.
* **Best practices for file serving** using `import.meta.url`.
* A **modern authentication pattern** that uses a separate API endpoint for user info, making
#### [NEW] [ai.ts](file:///Users/clock2/Developer/vt/yt_drop_v2/backend/ai.ts)
OpenAI-powered tag generation:
- `generateTags()` - Analyzes video title/description to suggest category,
subcategory, and tags
- Uses Val Town's OpenAI integration
- Structured JSON response parsing
YouTube Data API v3 integration with oEmbed fallback
- **[ai.ts](file:///Users/clock2/Developer/vt/yt_drop_v2/backend/ai.ts)** -
OpenAI-powered tag generation
### Main Application
### βœ… AI-Powered Features
- OpenAI GPT-4o-mini integration
- Automatic category, subcategory, and tag generation
- Manual tag regeneration via edit modal
- LastLogin automatically handles OAuth - no manual configuration needed
- YouTube API has daily quota limits (check Google Cloud Console)
- OpenAI calls use Val Town's standard OpenAI integration
- All data is stored in Val Town's SQLite database (persistent)
// AI-powered tag generation using OpenAI
import { OpenAI } from "https://esm.town/v/std/openai";
import type { AITagsResponse } from "../shared/types.ts";
import { DEFAULT_CATEGORIES } from "../shared/constants.ts";
const openai = new OpenAI();
/**
}`;
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
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" },
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 { readFile } from "https://esm.town/v/std/utils/index.ts";
import { Agent, run, webSearchTool } from "npm:@openai/agents@0.3.0";
import { storeLead } from "./db.ts";
const d = inputData.data || inputData;
if (!Deno.env.get("OPENAI_API_KEY")) {
const outputData = {
...Object.fromEntries(PASSTHROUGH_KEYS.map(k => [k, d[k] ?? ""])),
match: null,
reasoning: "Set OPENAI_API_KEY environment variable to enable AI research",
};
await storeLead(inputData, outputData);
…
8
…