Supabase - an open-source database infrastructure built on PostgreSQL.
OpenAI Models - models used here are
gpt-4
andtext-embedding-ada-002
A Supabase and OpenAI system is built, that allows to call an API endpoint with a question, and then generate an answer based on the custom data provided. This is done by using PostgreSQL vector storage, Supabase Edge functions, and OpenAI Embeddings. A supabase and OpenAI account is required.
Data about a fake person named Anitha is stored in .txt file, it's then turned into an embedding using the model text-embedding-ada-002
.Embeddings are stored in supabase vector.
id | content | embedding |
---|---|---|
1 | Anitha grew up in a small town in Kerala. | [0.019696854, 0.00064515544, 2.64515544] |
2 | After excelling in math and science classes in high school. | [0.0019600854, 0.01064515544, 0.64515544] |
A post endpoint is defined to receive questions in the request body. The questions are then converted into embeddings.
match_documents
returns an array of matching documents to the question.Then loop through the array of documents, format them for chatgpt promt.gpt-4
model is used.
const completionResponse = await openai.chat.completions.create({
messages:[{
role: "system",
content: `You are a happy and helpful assistant named Poppy.Who answers qustions based on the context sections
${matching_documents_array}`,
},
{ role: "user", content: "<question from user>? },],
model: "gpt-4",
})
Source code
https://github.com/AngelMathew/chatbotApi.git