Building with Open AI
Step 1: Verify Docker Installation
First, let’s verify that Docker is properly installed and open in your system. Open your terminal (Command Prompt on Windows) and run:
You should see the Docker version information if it's installed correctly. If not, you might want to revist the prerequisites and the Docker Basics section.
Step 2: Clone the LLM App Templates Repository
Next, clone the llm-app repository from GitHub. This repository contains all the files you’ll need.
If you get an error because you have previously cloned an older version of the llm-app repository, ensure you're in the correct repository directory and update it using:
This will update your local repository with the latest changes from the remote repository.
Step 3: Navigate to the relevant project directory
Change to the directory where the example is located.
Step 4: Changes in the requirements.txt, app.py and config.yaml files
In the Pathway LLM App repo (which you’ve already starred ⭐), you’ll see the demo question-answering template that uses YAML files to help you quickly set up the pipeline. While this makes Dockerized RAG applications 10x easier to productionize, in this bootcamp, we will take a different approach. You’ll skip the shortcuts and dive deeper into the application code, to build a solid foundation to create powerful customizations as you progress in your Gen AI journey.
Now that you’ve cloned the repo, let’s walk through some changes you’ll make to the files in the directory. This hands-on step will help you better understand how everything works under the hood.
Changes in the requirements.txt file:
To ensure you have all necessary dependencies, update the requirements.txt
file with the following content:
Changes in the app.py file
After cloning the repository and navigating to the correct directory, modify the app.py
file with the following content to ensure proper functionality:
Changes in the config.yaml
file:
config.yaml
file:Rename the existing app.yaml
file to config.yaml.
update the content of the config.yaml
file with the configuration below. It's easy to comprehend if you read the comments.:
Make sure to save the file after applying the changes.
Changes in the Dockerfile
:
Dockerfile
:Modify the Dockerfile
with the following content:
Step 5: Update your .env
File with your OpenAI API Key
.env
File with your OpenAI API KeyIn the .env
file already present in the project, replace the placeholder API key (sk-xxxxxx
) with the OpenAI API key you retrieved from the website.
Make sure to save the file after updating.
Step 6: Build the Docker Image
Now, let’s build the Docker image. This step might take a few minutes depending on your machine. Ensure you have enough space (approximately 8 GB).
The -t rag
part is tagging the Docker image with the name ‘rag’. Whereas the
.
at the end specifies the build context directory, which is the current directory. This tells Docker to look for the Dockerfile in the current directory and include any files/subdirectories in the build context.
Step 7: Run the Docker Container
Run the Docker container, mounting (described below) the data folder, and exposing port 8000.
For Windows:
For Linux/Mac:
Note: You will see the logs for parsing & embedding documents in the Docker image logs. Give it a few minutes to finish up on embeddings. You will see 0 entries (x minibatch(es)) have been... message. If there are no more updates, this means the app is ready for use!
Handling Port Conflicts: If port 8000
is already in use and you see an error related to it, you can specify a different port. For example, if you want to use port 8080
instead, modify the command as follows:
For Windows:
For Linux/Mac:
This will map port 8080
on your local machine to port 8000
in the Docker container. Just remember to update the port in the next step as well.
Open up another terminal window and follow the next steps.
Step 8: Check the List of Files
You will see the logs for parsing & embedding documents in the Docker image logs. Give it a few minutes to finish up on embeddings, you will see 0 entries (x minibatch(es)) have been… message. If there are no more updates, this means the app is ready for use!
Now, let's retrieve the list of files from which our LLMs will gather information. To check the available inputs and associated metadata, you can use either the curl
command (for Linux/Mac users) or Invoke-WebRequest
(for Windows PowerShell users) as described below:
For Linux/Mac Users (curl
command):
curl
command):Use the following curl
command to query the app:
This will return the list of files e.g. if you start with the data folder provided in the demo, the answer will be as follows:
For Windows Users (PowerShell Invoke-WebRequest
):
Invoke-WebRequest
):If you're using PowerShell on Windows, you can use the following Invoke-WebRequest
command to perform the same query:
This will also return the list of files with the associated metadata, similar to the example above.
Key Differences:
Use
curl
for Linux/Mac environments or for users who have installedcurl
on Windows.Use
Invoke-WebRequest
for users working within Windows PowerShell.
This ensures that no matter which environment you're using, you can retrieve the list of documents and associated metadata to confirm that the app is ready for queries.
Step 9: Last Step – Run the RAG Service
You can now run the RAG service. Start by asking a simple question. For example:
For Linux/Mac Users (curl
command):
curl
command):You can use the following curl
command to ask a simple question to the RAG service:
Note: If you change the port from 8000
to another value (e.g., 8080
), make sure to update the curl
command accordingly. For example, replace 8000
with 8080
in the URL.
It should return the following answer:
For Windows Users (PowerShell Invoke-WebRequest
):
Invoke-WebRequest
):If you're using PowerShell on Windows, use the Invoke-WebRequest
command to ask the same question:
Note: Just like with curl
, if you change the port to a different value (e.g., 8080
), make sure to update the URL in the Invoke-WebRequest
command.
This will return the same response with the answer:
But how do you tweak this for your use-case? Let's see that by understanding the contents of the repo which just used.
Last updated