Back
Version 13
6/18/2024
import { decode as base64Decode, encode as base64Encode } from "https://deno.land/std@0.166.0/encoding/base64.ts";
import { createClient } from "https://esm.sh/@libsql/client@0.6.0/web";
import { sqlToJSON } from "https://esm.town/v/nbbaier/sqliteExportHelpers?v=22";
import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
import { blob } from "https://esm.town/v/std/blob";
import * as druid from "npm:@saehrimnir/druidjs";
import cosSimilarity from "npm:cos-similarity";
import _ from "npm:lodash";
import OpenAI from "npm:openai";
const points = [
"animal that barks",
"dog",
"cat",
"animal",
"woof woof woof",
"man bites dog",
"dog bites man",
"discord bot",
"github api",
"chat server integration",
];
const openai = new OpenAI();
const cache = {};
async function getEmbedding(str) {
cache[str] = cache[str] || (await openai.embeddings.create({
model: "text-embedding-3-large",
input: str,
})).data[0].embedding;
return cache[str];
}
let embeddings = await blob.getJSON("blogPostEmbeddings");
if (!embeddings)
embeddings = await Promise.all(points.map((point) => getEmbedding(point)));
await blob.setJSON("blogPostEmbeddings", embeddings);
Updated: June 18, 2024