Creating a Securechat App using BGE-large Embedding and base Llama2-7b Summarisation Models

This example will take you through the procedure of deploying a LLM chatbot that can answer questions based on specific dataset(s) provided by you.

Prerequisites

  • You need to create a folder in your workspace. This folder will contain all the documents you are going to use for data ingestion.

    • You can directly put your document-containing folder in the workspace from your local system by using the filebrowser application on the workspace tab in DKubeX UI, or you can create a folder from the CLI to download the files from their URL.

      Note

      If you are going to use Skypilot for the ingestion process, make sure to keep the folder inside the /home/data/ directory on your DKubeX setup. As this directory can be accessed only from the CLI, you will need to first place it on your workspace, and then move it to the /home/data/ directory using the CLI.

  • Open the terminal application and export the following variables to your workspace by running the following commands on your terminal.

    • Replace the your DKubeX URL with the URL of your setup, <your DKubeX API key> part with your DKubeX API key, <your huggingface token> part with your Huggingface token to access the Llama2-7B model, and <username> with your DKubeX workspace name.

      Hint

      Use the following steps to find your DKubeX API key:

      • Open the DKubeX UI and click on your username on upper-right corner of the UI.

      • Click on the API Key option from the dropdown menu. A pop-up dialog box containing your DKubeX API key will open. Copy and note down this key.

      export PYTHONWARNINGS="ignore"
      export OPENAI_API_KEY="dummy"
      export DKUBEX_URL="<your DKubeX URL>"
      export DKUBEX_APIKEY="<your DKubeX API key>"
      export HF_TOKEN="<your huggingface token>"
      export NAMESPACE="<username>"
      export HOMEDIR=/home/${NAMESPACE}
      
  • The Llama2-7b model needs to be deployed on DKubeX.

    Note

    For detailed information regarding this section, please refer to Deploying LLMs in DKubeX.

    Here we will deploy the base Llama2-7B model, which is already pre-registered with DKubeX.

    Note

    This workflow requires an a10 GPU node. Make sure your cluster is equipped with such. Also, in case you are using any other type of GPU node, make sure to use the label for that node which you have put during DKubeX installation process.

    • Deploy the base Llama2-7B model using the following command.

      d3x llms deploy --name=llama27bbase --model=meta-llama--Llama-2-7b-chat-hf --type=a10 --token ${HF_TOKEN} --publish
      

      Note

      In case you are using a EKS setup, please change the value of the flag --type from a10 to g5.4xlarge in the following command. Also, in case you are using any other type of GPU node, make sure to use the label for that node which you have put during DKubeX installation process.

    • You can check the status of the deployment from the Deployments page in DKubeX or by running the following command.

      d3x serve list
      
    • Wait until the deployment is in running state.

Data ingestion and creating dataset

Note

This example uses the BAAI/bge-large-en-v1.5 embeddings model for data ingestion.

Data ingestion process can be done with or without using Skypilot. The procedures for both are given below.

  • A few .yaml files are required to be used in the ingestion process.

    • On the Terminal application in DKubeX UI, run the following commands. Replace the <username> part with your DKubeX workspace name.

      git clone https://github.com/dkubeio/dkubex-examples.git
      cd dkubex-examples
      git checkout llamaidx
      cd rag/ingestion
      cp ingest.yaml /home/<username>/ingest.yaml && cp custom_sdr.py /home/<username>/custom_sdr.py && cd
      
    • You need to provide proper details on the ingest.yaml file. Run vim ingest.yaml and make the following changes.

      • On the reader:inputs:loader_args:input_dir: section, provide the absolute path to your dataset folder.

      • On the reader:pyloader: section, provide the absolute path to the custom_sdr.py file, i.e. in this case, /home/<username>/dkubex-examples/rag/examples/custom_sdr.py.

    • You can also modify and customize several other options in the ingest.yaml file according to your needs, including the splitter class, chunk size, embedding model to be used, etc.

      Attention

      • The reader section in the ingest.yaml file denotes the type of dataloader to be used for the ingestion process. If you are going to use any other source of data for ingestion as compared to local directory data shown in this example, you need to provide the appropriate details for that type of dataloader.

        • For more information about dataloaders please visit How to use different Data Loaders (Data Readers).

        • You can use multiple type of data sources by providing the reader details simultaneously under the reader section in the ingest.yaml file.

      • Some of the dataloaders require separate pyloader files. Make sure to provide them, if needed.

  • Use the following command to trigger the ingestion process.

    d3x dataset ingest -d <dataset name> --config <absolute path to the ingest.yaml file>
    

    Note

    • The time taken for the ingestion process to complete depends on the size of the dataset. Please wait patiently for the process to complete.

    • In case the terminal shows a timed-out error, that means the ingestion is still in progress, and you will need to run the command provided on the CLI after the error message to continue to get the ingestion logs.

    • The record of the ingestion and related artifacts are also stored in the MLFlow application on DKubeX UI.

  • To check if the dataset has been created, stored and are ready to use, use the following command:

    d3x dataset list
    
  • To check the list of documents that has been ingested in the dataset, use the following command:

    d3x dataset show -d <dataset name>
    

Creating and accessing the chatbot application

  • From the DKubeX UI, open and log into the SecureLLM application. Once open, click on the Admin Login button and log in using the admin credentials provided during installation.

    Hint

    In case you do not have the credentials for logging in to SecureLLM, please contact your administrator.

  • On the left sidebar, click on the Keys menu and go to the Application Keys tab on that page.

  • To create a new key for your application, use the following steps:

    • On the API key name field, provide a unique name for the key to be created.

      ../_images/apikeyname2.png
    • From the LLM Keys dropdown list, select DKUBEX.

      ../_images/apikeyllmkey2.png
    • From the Models dropdown list, select your deployed base model.

      ../_images/apikeymodel2.png
    • Click on the Generate Key button.

  • A pop-up window will show up on your screen containing the application key for your new application. Alternatively, you can also access your application key from the list of keys in the Application Key tab.

    ../_images/sec292.png ../_images/sec302.png
    • Copy this application key for further use, as it will be required to create the chatbot application. Also make sure that you are copying the entire key including the sk- part.

  • From the DKubeX UI, go to the Terminal application.

  • You will need to configure and use the query.yaml file from the dkubex-examples repo to be used in the query process in the Securechat application.

    • Run the following command to put the query.yaml file on your workspace.

      cd
      cp dkubex-examples/rag/query/query.yaml ./query.yaml
      
    • Provide the following details on the query.yaml file. Once provided, save the file.

      • On the vectorstore_retriever:dataset: section, provide the name of your ingested dataset.

      • On the chat_engine:url: section, provide the endpoint URL of the deployed model to be used. The syntax for the URL is provided below. Replace <deployment name> with name of the deployment created earlier, and <your username> part with your username.

        http://<deployment name>-serve-svc.<your username>:8000
        

      Note

      You are providing your own username here because the llama27bbase deployment was done from your workspace earlier. If you are going to use a model deployed by any other user, you will need to provide the proper deployment name in place of llama27bbase and the username of that user.

      • On the tracking:experiment: section, provide a name for the experiment under which the query records and artifacts will be stored in MLFlow.

  • Create a new file on your workspace called securechat.yaml. This file will be used to create the securechat application.

    cd && touch securechat.yaml
    
    • Provide the following content on the file. Replace the parts in <> with the appropriate values.

      image: dkubex123/llmapp:securechat-081
      name: <securechat app name>
      cpu: 1
      gpu: 0
      memory: 4
      dockerserver: DOCKER_SERVER
      dockeruser: dkubex123
      dockerpsw: dckr_pat_dE90DkE9bzttBinnniexlHdPPgI
      publish: "true"
      env:
        OPENAI_API_KEY: ""
        SECUREAPP_ACCESS_KEY: allow
        FMQUERY_ARGS: "llm --dataset <dataset name> -dep <deployment name> -n <your username> --config /home/<your username>/query.yaml --securellm.appkey=<your secureLLM API key>"
      port: "3000"
      description: "<App description>"
      rewritetarget: "false"
      configsnippet: ""
      ingressprefix: /<identifier for app URL>
      output: yaml
      

      Note

      You are providing your own username here because the llama27bbase deployment was done from your workspace earlier. If you are going to use a model deployed by any other user, you will need to provide the proper deployment name in place of llama27bbase and the username of that user.

  • Launch the app deployment with the following command:

    d3x apps create -c securechat.yaml
    
  • To check the status of the app deployment, use the following command:

    d3x apps list
    
  • Once the app deployment status becomes running, you can access the application from the Apps page of DKubeX UI. Provide the application key that you set in the SECUREAPP_ACCESS_KEY field earlier to start using the chat application.