89export default async function server(request: Request): Promise<Response> {
90 if (request.method === "POST" && new URL(request.url).pathname === "/generate") {
91 const { OpenAI } = await import("https://esm.town/v/std/openai");
92 const openai = new OpenAI();
93
94 try {
95 const { topic } = await request.json();
96
97 const completion = await openai.chat.completions.create({
98 model: "gpt-4o-mini",
99 messages: [
137
138 const flashcardsResponse = completion.choices[0].message.content;
139 console.log("Raw OpenAI response:", flashcardsResponse); // Detailed debug logging
140
141 // More robust JSON parsing with extensive error handling
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" },
2import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
3import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
4import { OpenAI } from "https://esm.town/v/std/openai";
5import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
6
113export default async function server(request: Request): Promise<Response> {
114 if (request.method === "POST") {
115 const openai = new OpenAI();
116 const KEY = "EEPMOnitoring";
117
157 if (existingArticle.rows.length === 0) {
158 try {
159 const analysis = await openai.chat.completions.create({
160 model: "gpt-4o-mini",
161 messages: [
188 });
189 } catch (aiError) {
190 console.error("OpenAI analysis error:", aiError);
191 // Fallback analysis
192 await sqlite.execute(
1import { Bot } from "https://esm.sh/grammy@1.25.0";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { XMLParser } from "npm:fast-xml-parser";
4
35}
36
37const openai = new OpenAI();
38const bot = new Bot(TELEGRAM_TOKEN);
39
49
50async function summarizeDescription(item: RSSItem): Promise<string> {
51 const completion = await openai.chat.completions.create({
52 messages: [
53 {
1import { Hono } from "https://esm.sh/hono@4.7.7";
2import OpenAI from "https://esm.sh/openai@4.96.0";
3import { z } from "https://esm.sh/zod@3.24.3";
4import { zValidator } from "https://esm.sh/@hono/zod-validator@0.4.3?deps=hono@4.7.7,zod@3.24.3";
5
6const openai = new OpenAI();
7
8/**
9 * Transcribe audio from base64 string using OpenAI Whisper API
10 *
11 * @param audioB64 Base64 encoded audio data or URL
18 const audioFile = new File([audioBlob], "audio.mp3", { type: "audio/mp3" });
19
20 const transcription = await openai.audio.transcriptions.create({
21 file: audioFile,
22 model: "whisper-1",
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
216
217export default async function server(request: Request): Promise<Response> {
218 const { OpenAI } = await import("https://esm.town/v/std/openai");
219 const openai = new OpenAI();
220
221 if (request.method === 'POST' && new URL(request.url).pathname === '/chat') {
225 async start(controller) {
226 try {
227 const chatCompletion = await openai.chat.completions.create({
228 model: "gpt-4o-mini",
229 messages: [
244 }
245 } catch (error) {
246 console.error('OpenAI Error:', error);
247 controller.enqueue(new TextEncoder().encode('Sorry, there was an error processing your request.'));
248 } finally {
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
543 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
544 const { blob } = await import("https://esm.town/v/std/blob");
545 const { OpenAI } = await import("https://esm.town/v/std/openai");
546 const openai = new OpenAI();
547 const KEY = "Emotional_Companion";
548
646
647 try {
648 const completion = await openai.chat.completions.create({
649 messages: [
650 {
666 });
667 } catch (error) {
668 console.error("OpenAI Error:", error);
669 const fallbackResponses = [
670 "I'm here for you. Let's take a moment to breathe and reflect.",
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const MODEL = "gpt-4";
6
7async function generateRelatedIdeasBatch(
8 openai: OpenAI,
9 centerIdea: string,
10 count: number = 9,
11): Promise<{ matrix: string[][] } | null> {
12 try {
13 const response = await openai.chat.completions.create({
14 model: MODEL,
15 messages: [
54 const direction = url.searchParams.get("direction");
55
56 const openai = new OpenAI();
57 let matrixToRender: string[][] = [Array(GRID_SIZE).fill("...")];
58
59 if (centerIdea && direction) {
60 const result = await generateRelatedIdeasBatch(openai, centerIdea);
61 if (result && result.matrix) {
62 matrixToRender = result.matrix;
65 }
66 } else if (initialIdea) {
67 const result = await generateRelatedIdeasBatch(openai, initialIdea);
68 if (result && result.matrix) {
69 matrixToRender = result.matrix;