11
12### Toolings
13* Llms can uses [tools](https://platform.openai.com/docs/guides/function-calling), meaning you can make this an agent and a whole lot more useful.
14
15
1import { zodResponseFormat } from "https://esm.sh/openai/helpers/zod";
2import { z } from "https://esm.sh/zod";
3import { email } from "https://esm.town/v/std/email";
4import { OpenAI } from "https://esm.town/v/std/openai";
5
6export default async function(e: Email) {
7 const client = new OpenAI();
8
9 const Messages = z.object({
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: "Say hello in a creative way" },
173 console.log('Parsed topic:', topic);
174
175 // Dynamically import OpenAI with error handling
176 let OpenAI;
177 try {
178 const module = await import("https://esm.town/v/std/openai");
179 OpenAI = module.OpenAI;
180 } catch (importError) {
181 console.error('OpenAI import error:', importError);
182 return new Response(JSON.stringify({
183 error: `Failed to import OpenAI: ${importError.message}`
184 }), {
185 status: 500,
188 }
189
190 // Create OpenAI instance
191 const openai = new OpenAI();
192
193 // Generate explanation
194 const completion = await openai.chat.completions.create({
195 messages: [
196 {
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4import OpenAI from "https://esm.sh/openai@4.28.4";
5
6function App() {
184export default async function server(request: Request): Promise<Response> {
185 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
186 const { OpenAI } = await import("https://esm.town/v/std/openai");
187 const openai = new OpenAI();
188
189 const { message, characterPrompt } = await request.json();
190
191 const stream = await openai.chat.completions.create({
192 model: "gpt-4o-mini",
193 messages: [
1import OpenAI from "https://esm.sh/openai@4.28.4";
2
3export default async function(req: Request): Promise<Response> {
309 try {
310 const LEPTON_API_TOKEN = Deno.env.get('LEPTON_API_TOKEN') || '';
311 const openai = new OpenAI({
312 apiKey: LEPTON_API_TOKEN,
313 baseURL: 'https://llama3-3-70b.lepton.run/api/v1/',
329 };
330
331 const response = await openai.chat.completions.create(apiConfig);
332
333 return new Response(JSON.stringify(response), {
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3 const openai = new OpenAI();
4 const stream = await openai.chat.completions.create({
5 stream: true,
6 messages: [{ role: "user", content: "Write a poem in the style of beowulf about the DMV" }],
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3function extractCode(str: string): string {
19 }
20
21 const openai = new OpenAI();
22 const prompt =
23 `Generate a TypeScript function named "${functionName}" with the following parameters: ${parameters}. ONLY RETURN VALID JAVASCRIPT DO NOT INCLUDE ANY CONTEXT.`;
24 const completion = await openai.chat.completions.create({
25 messages: [
26 {
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: [
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: [