Step 1: Create a Template to use the specified Prompt
The first step is to create a template where you can configure your instances. You can use your template to specify the prompt to use (eg You are a Pirate who will help with legal documents) and if the instance will be used for doing question answering over documents, input URLs or data analysis. You can also use the same template for all the instances you create in step 2. You can specify the prompt and intent when creating the template. In this tutorial, you will create a template using the following code snippet:- In the code above, we first define the prompt for the template.
- We then send a request to BerriAI’s create_template endpoint with the prompt as the payload.
- The response will contain a JSON object with a template_id key, which we will store for later use.
Step 2: Create an Instance Using an Existing Template
Next, create an instance of the template you just created. An instance is a custom GPT-4 app that is fine-tuned to the data source specified. In this case, you will create an instance of the GPT-4 app for a specific Substack blog post.Step 3: Dynamic Instance Generation + Get off localhost - Create a Flask Server
Step 3 of the tutorial is to create a server that can dynamically generate GPT-4 instances for each subsequent blog post. To achieve this, we can utilize the Berri API endpoint to generate these instances on the fly. Here is the Flask app code for this purpose:- This app uses code from Step 2 and is converted into a Flask app.
- A template ID is already available and input URLs are dynamically set.
- The Flask server listens for HTTP POST requests on the /create-app endpoint.
- When it receives a request, it extracts the input URL from the form data.
- The Flask app sends a POST request to the Berri API endpoint with appropriate parameters, including the template ID, user email, and input URL, which varies based on the substack blog post.
- The response JSON from the Berri API includes the api_endpoint and website_endpoint, which is returned to the caller of the /create-app endpoint.
- An example response for this substack https://substack.com/inbox/post/109167394
- Make a full-stack app by adding a frontend to call your Flask server. Consider using React or Vue. Here’s a starting point: https://replit.com/join/ceztxyemli-ishaan-jaff
- Customize the chat.berri.ai interface for your application. Add your own branding and keep the necessary features.
- Chat.berri.ai is open-sourced on GitHub. Check it out here: https://github.com/ClerkieAI/Berri-chat-fe.