Skip to content

mandarini/ai-ng-docs

Repository files navigation

Angular AI Docs

Tools used

Credit

Inspired by: supabase-community/nextjs-openai-doc-search

Most code adjusted from Nx, specifically from:

Here is the Nx AI Assistant which this repo replicates (the functionality of).

You can read more about it in our blog post:

Contents

  • A script to create embeddings from the Angular docs and then save these embeddings on Supabase. Here's what it does:
    • Splits each markdown file into sections, based on the markdown headings.
    • Creates an embedding for each section using the text-embedding-ada-002 model from openai.
    • Saves the section embedding on Supabase.
  • A Nest.js app that does the following:
    • Creates an embedding for the user query using the text-embedding-ada-002 model from openai.
    • Sends the query embedding to Supabase.
    • Supabase tries to match the query embedding with the embeddings of the Angular docs sections. Using pgvector it tries to find the most similar embeddings.
    • It returns the most similar sections.
    • It concatenates these sections to the user query, along with a prompt, and sends it to openai's chat completion API.
    • It gets back the answer from openai and returns it.
  • A super simple Angular interface and service and interacts with Nest.js (gets user input, sends it to the server, gets the answer, and displays it).

How to use

API keys

You need API keys for OpenAI and Supabase. So, you need to fill in the following env vars:

  • OPENAI_KEY
  • SUPABASE_SERVICE_ROLE_KEY
  • PUBLIC_SUPABASE_URL

Running the app

  • Clone the repo, install the deps with npm i.
  • Run the server: npx nx serve ai-api
  • Run the Angular app: npx nx serve ai-chat
  • Navigate to localhost:4200 and ask a question about Angular.

To generate embeddings

  • Add the docs directory in your .env file.
  • Run the script: nx run embeddings:create

Useful links

Note

This repo contains the final code from the ng-conf 2024 workshop by Katerina Skroumpelou. You can find the starter version here: https://github.com/mandarini/ai-ng-docs-starter.

About

Final version for the ng conf workshop.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published