Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Template for building your own custom ChatGPT style doc search powered by Fresh, Deno, OpenAI, and Supabase.

NotificationsYou must be signed in to change notification settings

supabase-community/deno-fresh-openai-doc-search

Repository files navigation

Template for building your own custom ChatGPT style doc search powered by Fresh,Deno, OpenAI, and Supabase.

This starter takes all the.mdx files in thedocs directory and processesthem to use as custom context withinOpenAI Text Completionprompts.

Made with Fresh

Run locally

Prerequisites

Setup env vars:

cp .env.example .env

Set the required env vars as outlined in the file.

Start the project:

supabase startdeno task embeddingsdeno task start

This will watch the project directory and restart as necessary.

Deploy

Push local migrations to Supabase

  1. Create a new project on Supabase
  2. Link your project:supabase link --project-ref=your-project-ref
  3. Push up migration:supabase db push

Setup GitHub Action

We're using aGitHub Action togenerate the embeddings whenever we merge into themain branch.

  1. GetSUPABASE_URL andSUPABASE_SERVICE_ROLE_KEY from yourSupabase Studio and setthem as Actions secrets in GitHub.
  2. SetOPENAI_KEY as Actions secrets in GitHub.
  3. Push or merge intomain to kick off the GitHub action.

Automatic Deployment with Deno Deploy

These steps show you how to deploy your app close to your users at the edge withDeno Deploy.

  1. Clone this repository to your GitHub account.

  2. Sign intoDeno Deploy with your GitHub account.

  3. Select your GitHub organization or user, repository, and branch

  4. Select "Automatic" deployment mode andmain.ts as the entry point

  5. Click "Link", which will start the deployment.

  6. Once the deployment is complete, click on "Settings" and add the productionenvironmental variables, then hit "Save"

Voila, you've got your own custom ChatGPT!

Technical Details

Building your own custom ChatGPT involves four steps:

  1. [⚡️ GitHub Action] Pre-process the knowledge base (your.mdx files in yourdocs folder).
  2. [⚡️ GitHub Action] Store embeddings in Postgres withpgvector.
  3. [🏃 Runtime] Perform vector similarity search to find the content that'srelevant to the question.
  4. [🏃 Runtime] Inject content into OpenAI GPT-3 text completion prompt andstream response to the client.

⚡️ GitHub Action

Step 1. and 2. happen via aGitHub Action anytime we makechanges to themain branch. During this time thegenerate-embeddings script is being executedwhich performs the following tasks:

sequenceDiagram    participant GitHub Action    participant DB (pgvector)    participant OpenAI (API)    loop 1. Pre-process the knowledge base        GitHub Action->>GitHub Action: Chunk .mdx files into sections        loop 2. Create & store embeddings            GitHub Action->>OpenAI (API): create embedding for page section            OpenAI (API)->>GitHub Action: embedding vector(1536)            GitHub Action->>DB (pgvector): store embedding for page section        end    end
Loading

In addition to storing the embeddings, this script generates a checksum for eachof your.mdx files and stores this in another database table to make sure theembeddings are only regenerated when the file has changed.

🏃 Runtime

Step 3. and 4. happen at runtime, anytime the user submits a question. When thishappens, the following sequence of tasks is performed:

sequenceDiagram    participant Client    participant Edge Function    participant DB (pgvector)    participant OpenAI (API)    Client->>Edge Function: { query: lorem ispum }    critical 3. Perform vector similarity search        Edge Function->>OpenAI (API): create embedding for query        OpenAI (API)->>Edge Function: embedding vector(1536)        Edge Function->>DB (pgvector): vector similarity search        DB (pgvector)->>Edge Function: relevant docs content    end    critical 4. Inject content into prompt        Edge Function->>OpenAI (API): completion request prompt: query + relevant docs content        OpenAI (API)-->>Client: text/event-stream: completions response    end
Loading

The relevant files for this are theSearchDialog (Client) component and thevector-search (Edge Function).

The initialization of the database, including the setup of thepgvectorextension is stored in thesupabase/migrations folder which is automaticallyapplied to your local Postgres instance when runningsupabase start.

Learn More

Video: How I Built Supabase’s OpenAI Doc Search

About

Template for building your own custom ChatGPT style doc search powered by Fresh, Deno, OpenAI, and Supabase.

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp