7import cosSimilarity from "npm:cos-similarity";
8import _ from "npm:lodash";
9import OpenAI from "npm:openai";
1011export default async function blogPostEmbeddingsDimensionalityReduction() {
23];
2425const openai = new OpenAI();
26async function getEmbedding(str) {
27return (await openai.embeddings.create({
28model: "text-embedding-3-large",
29input: str,
compareEmbeddingsmain.tsx3 matches
6import cosSimilarity from "npm:cos-similarity";
7import _ from "npm:lodash";
8import OpenAI from "npm:openai";
910const comparisons = [
20];
2122const openai = new OpenAI();
23const cache = {};
24async function getEmbedding(str) {
25cache[str] = cache[str] || (await openai.embeddings.create({
26model: "text-embedding-3-large",
27input: str,
indexValsBlobsmain.tsx4 matches
4import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
5import { blob } from "https://esm.town/v/std/blob";
6import OpenAI from "npm:openai";
7import { truncateMessage } from "npm:openai-tokens";
89const dimensions = 1536;
39);
4041const openai = new OpenAI();
42for (const newValsBatch of newValsBatches) {
43const batchDataIndex = nextDataIndex;
47const code = getValCode(val);
4849const embedding = await openai.embeddings.create({
50model: "text-embedding-3-small",
51input: truncateMessage(code, "text-embedding-3-small"),
semanticSearchNeonmain.tsx3 matches
3import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
4import { blob } from "https://esm.town/v/std/blob";
5import OpenAI from "npm:openai";
67const dimensions = 1536;
11await client.connect();
1213const openai = new OpenAI();
14const queryEmbedding = (await openai.embeddings.create({
15model: "text-embedding-3-small",
16input: query,
indexValsNeonmain.tsx4 matches
5import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
6import { blob } from "https://esm.town/v/std/blob";
7import OpenAI from "npm:openai";
8import { truncateMessage } from "npm:openai-tokens";
910// CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
41}
4243const openai = new OpenAI();
44for (const newValsBatch of newValsBatches) {
45await Promise.all([...Array(newValsBatch.length).keys()].map(async (valIndex) => {
47const code = getValCode(val);
4849const embedding = await openai.embeddings.create({
50model: "text-embedding-3-small",
51input: truncateMessage(code, "text-embedding-3-small"),
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
convertResumemain.tsx1 match
122event.preventDefault();
123const resumeContent = document.getElementById('resumeContent').value;
124const apiKey = '${Deno.env.get("OPENAI_API_KEY")}';
125const spinner = document.getElementById('spinner');
126const jsonOutput = document.getElementById('jsonOutput');
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
34let location = "brooklyn ny";
8).then(r => r.json());
910const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12messages: [{
13role: "user",
purpleKangarooREADME.md1 match
1# ChatGPT Implemented in Val Town
23Demonstrated how to use assistants and threads with the OpenAI SDK and how to stream the response with Server-Sent Events.
45<p align=center>
purpleKangaroomain.tsx8 matches
1/** @jsxImportSource https://esm.sh/react */
2import OpenAI from "npm:openai";
3import { renderToString } from "npm:react-dom/server";
45// This uses by personal API key, you'll need to provide your own if
6// you fork this. We'll be adding support to the std/openai lib soon!
7const openai = new OpenAI();
8import { Hono } from "npm:hono@3";
938});
3940// Setup the SSE connection and stream back the response. OpenAI handles determining
41// which message is the correct response based on what was last read from the
42// thread. This is likely vulnerable to race conditions.
58const app = new Hono();
59app.get("/", async (c) => {
60const thread = await openai.beta.threads.create();
61const assistant = await openai.beta.assistants.create({
62name: "",
63instructions:
114app.post("/post-message", async (c) => {
115let message = await c.req.text();
116await openai.beta.threads.messages.create(
117c.req.query("threadId"),
118{ role: "user", content: message },
132));
133};
134const run = openai.beta.threads.runs.stream(threadId, {
135assistant_id: assistantId,
136// Make sure we only display messages we haven't seen yet.