Supercharge AI Apps with Custom Embeddings and Chat GPT
Table of Contents:
- Introduction
- Generating Custom Embeddings with Superbass
2.1 Installing Super Bass CLI
2.2 Creating a New Super Bass Project
2.3 Creating a New Edge Function
2.4 Generating Embeddings
2.5 Configuring the Serve Function
- Using Vex Library for Chat GPT with Additional Context
3.1 Installing Vex and Other Libraries
3.2 Loading and Preparing the Wikipedia Dataset
3.3 Connecting Vex to Postgres Database
3.4 Querying and Retrieving Relevant Articles
3.5 Providing Additional Context to Chat GPT
- Conclusion
Introduction
In this article, we will explore how easy it is to generate custom embeddings using Superbass, a powerful AI Tool. We will walk through a step-by-step example using Super Bass Edge functions and the new transformers.js Package. Additionally, we will also Delve into the usage of the Vex library in Python to provide chat GPT with additional context from Wikipedia. By the end of this article, You will have a clear understanding of how to leverage Superbass's tooling to build AI apps with custom embeddings and chat GPT.
Generating Custom Embeddings with Superbass
To begin, we need to install the Super Bass CLI and Create a new Super Bass project. By following the steps outlined below, we can generate embeddings using Superbass:
Installing Super Bass CLI
To get started with Superbass, we need to install the Super Bass CLI. This can be done by running the command 'npm install D Super Bass' in a new node.js project. This command will also install the Super Bass CLI as a Dev dependency, ensuring that we have a specific version of the CLI for our project.
Creating a New Super Bass Project
Once the Super Bass CLI is installed, we can create a new Super Bass project using the 'MPX Super Bass init' command. This command initializes the Super Bass project and generates the necessary workspace settings for VSCode. By opening the project workspace, we can view the project structure, with separate folders for the node.js part and the Super Bass Edge functions.
Creating a New Edge Function
To generate embeddings, we need to create a new Edge function within our Super Bass project. By using the 'MPX Super Bass functions new' command, we can create a new Edge function called 'generate-embedding'. This command generates a folder within the Super Bass functions directory, along with an index.ts file for our new Edge function.
Generating Embeddings
Now that we have our Edge function set up, we can start generating embeddings. In this step, we will import the pipeline function from the transformers.js package, which is responsible for generating our embeddings. Additionally, we need to set some configuration options, such as disabling browser cache and local models, to ensure smooth execution within the Dino Edge environment. Once the configuration is set, we can call the pipeline function with the appropriate parameters to generate the embeddings using the Super Bass GTE Small model. This model has a low dimension size, which is crucial for optimal performance.
Configuring the Serve Function
To serve our Edge function and receive input and output, we need to modify the serve function. We will modify the serve function to accept input, generate embeddings using the 'generate-embedding' function, and provide configuration options such as setting the pooling to mean and normalization to true. Finally, we can send back the generated embeddings as the response from our Edge function.
Using Vex Library for Chat GPT with Additional Context
In addition to generating custom embeddings with Superbass, we can also enhance chat GPT with additional context using the Vex library in Python. The following steps explain how to achieve this:
Installing Vex and Other Libraries
To use the Vex library, we need to install it along with other required libraries. Vex is a tool developed by Superbass and is capable of handling the installation of additional machine learning dependencies. We also need to install the datasets library, which provides a convenient wrapper for open source datasets from Hugging Face. Lastly, we need to install the passar library, which is a sub-dependency required for certain datasets.
Loading and Preparing the Wikipedia Dataset
Once the required libraries are installed, we can proceed to load the Wikipedia dataset using the datasets library. The dataset contains millions of records, so manual input is not feasible. We then connect Vex to our PostgreSQL database using the connection STRING obtained from the Superbass dashboard. With the connection established, we create a new collection in our database, called 'Wiki_collection', and use the adapter to chunk up paragraphs and generate embeddings using a Hugging Face model for sentences.
Querying and Retrieving Relevant Articles
After preparing the dataset and generating embeddings, we can query our 'Wiki_collection' for specific articles. In this example, we filter the dataset to retrieve articles related to the Olympics and the year 2022. By limiting the query to the closing ceremony of the 2022 Winter Olympics, we can obtain relevant results. We iterate over the retrieved articles, printing their titles and IDs, demonstrating the relevance of the retrieved data.
Providing Additional Context to Chat GPT
With the relevant articles and their associated titles and content, we can now provide this additional context to chat GPT using the OpenAI library. It is essential to provide the OpenAI API Key. We formulate a message prompt, informing chat GPT that it is a helpful assistant and providing the context of the Wikipedia articles. By asking a specific question regarding the closing ceremony of the 2022 Winter Olympic Games, we test chat GPT's ability to generate a response Based on the provided additional context.
Conclusion
In conclusion, Superbass provides convenient tooling to generate custom embeddings for AI applications. With the Super Bass CLI and Edge functions, we can easily create projects and generate embeddings using the transformers.js package. Additionally, the Vex library allows us to enhance chat GPT with additional context from Wikipedia. By following the steps outlined in this article, you can leverage Superbass's tooling to build powerful AI apps and chatbots with the supercharging capabilities of a billion robots.
Highlights:
- Superbass offers convenient tooling for generating custom embeddings
- Super Bass CLI simplifies project setup and management
- Transformers.js package enables easy generation of embeddings
- Vex library enhances chat GPT with additional context from Wikipedia
- PostgreSQL integration with Vex allows efficient storage and retrieval of embeddings
- Leveraging Superbass's tooling can supercharge AI applications
FAQ:
Q: What is Superbass?
A: Superbass is a platform that provides convenient tooling for AI applications, including the generation of custom embeddings and integration with chat GPT.
Q: How can I generate custom embeddings using Superbass?
A: With the Super Bass CLI and the transformers.js package, you can easily generate custom embeddings by following the step-by-step guide provided in the article.
Q: What is the Vex library used for?
A: The Vex library, developed by Superbass, allows Python users to enhance chat GPT with additional context from external sources, such as Wikipedia.
Q: Can I use Superbass for projects in languages other than JavaScript?
A: Yes, Superbass supports projects in other languages as well, such as Python. The article provides an example of using the Vex library in Python to enhance chat GPT.
Q: Is it possible to use Superbass without the Super Bass CLI?
A: While the Super Bass CLI offers convenience for project management, it is not necessary to use Superbass. The article demonstrates the usage of the Super Bass CLI but also provides alternative ways to achieve the same results in Python.
Q: Can I use my own models with Superbass?
A: Yes, Superbass supports the usage of custom models. The article showcases the usage of Hugging Face models but also mentions the option to use custom models in the Super Bass Edge functions.