287 } else if (url.pathname === "/api/analyze") {
288 if (req.method === "POST") {
289 const { OpenAI } = await import("https://esm.town/v/std/openai");
290 const openai = new OpenAI();
291
292 try {
297 Full Content: ${fullContent}`;
298
299 const completion = await openai.chat.completions.create({
300 messages: [{ role: "user", content: prompt }],
301 model: "gpt-4o-mini",
1import { encode } from "https://deno.land/std@0.203.0/encoding/base64.ts";
2import OpenAI from "https://esm.sh/openai@4.24.1";
3import { email } from "https://esm.town/v/std/email";
4import { pdfText } from "jsr:@pdf/pdftext";
134async function sendRequestToFireworks(prompt, apiKey, model) {
135 try {
136 const client = new OpenAI({
137 baseURL: "https://api.fireworks.ai/inference/v1",
138 apiKey: apiKey,
2
3 export default async function (Request:Request):Promise<Response> {
4 const OpenAIRequest = {
5 messages: [
6 { role:'system', content:'please answer the following question' },
14 method: 'POST',
15 headers:{ 'Content-Type':'application/json' },
16 body: JSON.stringify(OpenAIRequest)
17 });
18
243export default async function server(request: Request): Promise<Response> {
244 if (request.method === "POST") {
245 const { OpenAI } = await import("https://esm.town/v/std/openai");
246 const openai = new OpenAI();
247
248 const body = await request.json();
249 const messages = body.messages || [];
250
251 const completion = await openai.chat.completions.create({
252 messages: messages,
253 model: "gpt-4o-mini",
114 }
115
116 return await OpenAIChatCompletion(Request)
117 }
118
2 import { floatingQuotaTracker } from 'https://esm.town/v/rozek/floatingQuotaTracker'
3
4/**** how long until "OpenAIChatCompletion" becomes available again? ****/
5
6 export default async function (Request:Request):Promise<Response> {
2import { Hono } from "npm:hono@3";
3import { html } from "npm:hono@3/html";
4import { OpenAI } from "npm:openai";
5
6const app = new Hono();
7const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY_VOICE") });
8
9class TranscriptionService {
10 async transcribeAudio(audioFile) {
11 try {
12 const transcription = await openai.audio.transcriptions.create({
13 file: audioFile,
14 model: "whisper-1",
18 return transcription;
19 } catch (error) {
20 console.error("OpenAI API error:", error);
21 throw error;
22 }
403
404 try {
405 const response = await openai.chat.completions.create({
406 model: "gpt-4o-mini",
407 messages: [
421 return c.text(translation);
422 } catch (error) {
423 console.error("OpenAI API error:", error);
424 return c.text("Error occurred during translation", 500);
425 }
436
437 try {
438 const mp3 = await openai.audio.speech.create({
439 model: "tts-1",
440 voice: voice,
448 });
449 } catch (error) {
450 console.error("OpenAI API error:", error);
451 return c.text("Error occurred during speech generation", 500);
452 }
3The app is set up so you can easily have a conversation between two people. The app will translate between the two selected languages, in each voice, as the speakers talk.
4
5Add your OpenAI API Key, and make sure to open in a separate window for Mic to work.
1import { val } from 'https://esm.town/v/std/val';
2import { OpenAI } from 'https://esm.town/v/std/openai';
3
4// Initialize OpenAI
5const openai = new OpenAI();
6
7// Type definitions for Airtable attachments
166 `;
167
168 const completion = await openai.chat.completions.create({
169 messages: [
170 {
282 } else if (url.pathname === "/api/analyze") {
283 if (req.method === 'POST') {
284 const { OpenAI } = await import("https://esm.town/v/std/openai");
285 const openai = new OpenAI();
286
287 try {
292 Full Content: ${fullContent}`;
293
294 const completion = await openai.chat.completions.create({
295 messages: [{ role: "user", content: prompt }],
296 model: "gpt-4o-mini",