8import { Hono } from "npm:hono@3";
9import _ from "npm:lodash@4";
10import OpenAI from "npm:openai";
11import { renderToString } from "npm:react-dom/server";
12
309
310 const contextWindow: any = await valleGetValsContextWindow(model);
311 const openai = new OpenAI();
312 const stream = await openai.chat.completions.create({
313 model,
314 stream: true,
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" });
7import { Hono } from "npm:hono@3";
8import _ from "npm:lodash@4";
9import OpenAI from "npm:openai";
10import { renderToString } from "npm:react-dom/server";
11
195
196 const contextWindow: any = await valleGetValsContextWindow(model);
197 const openai = new OpenAI();
198 const stream = await openai.chat.completions.create({
199 model,
200 stream: true,
7import { Hono } from "npm:hono@3";
8import _ from "npm:lodash@4";
9import OpenAI from "npm:openai";
10import { renderToString } from "npm:react-dom/server";
11const vt = new ValTown({ bearerToken: Deno.env.get("valtown") });
172
173 const contextWindow = await valleGetValsContextWindow(model);
174 const openai = new OpenAI();
175 const stream = await openai.chat.completions.create({
176 model,
177 stream: true,
10import { Hono } from "npm:hono@3";
11import _ from "npm:lodash@4";
12import OpenAI from "npm:openai";
13import { renderToString } from "npm:react-dom/server";
14
139
140 const contextWindow = await valleGetValsContextWindow(model);
141 const openai = new OpenAI();
142 const stream = await openai.chat.completions.create({
143 model,
144 stream: true,
7import { Hono } from "npm:hono@3";
8import _ from "npm:lodash@4";
9import OpenAI from "npm:openai";
10import { renderToString } from "npm:react-dom/server";
11
165
166 const contextWindow: any = await valleGetValsContextWindow(model);
167 const openai = new OpenAI();
168 const stream = await openai.chat.completions.create({
169 model,
170 stream: true,
6import { Hono } from "npm:hono@3";
7import _ from "npm:lodash@4";
8import OpenAI from "npm:openai";
9import { renderToString } from "npm:react-dom/server";
10
179
180 const contextWindow = await valleGetValsContextWindow.call(null, model);
181 const openai = new OpenAI();
182 const stream = await openai.chat.completions.create({
183 model,
184 stream: true,
6import { Hono } from "npm:hono";
7import _ from "npm:lodash@4";
8import OpenAI from "npm:openai";
9import { renderToString } from "npm:react-dom/server";
10
156
157 const contextWindow = await valleGetValsContextWindow(model);
158 const openai = new OpenAI();
159 const stream = await openai.chat.completions.create({
160 model,
161 stream: true,
11import { Hono } from "npm:hono";
12import _ from "npm:lodash";
13import OpenAI from "npm:openai";
14import { renderToString } from "npm:react-dom/server";
15
144
145 const contextWindow = await valleGetValsContextWindow(model);
146 const openai = new OpenAI();
147 const stream = await openai.chat.completions.create({
148 model,
149 stream: true,
1Fork it and authenticate with your Val Town API token as the password. Needs an `OPENAI_API_KEY` env var to be set.
2
3WARNING: pollutes your homepage with lots of temporary vals!!