514 const url = new URL(request.url);
515 const { blob } = await import("https://esm.town/v/std/blob");
516 const { OpenAI } = await import("https://esm.town/v/std/openai");
517
518 const openai = new OpenAI();
519
520 // Simple rate limiting
553
554 try {
555 const completion = await openai.chat.completions.create({
556 messages: [
557 {
1import { fetch } from "https://esm.town/v/std/fetch";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import process from "node:process";
4
5const openai = new OpenAI();
6
7// Depending on the day do one of these:
43 console.log(prompt);
44
45 const completion = await openai.chat.completions.create({
46 messages: [
47 { role: "user", content: prompt },
498 const url = new URL(request.url);
499 const { blob } = await import("https://esm.town/v/std/blob");
500 const { OpenAI } = await import("https://esm.town/v/std/openai");
501
502 const openai = new OpenAI();
503
504 // Simple rate limiting
537
538 try {
539 const completion = await openai.chat.completions.create({
540 messages: [
541 {
498 const url = new URL(request.url);
499 const { blob } = await import("https://esm.town/v/std/blob");
500 const { OpenAI } = await import("https://esm.town/v/std/openai");
501
502 const openai = new OpenAI();
503
504 // Simple rate limiting
537
538 try {
539 const completion = await openai.chat.completions.create({
540 messages: [
541 {
1import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
2
3/**
4 * API Client for interfacing with the OpenAI API. Uses Val Town credentials.
5 */
6export class OpenAI {
7 private rawOpenAIClient: RawOpenAI;
8
9 /**
10 * API Client for interfacing with the OpenAI API. Uses Val Town credentials.
11 *
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
19 */
20 constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
21 this.rawOpenAIClient = new RawOpenAI({
22 ...options,
23 baseURL: "https://std-openaiproxy.web.val.run/v1",
24 apiKey: Deno.env.get("valtown"),
25 organization: null,
28
29 get chat() {
30 return this.rawOpenAIClient.chat;
31 }
32
33 get beta() {
34 return {
35 chat: this.rawOpenAIClient.beta.chat,
36 };
37 }
110
111export default async function server(request: Request): Promise<Response> {
112 const { OpenAI } = await import("https://esm.town/v/std/openai");
113 const openai = new OpenAI();
114
115 const url = new URL(request.url);
119
120 try {
121 const completion = await openai.chat.completions.create({
122 model: "gpt-4o",
123 messages: [
17 COUNT(*) AS count
18 FROM
19 openai_usage,
20 params
21 WHERE
38};
39
40export class OpenAIUsage {
41 constructor() {}
42 async migrate() {
43 await sqlite.batch([`CREATE TABLE IF NOT EXISTS openai_usage (
44 id INTEGER PRIMARY KEY,
45 user_id TEXT NOT NULL,
52 }
53 async drop() {
54 await sqlite.batch([`DROP TABLE IF EXISTS openai_usage`]);
55 }
56 async writeUsage(ur: UsageRow) {
57 sqlite.execute({
58 sql: "INSERT INTO openai_usage (user_id, handle, tier, tokens, model) VALUES (?, ?, ?, ?, ?)",
59 args: [ur.userId, ur.handle, ur.tier, ur.tokens, ur.model],
60 });
78 let resp = await sqlite.execute({
79 sql: `SELECT count(*)
80FROM openai_usage
81WHERE (
82 (model LIKE 'gpt-4%' AND model NOT LIKE '%mini%')
670 }
671
672 const { OpenAI } = await import("https://esm.town/v/std/openai");
673 const regenerateKey = request.headers.get("Regenerate-Key") || "0";
674 const openai = new OpenAI();
675
676 const { sport, skillLevel, ageGroup, groupSize, selectedTopics, sessionDuration } = await request.json();
707 Ensure that the conclusion ties together all the main concepts covered in the training, reinforces the learning objectives, and provides clear takeaways for both participants and coaches. The questions in the conclusion should prompt critical thinking about the skills practiced and their application in the sport.`;
708
709 const completion = await openai.chat.completions.create({
710 messages: [{ role: "user", content: prompt + `\n\nRegenerate key: ${regenerateKey}` }],
711 model: "gpt-4o-mini",
14 }
15
16 const { OpenAI } = await import("https://esm.town/v/std/openai");
17 const regenerateKey = request.headers.get("Regenerate-Key") || "0";
18 const openai = new OpenAI();
19
20 const { sport, skillLevel, ageGroup, groupSize, selectedTopics, sessionDuration } = await request.json();
30 "settings": {
31 "model": "gpt-4o-mini",
32 "provider": "openai",
33 "system": "please summarize the following article in a 2-4 sentences, describing it from a 3rd person point of view",
34 "prompt": "{jina.content}"