529
530export default async function server(request: Request): Promise<Response> {
531 const { OpenAI } = await import("https://esm.town/v/std/openai");
532 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
533 const openai = new OpenAI();
534 const KEY = "homerepair";
535
560 const { agentId, command, inputs } = await request.json();
561
562 // Simulate command execution with OpenAI
563 const messages = [
564 {
572
573 try {
574 const completion = await openai.chat.completions.create({
575 messages: messages,
576 model: "gpt-4o-mini",
588 headers: { "Content-Type": "application/json" },
589 });
590 } catch (openAIError) {
591 console.error("OpenAI API Error:", {
592 message: openAIError.message,
593 name: openAIError.name,
594 stack: openAIError.stack,
595 response: openAIError.response
596 ? await openAIError.response.text()
597 : "No response body",
598 });
600 return new Response(
601 JSON.stringify({
602 error: "OpenAI API Error",
603 details: openAIError.message,
604 stackTrace: openAIError.stack,
605 }),
606 {
4
5import { email } from "https://esm.town/v/std/email";
6import { OpenAI } from "https://esm.town/v/std/openai";
7import { Project, EmailSubscriber } from "../shared/types.ts";
8import { logger } from "./utils.ts";
9
10const openai = new OpenAI();
11
12/**
44
45 try {
46 // Generate welcome email content using OpenAI
47 const prompt = `
48 You are writing a personalized welcome email to someone who just subscribed to "${project.name}".
59 `;
60
61 const completion = await openai.chat.completions.create({
62 messages: [
63 { role: "system", content: "You are a helpful assistant that writes excellent, personalized emails." },
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(
13 additionalContext = "Focus on actionable, practical keyword strategies",
14) {
15 const openai = new OpenAI();
16
17 try {
39 Format the response as a structured JSON object.`;
40
41 const response = await openai.chat.completions.create({
42 model: "gpt-4o-mini",
43 response_format: { type: "json_object" },
26 console.log("🔊 Sending request to Groq Speech API");
27 const start = Date.now();
28 const response = await fetch("https://api.groq.com/openai/v1/audio/speech", {
29 method: "POST",
30 headers: {
20 console.log("🔵 Sending request to Groq API");
21 const start = Date.now();
22 const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
23 method: "POST",
24 headers: {
63 console.log("🎤 Sending request to Groq Whisper API");
64 const start = Date.now();
65 const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
66 method: "POST",
67 headers: {
68 console.log("🎤 Sending request to Groq Whisper API");
69 const start = Date.now();
70 const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
71 method: "POST",
72 headers: {
158 console.log("🔵 Sending request to Groq API");
159 const start = Date.now();
160 const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
161 method: "POST",
162 headers: {
214 console.log("🔊 Sending request to Groq Speech API");
215 const start = Date.now();
216 const response = await fetch("https://api.groq.com/openai/v1/audio/speech", {
217 method: "POST",
218 headers: {
1export default async function (e: Email) {
2 const { OpenAI } = await import("https://esm.town/v/std/openai");
3 const openai = new OpenAI();
4
5 const skinkDescription = await openai.chat.completions.create({
6 messages: [
7 {
137Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
138
139### OpenAI
140```ts
141import { OpenAI } from "https://esm.town/v/std/openai";
142const openai = new OpenAI();
143const completion = await openai.chat.completions.create({
144 messages: [
145 { role: "user", content: "Say hello in a creative way" },
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 {