434export default async function server(request: Request): Promise<Response> {
435 if (request.method === 'POST' && request.url.includes('/recommendations')) {
436 const { OpenAI } = await import("https://esm.town/v/std/openai");
437 const openai = new OpenAI();
438
439 const { latitude, longitude } = await request.json();
459 `;
460
461 const completion = await openai.chat.completions.create({
462 messages: [{ role: "user", content: prompt }],
463 model: "gpt-4o-mini",
35Use Cerebras for AI on the backend like so:
36
37const { OpenAI } = await import("https://esm.sh/openai");
38const client = new OpenAI({
39 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
40 baseURL: "https://api.cerebras.ai/v1"
83 const { messages } = await request.json();
84
85 const { OpenAI } = await import("https://esm.sh/openai");
86 // Cerebras Inference
87 // Very important: do not change this
88 // Keep these comments so we remember not to change this
89 const client = new OpenAI({
90 apiKey: Deno.env.get("CEREBRAS_API_KEY"),
91 baseURL: "https://api.cerebras.ai/v1",
18brian@airbnb.com,Brian Chesky
19drew@dropbox.com,Drew Houston
20sam@openai.com,Sam Altman
21tim@apple.com,Tim Cook
22jeff@amazon.com,Jeff Bezos
1 import { InvocationTracker } from 'https://esm.town/v/rozek/InvocationTracker'
2 import { floatingQuotaTracker } from 'https://esm.town/v/rozek/floatingQuotaTracker'
3 import { OpenAI } from 'https://esm.town/v/std/openai'
4
5// don't forget to define Env.Var "OpenAIChatCompletion" for authorization!
6
7 interface Indexable { [Key:string]:any }
8
9/**** rate-limited access to the OpenAI API ****/
10
11 export default async function (Request:Request):Promise<Response> {
28 /**** handle authorization - but only if Env.Var. is set ****/
29
30 const AccessToken = process.env.OpenAIChatCompletion
31 if (AccessToken != null) {
32 const AuthHeader = Request.headers.get('Authorization')
43 /**** count this invocation ****/
44
45 const TrackingTable = 'OpenAIChatCompletion_Usage'
46 const Granularity_ = 15*60*1000 // how precisely should be logged?
47
51 /**** limit the rate at whic hthis resource is accessed ****/
52
53 const ResourceTable = 'OpenAIChatCompletion'
54 const ResourceLimit = 10 // max. number of allowed requests per period
55 const ResourcePeriod = 60*1000 // the period, given in ms
84 try {
85 if (stream == true) {
86 const CompletionStream = await new OpenAI().chat.completions.create({
87 ...ParameterSet, stream:true
88 })
109 })
110 } else {
111 const Completion = await new OpenAI().chat.completions.create({
112 ...ParameterSet, stream:false
113 })
118 }
119
120 return await OpenAIChatCompletion(Request)
121 }
122
5 options = {},
6) => {
7 // Initialize OpenAI API stub
8 const { Configuration, OpenAIApi } = await import(
9 "https://esm.sh/openai@3.3.0"
10 );
11 const configuration = new Configuration({
12 apiKey: process.env.OPENAI,
13 });
14 const openai = new OpenAIApi(configuration);
15 // Request chat completion
16 const messages = typeof prompt === "string"
17 ? [{ role: "user", content: prompt }]
18 : prompt;
19 const { data } = await openai.createChatCompletion({
20 model: "gpt-3.5-turbo-0613",
21 messages,
1import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
2import { OpenAI } from "https://esm.town/v/std/openai";
3
4const KEY = "memorySampleSummary";
6const SCHEMA_VERSION = 1;
7
8const openai = new OpenAI();
9
10// Initialize the database
22// Generate embedding for a given text
23async function generateEmbedding(text: string): Promise<number[]> {
24 const response = await openai.embeddings.create({
25 model: "text-embedding-ada-002",
26 input: text,
2import { fileToDataURL } from "https://esm.town/v/stevekrouse/fileToDataURL";
3import { modifyImage } from "https://esm.town/v/stevekrouse/modifyImage";
4import { chat } from "https://esm.town/v/stevekrouse/openai";
5import { Hono } from "npm:hono@3";
6
409export default async function server(request: Request): Promise<Response> {
410 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
411 const { OpenAI } = await import("https://esm.town/v/std/openai");
412 const KEY = "aiMessenger";
413 const openai = new OpenAI();
414
415 const SCHEMA_VERSION = 5;
655 if (mode === "ai") {
656 // Generate AI response
657 const aiCompletion = await openai.chat.completions.create({
658 messages: [{
659 role: "user",
393export default async function server(request: Request): Promise<Response> {
394 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
395 const { OpenAI } = await import("https://esm.town/v/std/openai");
396 const KEY = "selfassuredCoralPig";
397 const openai = new OpenAI();
398
399 const SCHEMA_VERSION = 5;
616 if (mode === 'ai') {
617 // Generate AI response
618 const aiCompletion = await openai.chat.completions.create({
619 messages: [{
620 role: "user",