Skip to content

Commit

Permalink
feat: fixed some config stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zzulanas committed Jun 20, 2023
1 parent c81c951 commit 516c472
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
31 changes: 0 additions & 31 deletions lib/generate-embeddings.mjs

This file was deleted.

34 changes: 34 additions & 0 deletions lib/generate-embeddings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Configuration, OpenAIApi } from "openai";
import { supabaseClient } from "./supabase-client";

const configuration = new Configuration({ apiKey: process.env.OPENAI_KEY });
const openAi = new OpenAIApi(configuration);

const documents = [
"Zach loves long walks on the beach",
"Zach loves ice cream, especially vanilla ice cream",
"In Zach's free time he likes to rock climb, the highest grade he can do is around a V5, he's still learning!",
];

async function generateEmbeddings(documents: string[]) {
// Assuming each document is a string
for (const document of documents) {
// OpenAI recommends replacing newlines with spaces for best results
const input = document.replace(/\n/g, " ");

const embeddingResponse = await openAi.createEmbedding({
model: "text-embedding-ada-002",
input,
});

const [{ embedding }] = embeddingResponse.data.data;

// In production we should handle possible errors
await supabaseClient.from("documents").insert({
content: document,
embedding,
});
}
}

generateEmbeddings(documents);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"build": "pnpm run embeddings && next build",
"build": "next build",
"start": "next start",
"lint": "next lint",
"embeddings": "tsx lib/generate-embeddings.ts"
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"lib/generate-embeddings.mjs"
"lib/generate-embeddings.ts"
],
"exclude": ["node_modules"]
"exclude": ["node_modules", "supabase"]
}

1 comment on commit 516c472

@vercel
Copy link

@vercel vercel bot commented on 516c472 Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zzulanas-dev – ./

zzulanas-dev-zzulanas.vercel.app
zzulanas-dev.vercel.app
zzulanas-dev-git-main-zzulanas.vercel.app

Please sign in to comment.