114 if (new URL(request.url).pathname === '/generate-idea') {
115 try {
116 const { OpenAI } = await import("https://esm.town/v/std/openai");
117 const openai = new OpenAI();
118
119 const completion = await openai.chat.completions.create({
120 messages: [
121 {
303 console.log(`Received ${request.method} request to ${request.url}`);
304
305 const { OpenAI } = await import("https://esm.town/v/std/openai");
306 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
307 const openai = new OpenAI();
308 const url = new URL(request.url);
309
334 console.log("Generated prompt:", prompt);
335
336 const completion = await openai.chat.completions.create({
337 messages: [{ role: "user", content: prompt }],
338 model: "gpt-4o-mini",
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(request: Request) {
41 }
42
43 const openai = new OpenAI();
44
45 const summaryPrompt = "This is a news link: " + inputUrl
54
55 try {
56 // Get the article summary from OpenAI
57 const summaryResponse = await openai.chat.completions.create({
58 model: "gpt-4o-mini",
59 response_format: { type: "json_object" },
75 return new Response(
76 JSON.stringify({
77 error: `OpenAI processing failed: ${error.message}`,
78 errorStack: error.stack,
79 }),
1Uses OpenAI to generate a thought-provoking statement and emails it to you at whatever interval you set.
2
3Clone/fork this, set the interval you want (eg. every 1 days) and hit run to test it.
168 );
169
170 const { OpenAI } = await import("https://esm.town/v/std/openai");
171 const openai = new OpenAI();
172
173 try {
174 const imageAnalysis = await withTimeout(openai.chat.completions.create({
175 model: "gpt-4o",
176 messages: [
199 : '';
200
201 const story = await withTimeout(openai.chat.completions.create({
202 model: "gpt-4o-mini",
203 messages: [
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(request: Request): Promise<Response> {
4 try {
5 const openai = new OpenAI();
6
7 const completion = await openai.chat.completions.create({
8 messages: [
9 {
2
3import { telegramSendMessage } from "https://esm.town/v/vtdocs/telegramSendMessage?v=5";
4import { OpenAI } from "https://esm.town/v/std/openai";
5import { blob } from "https://esm.town/v/std/blob";
6
7const openai = new OpenAI();
8
9// Task structure
98 `;
99
100 const completion = await openai.chat.completions.create({
101 messages: [{ role: "user", content: prompt }],
102 model: "gpt-4o-mini",
1import { OpenAI } from "https://esm.town/v/std/openai?v=5"
2import { sqlite } from "https://esm.town/v/std/sqlite?v=6"
3import { Chess } from "npm:chess.js"
131 return c.html(`<body>
132 <div class='p-4'>
133 <h2 class='font-bold'>OpenAI Chess</h2>
134 <p class='pb-4'>Play chess against ChatGPT-4</p>
135 <div id="myBoard" style="width: 400px"></div>
171 chess.move(san)
172
173 const openai = new OpenAI()
174
175 let messages = []
182 args: [c.req.param().id, `Requesting response to ${san}`],
183 })
184 const completion = await openai.chat.completions.create({
185 messages: [
186 {
670 }
671
672 const { OpenAI } = await import("https://esm.town/v/std/openai");
673 const regenerateKey = request.headers.get("Regenerate-Key") || "0";
674 const openai = new OpenAI();
675
676 const { sport, skillLevel, ageGroup, groupSize, selectedSkills, sessionDuration } = await request.json();
707 Ensure that the conclusion ties together all the main concepts covered in the training, reinforces the learning objectives, and provides clear takeaways for both participants and coaches. The questions in the conclusion should prompt critical thinking about the skills practiced and their application in the sport.`;
708
709 const completion = await openai.chat.completions.create({
710 messages: [{ role: "user", content: prompt + `\n\nRegenerate key: ${regenerateKey}` }],
711 model: "gpt-4o-mini",
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}.