209
210 try {
211 // More robust OpenAI import and initialization
212 const openaiModule = await import("https://esm.town/v/std/openai");
213
214 // Detailed logging and error checking
215 console.log("OpenAI Module:", Object.keys(openaiModule));
216
217 // Use a more flexible approach to accessing OpenAI
218 const OpenAI = openaiModule.default || openaiModule.OpenAI;
219
220 if (!OpenAI) {
221 throw new Error("Unable to find OpenAI constructor in the imported module");
222 }
223
224 const openai = new OpenAI({
225 // Add any necessary configuration if required
226 // For example: apiKey might be needed depending on the library version
227 });
228
229 // Verify the openai object has the required methods
230 if (!openai.chat || !openai.chat.completions || !openai.chat.completions.create) {
231 throw new Error("OpenAI object does not have the expected chat completion method");
232 }
233
244 };
245
246 const completion = await openai.chat.completions.create({
247 messages: [systemPrompt, ...messages],
248 model: "gpt-4o-mini",
259 if (url.pathname === '/generate-image') {
260 // Verify images method exists
261 if (!openai.images || !openai.images.generate) {
262 throw new Error("OpenAI object does not have the expected image generation method");
263 }
264
266 const { prompt, style, count } = body;
267
268 const imageResponse = await openai.images.generate({
269 model: "dall-e-3",
270 prompt: `A ${style} image of: ${prompt}.
2import React, { useState, useRef, useCallback, useEffect } from "https://esm.sh/react";
3import { createRoot } from "https://esm.sh/react-dom/client";
4import OpenAI from "https://esm.sh/openai";
5
6// Plant Database
121 const base64Image = reader.result.split(',')[1];
122
123 const openai = new OpenAI({
124 apiKey: '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',
125 dangerouslyAllowBrowser: true
127
128 try {
129 const response = await openai.chat.completions.create({
130 model: "gpt-4o",
131 messages: [
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { z } from "npm:zod";
3
33 }
34
35 const openai = new OpenAI();
36
37 const completion = await openai.chat.completions.create({
38 messages: [
39 { role: "user", content: prompt(topic, level.data, stage, difficulty.data) },
30 "settings": {
31 "model": "gpt-4o-mini",
32 "provider": "openai",
33 "system": "please summarize the following article in a 2-4 sentences, describing it from a 3rd person point of view",
34 "prompt": "{jina.content}"
18brian@airbnb.com,Brian Chesky
19drew@dropbox.com,Drew Houston
20sam@openai.com,Sam Altman
21tim@apple.com,Tim Cook
22jeff@amazon.com,Jeff Bezos
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
3
4let location = "munchen";
8).then(r => r.json());
9
10const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12 messages: [{
13 role: "user",
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const openai = new OpenAI();
4
5const completion = await openai.chat.completions.create({
6 messages: [
7 { role: "user", content: "C#怎么实现一个线程安全的求和" },
149
150 try {
151 // Dynamic imports for SQLite and OpenAI
152 const [{ sqlite }, { OpenAI }] = await Promise.all([
153 import("https://esm.town/v/stevekrouse/sqlite"),
154 import("https://esm.town/v/std/openai")
155 ]);
156
157 const openai = new OpenAI();
158 const SPECIFICATIONS_TABLE = "val_town_agent_specifications";
159 const IMPLEMENTATIONS_TABLE = "val_town_agent_implementations";
227
228 // Generate implementation using GPT-4o-mini
229 const completion = await openai.chat.completions.create({
230 messages: [
231 {
149 const webpageText = await webpageResponse.text();
150
151 // Use OpenAI as Claude proxy
152 const { OpenAI } = await import("https://esm.town/v/std/openai");
153 const openai = new OpenAI();
154
155 const completion = await openai.chat.completions.create({
156 messages: [
157 {
3import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84";
4import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken?v=1";
5import { openai } from "npm:@ai-sdk/openai";
6import ValTown from "npm:@valtown/sdk";
7import { streamText } from "npm:ai";
36
37 const stream = await streamText({
38 model: openai("gpt-4o", {
39 baseURL: "https://std-openaiproxy.web.val.run/v1",
40 apiKey: Deno.env.get("valtown"),
41 } as any),