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({
144export default async function server(request: Request): Promise<Response> {
145 const { blob } = await import("https://esm.town/v/std/blob");
146 const { OpenAI } = await import("https://esm.town/v/std/openai");
147 const openai = new OpenAI();
148
149 if (request.method === 'POST') {
170 const { prompt } = await request.json();
171
172 const response = await openai.images.generate({
173 model: "dall-e-3",
174 prompt: prompt,
1
2import { OpenAI } from "https://esm.town/v/yawnxyz/OpenAI";
3import { fetch } from "https://esm.town/v/std/fetch";
4
44export class AudioManager {
45 constructor(apiKey=null, uploadFunction = null, downloadFunction = null) {
46 this.openai = new OpenAI(apiKey);
47 this.uploadFunction = uploadFunction || this.blobUpload;
48 }
68 };
69 const mergedOptions = { ...defaultOptions, ...options };
70 const transcription = await this.openai.audio.transcriptions.create(mergedOptions);
71 return transcription;
72 }
80 const mergedOptions = { ...defaultOptions, ...options };
81
82 const translation = await this.openai.audio.translations.create(mergedOptions);
83 return translation;
84 }
85
86 // returns an openai speech object
87 async textToSpeech(text, options = {}) {
88 const defaultOptions = {
92 };
93 const mergedOptions = { ...defaultOptions, ...options };
94 const speech = await this.openai.audio.speech.create(mergedOptions);
95 const arrayBuffer = await speech.arrayBuffer();
96 const blob = new Blob([arrayBuffer], { type: "audio/mpeg" });
106 };
107 const mergedOptions = { ...defaultOptions, ...options };
108 const speech = await this.openai.audio.speech.create(mergedOptions);
109 const arrayBuffer = await speech.arrayBuffer();
110 const blob = new Blob([arrayBuffer], { type: "audio/mpeg" });
2import { email } from "https://esm.town/v/std/email";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4import { OpenAI } from "npm:openai";
5
6function stripHtmlBackticks(html: string): string {
9
10export default async function(e: Email) {
11 const openai = new OpenAI();
12 console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`);
13
25 }
26
27 const summary = await openai.chat.completions.create({
28 messages: [
29 {
390export default async function server(request: Request): Promise<Response> {
391 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
392 const { OpenAI } = await import("https://esm.town/v/std/openai");
393 const KEY = "highApricotImpala";
394 const SCHEMA_VERSION = 2;
501 );
502
503 const openai = new OpenAI();
504
505 const completion = await openai.chat.completions.create({
506 messages: [
507 {
1import { parseBearerString } from "https://esm.town/v/andreterron/parseBearerString";
2import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
3import { OpenAIUsage } from "https://esm.town/v/std/OpenAIUsage";
4import { RateLimit } from "npm:@rlimit/http";
5const client = new OpenAIUsage();
6
7const allowedPathnames = [
42
43 // Proxy the request
44 const url = new URL("." + pathname, "https://api.openai.com");
45 url.search = search;
46
47 const headers = new Headers(req.headers);
48 headers.set("Host", url.hostname);
49 headers.set("Authorization", `Bearer ${Deno.env.get("OPENAI_API_KEY")}`);
50 headers.set("OpenAI-Organization", Deno.env.get("OPENAI_API_ORG"));
51
52 const modifiedBody = await limitFreeModel(req, user);
63 });
64
65 const openAIRes = await fetch(url, {
66 method: req.method,
67 headers,
71
72 // Remove internal header
73 const res = new Response(openAIRes.body, openAIRes);
74 res.headers.delete("openai-organization");
75 return res;
76}
1import { email } from "https://esm.town/v/std/email";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4
8
9export default async function(e: Email) {
10 const openai = new OpenAI();
11
12 const summary = await openai.chat.completions.create({
13 messages: [
14 {
1import { email } from "https://esm.town/v/std/email";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4
9export default async function(e: Email) {
10 console.log(e.from, e.subject);
11 const openai = new OpenAI();
12
13 const summary = await openai.chat.completions.create({
14 messages: [
15 {
1import { email } from "https://esm.town/v/std/email";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4
9export default async function(e: Email) {
10 console.log(e.from, e.subject);
11 const openai = new OpenAI();
12
13 const summary = await openai.chat.completions.create({
14 messages: [
15 {