-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
37 additions
and
34 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
516c472
There was a problem hiding this comment.
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