Search

3,267 results found for openai (1937ms)

Code
3,172

export default async function server(request: Request): Promise<Response> {
// Standard Val Town imports (ensure these versions are suitable)
const { OpenAI } = await import("http://esm.town/v/std/openai"); // Use npm import for better
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite"); // Stick with esm.to
// Use environment variable for API key (Val Town handles
const openai = new OpenAI(); // Automatically uses process.env.OPENAI_API_KEY
// --- Database Setup ---
console.log(`Generating study material for: ${topic}`);
const studyMaterialResponse = await openai.chat.completions.create({
model: "gpt-4o-mini", // Or choose another appropriate model
messages: [
const studyMaterial = studyMaterialResponse.choices[0]?.message?.content;
if (!studyMaterial) {
throw new Error("OpenAI did not return study material content.");
}
console.log(`Generating quiz for: ${topic}`);
const quizResponse = await openai.chat.completions.create({
model: "gpt-4o-mini", // Or choose another appropriate model
response_format: { type: "json_object" }, // Request JSON output
const jsonString = quizResponse.choices[0]?.message?.content;
if (!jsonString) {
throw new Error("OpenAI did not return quiz content.");
}
// Parse the JSON response from OpenAI
let parsedQuiz;
try {
parsedQuiz = JSON.parse(jsonString);
} catch (parseError) {
console.error("Failed to parse JSON from OpenAI:", jsonString);
throw new Error("Failed to parse quiz data from AI response.");
}
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" },
export default async function server(request: Request): Promise<Response> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
const openai = new OpenAI();
const KEY = "homerepair";
const { agentId, command, inputs } = await request.json();
// Simulate command execution with OpenAI
const messages = [
{
try {
const completion = await openai.chat.completions.create({
messages: messages,
model: "gpt-4o-mini",
headers: { "Content-Type": "application/json" },
});
} catch (openAIError) {
console.error("OpenAI API Error:", {
message: openAIError.message,
name: openAIError.name,
stack: openAIError.stack,
response: openAIError.response
? await openAIError.response.text()
: "No response body",
});
return new Response(
JSON.stringify({
error: "OpenAI API Error",
details: openAIError.message,
stackTrace: openAIError.stack,
}),
{
import { email } from "https://esm.town/v/std/email";
import { OpenAI } from "https://esm.town/v/std/openai";
import { Project, EmailSubscriber } from "../shared/types.ts";
import { logger } from "./utils.ts";
const openai = new OpenAI();
/**
try {
// Generate welcome email content using OpenAI
const prompt = `
You are writing a personalized welcome email to someone who just subscribed to "${project.
`;
const completion = await openai.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant that writes excellent, personali
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(
additionalContext = "Focus on actionable, practical keyword strategies",
) {
const openai = new OpenAI();
try {
Format the response as a structured JSON object.`;
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
response_format: { type: "json_object" },
console.log("🔊 Sending request to Groq Speech API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/audio/speech", {
method: "POST",
headers: {
console.log("🔵 Sending request to Groq API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
console.log("🎤 Sending request to Groq Whisper API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
method: "POST",
headers: {
console.log("🎤 Sending request to Groq Whisper API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/audio/transcriptions", {
method: "POST",
headers: {
console.log("🔵 Sending request to Groq API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST",
headers: {
console.log("🔊 Sending request to Groq Speech API");
const start = Date.now();
const response = await fetch("https://api.groq.com/openai/v1/audio/speech", {
method: "POST",
headers: {
export default async function (e: Email) {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const skinkDescription = await openai.chat.completions.create({
messages: [
{