5 options = {},
6) => {
7 // Initialize OpenAI API stub
8 const { Configuration, OpenAIApi } = await import(
9 "https://esm.sh/openai@3.3.0"
10 );
11 console.log(process.env);
12 // const configuration = new Configuration({
13 // apiKey: process.env.OPENAI,
14 // });
15 // const openai = new OpenAIApi(configuration);
16 // // Request chat completion
17 // const messages = typeof prompt === "string"
18 // ? [{ role: "user", content: prompt }]
19 // : prompt;
20 // const { data } = await openai.createChatCompletion({
21 // model: "gpt-3.5-turbo-0613",
22 // messages,
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
11 });
12 }
13 const openai = new OpenAI();
14
15 try {
30 };
31 }
32 const stream = await openai.chat.completions.create(body);
33 if (!body.stream) {
34 return new Response(JSON.stringify(body), {
1import { api } from "https://esm.town/v/pomdtr/api";
2import { email } from "https://esm.town/v/std/email?v=12";
3import { OpenAI } from "https://esm.town/v/std/OpenAI";
4
5async function getValByAlias({ author, name }: { author: string; name: string }) {
88
89export function askAI(content: string) {
90 const client = new OpenAI();
91 const runner = client.beta.chat.completions.runTools({
92 model: "gpt-3.5-turbo",
1import { OpenAI } from "https://esm.town/v/std/openai?v=4";
2
3const openai = new OpenAI();
4
5async function runConversation() {
13 `.replaceAll(/\s+/g, "");
14
15 const response = await openai.chat.completions.create({
16 messages: [
17 { role: "user", content: prompt },
1Migrated from folder: openai_function_calling/grayWildfowl
1import { Hono } from "npm:hono";
2import { OpenAI } from "npm:openai";
3
4const defaultUser = {
95
96const personalizationGPT = async (user: UserObject) => {
97 const openai = new OpenAI();
98 let chatCompletion = await openai.chat.completions.create({
99 messages: [
100 {
5Use GPT to return JIT personalization for client side applications.
6
7If you fork this, you'll need to set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
8
9Migrated from folder: PersonalizationGPT/PersonalizationGPT
3import { jsx } from "npm:hono@3/jsx";
4import { cors } from 'npm:hono/cors';
5import { OpenAI } from "npm:openai";
6
7const app = new Hono();
8const openai = new OpenAI();
9
10app.use('*', cors({
19 <html>
20 <head>
21 <title>OpenAI Prompt Example</title>
22 <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
23 <script src="https://cdn.tailwindcss.com"></script>
25 <body>
26 <div class="container mx-auto py-8">
27 <h1 class="text-4xl font-bold mb-4">OpenAI Prompt Example</h1>
28 <form action="/prompt" method="GET">
29 <label for="prompt" class="block mb-2 font-bold">Prompt:</label>
50
51 try {
52 const response = await openai.chat.completions.create({
53 model: "gpt-4",
54 messages: [{ role: "user", content: prompt }],
59 return c.redirect(`/?response=${encodeURIComponent(generatedResponse)}`);
60 } catch (error) {
61 console.error('OpenAI API error:', error);
62 return c.redirect('/?response=Error%20occurred.');
63 }
1Migrated from folder: Libraries/ai/OpenAI/openAiExample
1# OpenAI ChatGPT helper function
2
3This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
4
5```ts
6import { chat } from "https://esm.town/v/stevekrouse/openai";
7
8const { content } = await chat("Hello, GPT!");
11
12```ts
13import { chat } from "https://esm.town/v/stevekrouse/openai";
14
15const { content } = await chat(