1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import {
4 saveItinerary,
12
13const app = new Hono();
14const openai = new OpenAI();
15
16function generateId(): string {
82 Provide realistic coordinates within the actual site boundaries.`;
83
84 const completion = await openai.chat.completions.create({
85 messages: [{ role: "user", content: prompt }],
86 model: "gpt-4o-mini",
198 },
199 {
200 "title": "An Introduction to OpenAI fine-tuning",
201 "slug": "an-introduction-to-openai-fine-tuning",
202 "link": "/blog/an-introduction-to-openai-fine-tuning",
203 "description": "How to customize OpenAI to your liking",
204 "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205 "author": "Steve Krouse",
417 "slug": "val-town-newsletter-16",
418 "link": "/blog/val-town-newsletter-16",
419 "description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420 "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421 "author": "Steve Krouse",
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1// MEES Assistant API Endpoint
2// Remember to add your environment variables in Val settings:
3// - OPENAI_API_KEY
4// - PINECONE_API_KEY
5// - ASSISTANT_ID
6
7import { OpenAI } from "https://deno.land/x/openai@v4.20.1/mod.ts";
8import { Pinecone } from "https://esm.sh/@pinecone-database/pinecone@1.1.2";
9
10const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") });
11const pinecone = new Pinecone({ apiKey: Deno.env.get("PINECONE_API_KEY") });
12const ASSISTANT_ID = Deno.env.get("ASSISTANT_ID");
34
35 // Get embedding for query
36 const embeddingResponse = await openai.embeddings.create({
37 model: "text-embedding-3-small",
38 input: query,
123 let thread;
124 if (threadId) {
125 thread = await openai.beta.threads.retrieve(threadId);
126 } else {
127 thread = await openai.beta.threads.create();
128 }
129
130 // Add message to thread
131 await openai.beta.threads.messages.create(thread.id, {
132 role: "user",
133 content: message,
135
136 // Run the assistant
137 const run = await openai.beta.threads.runs.create(thread.id, {
138 assistant_id: ASSISTANT_ID,
139 });
214
215 // Poll for completion
216 let runStatus = await openai.beta.threads.runs.retrieve(thread.id, run.id);
217 let allMediaDisplays = [];
218
219 while (runStatus.status !== "completed" && runStatus.status !== "failed") {
220 await new Promise(resolve => setTimeout(resolve, 1000));
221 runStatus = await openai.beta.threads.runs.retrieve(thread.id, run.id);
222
223 if (runStatus.status === "requires_action") {
226 allMediaDisplays = [...allMediaDisplays, ...mediaDisplays];
227
228 await openai.beta.threads.runs.submitToolOutputs(thread.id, run.id, {
229 tool_outputs: toolOutputs,
230 });
237
238 // Get the assistant's response
239 const messages = await openai.beta.threads.messages.list(thread.id);
240 const lastMessage = messages.data[0];
241 const response = lastMessage.content[0].type === "text"
1// This approach fetches GitHub activity for two users specified in the URL,
2// sends it to OpenAI for analysis, and returns collaboration suggestions.
3// It uses the GitHub API (which doesn't require authentication for public data)
4// and the OpenAI API (which does require an API key).
5// Tradeoff: We're using an inline API key for simplicity, which isn't ideal for security.
6// Note: This might hit rate limits for the GitHub API due to fetching a year of data.
7
8import { OpenAI } from "https://esm.town/v/std/openai";
9
10const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
11
12export default async function main(req: Request): Promise<Response> {
51 const user1Summary = summarizeActivity(user1Data);
52
53 const openai = new OpenAI(OPENAI_API_KEY);
54 const completion = await openai.chat.completions.create({
55 model: "gpt-4o-mini",
56 messages: [
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
9Configure the following variables in your environment:
10- `AGENT_API_KEY` (This is a secure token that you choose to secure the agent.tsx POST endpoint)
11- `OPENAI_API_KEY` (An OpenAI API Key)
12- `EXA_API_KEY` (Optional, though needed if you use the web search tool)
13
198 },
199 {
200 "title": "An Introduction to OpenAI fine-tuning",
201 "slug": "an-introduction-to-openai-fine-tuning",
202 "link": "/blog/an-introduction-to-openai-fine-tuning",
203 "description": "How to customize OpenAI to your liking",
204 "pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205 "author": "Steve Krouse",
417 "slug": "val-town-newsletter-16",
418 "link": "/blog/val-town-newsletter-16",
419 "description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420 "pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421 "author": "Steve Krouse",