389
390export default async function server(request: Request): Promise<Response> {
391 const { OpenAI } = await import("https://esm.town/v/std/openai");
392 const openai = new OpenAI();
393 const url = new URL(request.url);
394
399 switch(url.pathname) {
400 case '/api/generate-buyer-persona':
401 const buyerPersonaResult = await openai.chat.completions.create({
402 messages: [{
403 role: "user",
444
445 case '/api/identify-problems':
446 const problemsResult = await openai.chat.completions.create({
447 messages: [{
448 role: "user",
473
474 case '/api/generate-solutions':
475 const solutionsResult = await openai.chat.completions.create({
476 messages: [{
477 role: "user",
504
505 case '/api/create-offer':
506 const offerResult = await openai.chat.completions.create({
507 messages: [{
508 role: "user",
2import process from "node:process";
3import { marked } from "npm:marked";
4import { OpenAI } from "npm:openai";
5
6function pm(...lines: string[]): string {
16 );
17
18 const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai" });
19 const response = await client.chat.completions.create({
20 model: "sonar",
1import { openai } from 'npm:@ai-sdk/openai';
2import { generateText, tool } from 'npm:ai';
3import * as mathjs from 'npm:mathjs';
5
6const response = await generateText({
7 model: openai('gpt-4o-2024-08-06', { structuredOutputs: true }),
8 tools: {
9 calculate: tool({
1import { openai } from "npm:@ai-sdk/openai";
2import { generateText } from "npm:ai";
3
23
24 const { text: reading } = await generateText({
25 model: openai("gpt-4o-mini"),
26 system: "You are a creative writer specializing in Lord of the Rings themed horoscopes.",
27 prompt:
1```typescript
2import { openai } from "npm:@ai-sdk/openai";
3import { generateText } from "npm:ai";
4
32
33 const { text: reading } = await generateText({
34 model: openai("gpt-4o-mini"),
35 system: "You are a Star Trek zodiac reader.",
36 prompt: `Create a thematic reading for a person born under the ${race} race with traits of ${traits.join(', ')}.`
1```typescript
2import { openai } from "npm:@ai-sdk/openai";
3import { generateText } from "npm:ai";
4
44
45 const { text: fortune } = await generateText({
46 model: openai("gpt-4o-mini"),
47 system: "You are a Star Trek themed fortune teller.",
48 prompt: `Create a fortune for someone with the traits: ${raceAssignment.traits}.`
178 <h4>API</h4>
179 <p>An API (Application Programming Interface) is a set of rules and protocols designed to make it easy
180 to communicate. For example OpenAI has an API designed to make it easy for ChatGPT to communicate with
181 many different kinds of softwares. It's very common for front ends to call APIs. You don't literally
182 call an API, you call it's endpoints. There are disadvantages to calling an API like the fact you're
1import { openai } from "npm:@ai-sdk/openai";
2import { generateText } from "npm:ai";
3
14
15 const { text } = await generateText({
16 model: openai("gpt-4o-mini"),
17 system: "You are a creative name generator that creates humorous or fitting names for people based on a given reason for why they are considered bad.",
18 prompt: `Generate a name for a person who is considered bad because: ${reason}. Make it creative and humorous.`,
1import { openai } from "npm:@ai-sdk/openai";
2import { generateText } from "npm:ai";
3
14
15 const { text } = await generateText({
16 model: openai("gpt-4o-mini"),
17 system: "You are a creative AI that generates unique car names based on a given color.",
18 prompt: `Create a unique and catchy car name for a car that is ${color}.`,
19
20 const { text } = await generateText({
21 model: openai("gpt-4o-mini"),
22 system: "You are a creative AI that generates bird names based on car models.",
23 prompt: `Generate a random bird name inspired by the following car models: ${carModels.join(", ")}.`