### Download and Install NVIDIA AI Workbench CLI (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Downloads the latest version of the NVIDIA AI Workbench CLI (nvwb-cli) for the current architecture, makes it executable, and runs the installer with sudo. This should be run on the remote machine. ```bash mkdir -p $HOME/.nvwb/bin && \ curl -L https://workbench.download.nvidia.com/stable/workbench-cli/$(curl -L -s https://workbench.download.nvidia.com/stable/workbench-cli/LATEST)/nvwb-cli-$(uname)-$(uname -m) --output $HOME/.nvwb/bin/nvwb-cli && \ chmod +x $HOME/.nvwb/bin/nvwb-cli && \ sudo -E $HOME/.nvwb/bin/nvwb-cli install ``` -------------------------------- ### Make AppImage Executable - Bash Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md This command makes the downloaded NVIDIA AI Workbench AppImage file executable on Ubuntu, which is a necessary step before running the installer. ```bash chmod +x NVIDIA-AI-Workbench-*.AppImage ``` -------------------------------- ### AI Workbench Remote Lab Setup Diagram Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md A Mermaid flowchart illustrating the proposed setup for using NVIDIA AI Workbench with a remote lab machine. It shows a local client connecting via SSH to a remote lab machine within a 'lab environment' subgraph. ```mermaid mermaid flowchart LR local subgraph lab environment remote-lab-machine end local <-.ssh.-> remote-lab-machine ``` -------------------------------- ### Defining a Frontend View (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md This Python snippet demonstrates how to define a new view in `code/frontend/server.py` using the `frontend.view.View` class. It configures the view's name for the menu and assigns optional Gradio pages to the left and right layout sections. ```python my_view = frontend.view.View( name="My New View", # the name in the menu left=frontend.pages.sample_page, # the page to show on the left right=frontend.pages.another_page # the page to show on the right ) ``` -------------------------------- ### Setting Custom Config File Path (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Demonstrates how to specify a custom configuration file path for the application using the `APP_CONFIG` environment variable. This file will take precedence over default locations. ```bash export APP_CONFIG=/etc/my_config.yaml ``` -------------------------------- ### Audit Python Environment (shell) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Runs a script to audit the installed Python packages, reporting those in a warning or error state (indicating potential CVEs or vulnerabilities). ```shell /project/code/tools/audit.sh ``` -------------------------------- ### Chat Frontend Configuration Schema (YAML) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Defines the configuration options for the Chat Frontend component. It includes settings for connecting to the Chain Server, handling proxy prefixes, and specifying the Chain Server's config file location. ```yaml # The URL to the chain on the chain server. # ENV Variables: APP_CHAIN_URL # Type: string chain_url: http://localhost:3030/ # The url prefix when this is running behind a proxy. # ENV Variables: PROXY_PREFIX, APP_PROXY_PREFIX # Type: string proxy_prefix: / # Path to the chain server's config. # ENV Variables: APP_CHAIN_CONFIG_FILE # Type: string chain_config_file: ./config.yaml log_level: ``` -------------------------------- ### Connection Flow Diagram - Mermaid Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_3_0_install_nvwb.md This Mermaid flowchart visualizes the network connection setup described in the text, showing a local client machine connecting to a remote lab machine within a lab environment using SSH. ```Mermaid flowchart LR local subgraph lab environment remote-lab-machine end local <-.ssh.-> remote-lab-machine ``` -------------------------------- ### Authenticating Docker with NGC Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Instructs the user to run the Docker login command to authenticate their Docker client with the NVIDIA Container Registry (nvcr.io) using their NGC Personal Key. The subsequent steps explain how to provide the username ($oauthtoken) and password (the NGC Personal Key). ```bash docker login nvcr.io ``` -------------------------------- ### Chain Server Configuration Schema (YAML) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Defines the structure and available options for configuring the Chain Server component. It includes settings for API keys, database connections, model details (LLM, embedding, reranking), and logging. Environment variable mappings are also indicated. ```yaml # Your API key for authentication to AI Foundation. # ENV Variables: NGC_API_KEY, NVIDIA_API_KEY, APP_NVIDIA_API_KEY # Type: string, null nvidia_api_key: ~ # The Data Source Name for your Redis DB. # ENV Variables: APP_REDIS_DSN # Type: string redis_dsn: redis://localhost:6379/0 llm_model: # The name of the model to request. # ENV Variables: APP_LLM_MODEL__NAME # Type: string name: meta/llama3-8b-instruct # The URL to the model API. # ENV Variables: APP_LLM_MODEL__URL # Type: string url: https://integrate.api.nvidia.com/v1 embedding_model: # The name of the model to request. # ENV Variables: APP_EMBEDDING_MODEL__NAME # Type: string name: nvidia/nv-embedqa-e5-v5 # The URL to the model API. # ENV Variables: APP_EMBEDDING_MODEL__URL # Type: string url: https://integrate.api.nvidia.com/v1 reranking_model: # The name of the model to request. # ENV Variables: APP_RERANKING_MODEL__NAME # Type: string name: nv-rerank-qa-mistral-4b:1 # The URL to the model API. # ENV Variables: APP_RERANKING_MODEL__URL # Type: string url: https://integrate.api.nvidia.com/v1 milvus: # The host machine running Milvus vector DB. # ENV Variables: APP_MILVUS__URL # Type: string url: http://localhost:19530 # The name of the Milvus collection. # ENV Variables: APP_MILVUS__COLLECTION_NAME # Type: string collection_name: collection_1 log_level: ``` -------------------------------- ### Downloading and Running NVIDIA AI Workbench Installer (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_3_4_remote_ubuntu.md Creates a directory for the Workbench CLI, downloads the latest version of the `nvwb-cli` executable for the current architecture, makes it executable, and then runs the installer with `sudo -E`. This script is executed on the remote Ubuntu host after establishing an SSH connection. ```bash mkdir -p $HOME/.nvwb/bin && \ curl -L https://workbench.download.nvidia.com/stable/workbench-cli/$(curl -L -s https://workbench.download.nvidia.com/stable/workbench-cli/LATEST)/nvwb-cli-$(uname)-$(uname -m) --output $HOME/.nvwb/bin/nvwb-cli && \ chmod +x $HOME/.nvwb/bin/nvwb-cli && \ sudo -E $HOME/.nvwb/bin/nvwb-cli install ``` -------------------------------- ### HTML Structure for Frontend Logo Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md This HTML snippet from `code/frontend/_assets/index.html` shows the `div` element with ID `logo` that contains the SVG definition for the frontend logo. Modifying the SVG content within this div allows customization of the displayed logo. ```html ``` -------------------------------- ### Update Python Packages and NIMs (shell) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Automatically updates Python dependencies and NIM applications by running the specified shell script. ```shell /project/code/tools/bump.sh ``` -------------------------------- ### Mermaid Diagram: Left-Only Frontend Layout Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md This Mermaid diagram visualizes the frontend layout when only the left page is configured in a view. It shows a menu bar above a single-column section where the left page iframe expands to fill the available space. ```mermaid block-beta columns 1 menu["menu bar"] block columns 1 left:1 end ``` -------------------------------- ### Mermaid Diagram: Two-Page Frontend Layout Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md This Mermaid diagram visualizes the frontend layout when both left and right pages are configured in a view. It depicts a menu bar above a two-column section where the left and right page iframes are displayed side-by-side. ```mermaid block-beta columns 1 menu["menu bar"] block columns 2 left right end ``` -------------------------------- ### Install pypdf Library (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Installs the `pypdf` library using pip, which is required for loading PDF documents. This command is typically executed within a notebook environment. ```bash !pip install pypdf ``` -------------------------------- ### Generate and Copy SSH Key (Windows PowerShell) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Generates an RSA SSH key pair if it doesn't exist and appends the public key to the remote machine's authorized_keys file using PowerShell. Requires replacing REMOTE_USER and REMOTE-MACHINE. ```powershell ssh-keygen -f "C:\Users\local-user\.ssh\id_rsa" -t rsa -N '""' type $env:USERPROFILE\.ssh\id_rsa.pub | ssh REMOTE_USER@REMOTE-MACHINE "cat >> .ssh/authorized_keys" ``` -------------------------------- ### Generate and Copy SSH Key (MacOS/Linux Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Generates an RSA SSH key pair if it doesn't exist and copies the public key to the remote machine's authorized_keys file using ssh-copy-id. Requires replacing REMOTE_USER and REMOTE-MACHINE. ```bash if [ ! -e ~/.ssh/id_rsa ]; then ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ""; fi ssh-copy-id REMOTE_USER@REMOTE-MACHINE ``` -------------------------------- ### Setting up SSH Key Authentication (PowerShell) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_3_4_remote_ubuntu.md Generates an RSA SSH key pair on a Windows local client and appends the public key to the authorized_keys file on the remote Ubuntu machine for passwordless SSH access. Requires replacing placeholders for the local user, remote user, and remote machine address. ```powershell ssh-keygen -f "C:\Users\local-user\.ssh\id_rsa" -t rsa -N '""' type $env:USERPROFILE\.ssh\id_rsa.pub | ssh REMOTE_USER@REMOTE-MACHINE "cat >> .ssh/authorized_keys" ``` -------------------------------- ### Setting up SSH Key Authentication (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_3_4_remote_ubuntu.md Checks if an RSA SSH key pair exists on a MacOS or Linux local client. If not, it generates one. Then, it uses `ssh-copy-id` to securely copy the public key to the remote Ubuntu machine's authorized_keys file, enabling passwordless SSH. Requires replacing placeholders for the remote user and remote machine address. ```bash if [ ! -e ~/.ssh/id_rsa ]; then ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ""; fi ssh-copy-id REMOTE_USER@REMOTE-MACHINE ``` -------------------------------- ### Make AI Workbench AppImage Executable - Bash Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_3_3_ubuntu.md This command uses the 'chmod' utility to add execute permissions ('+x') to the downloaded NVIDIA AI Workbench AppImage file, making it runnable. This is a required step before executing the installer. ```bash chmod +x NVIDIA-AI-Workbench-*.AppImage ``` -------------------------------- ### Post Message to Parent Window (JavaScript) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Posts a message containing a configuration update (`{"use_kb": true}`) to the top-level window (application shell) using `window.top.postMessage`. This message is intended for inter-page communication within a multi-page view, allowing one page (e.g., 'control') to signal changes to another (e.g., 'chat'). The message is forwarded by the shell to all child iframes. ```javascript window.top.postMessage({"use_kb": true}, '*'); ``` -------------------------------- ### Handle Incoming Messages and Update Gradio Component (JavaScript) Source: https://github.com/nvidia/nim-anywhere/blob/main/README.md Adds an event listener to the window for incoming `message` events. It checks if the message is trusted (`event.isTrusted`). If so, it finds a Gradio component with the `elem_id` 'use_kb' within the `gradio_config` and updates its `value` property with the corresponding data received in the message payload (`event.data["use_kb"]`). This allows synchronizing component values across different pages receiving the same message. ```javascript window.addEventListener( "message", (event) => { if (event.isTrusted) { use_kb = gradio_config.components.find((element) => element.props.elem_id == "use_kb"); use_kb.props.value = event.data["use_kb"]; }; }, false); ``` -------------------------------- ### Defining a Frontend View in Python Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md Illustrates how to define a new view using the `frontend.view.View` class. Describes the `name` parameter for the menu label and the optional `left` and `right` parameters to specify the Gradio pages to display in the view's layout. ```python my_view = frontend.view.View( name="My New View", # the name in the menu left=frontend.pages.sample_page, # the page to show on the left right=frontend.pages.another_page # the page to show on the right ) ``` -------------------------------- ### Run All Linters Shell Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.0_contributing.md Executes the main linting script to run all configured code quality checks and security scans as performed by the CI pipelines. ```Shell /project/code/tools/lint.sh ``` -------------------------------- ### Initialize NVIDIA Embedding Model (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Initializes the `NVIDIAEmbeddings` model from `langchain_nvidia_ai_endpoints` using configuration values. It requires an NVIDIA API key, model name, and base URL to connect to the NVIDIA AI endpoint. ```python from chain_server.configuration import config from langchain_nvidia_ai_endpoints import NVIDIAEmbeddings # "nvapi-xxx" is the NVIDIA API KEY format. If you have not configured this variable, be sure to do so. embedding_model = NVIDIAEmbeddings( model=config.embedding_model.name, base_url=str(config.embedding_model.url), api_key=config.nvidia_api_key, truncate="END" ) ``` -------------------------------- ### Mermaid Diagram for Full Frontend Layout Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md Visual representation using Mermaid syntax showing the frontend layout when both the left and right pages are defined within a view. It depicts the menu bar at the top and a two-column layout below for the left and right content areas. ```mermaid block-beta columns 1 menu["menu bar"] block columns 2 left right end ``` -------------------------------- ### Unzip Dataset (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Unzips the sample PDF dataset archive `corp-comms-dataset.zip` into the `../data/` directory. The `-n` flag prevents overwriting existing files if they already exist. ```bash !unzip -n ../data/corp-comms-dataset.zip -d ../data/ ``` -------------------------------- ### Run Specific Linter Shell Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.0_contributing.md Runs the linting script with a specific argument to target a particular check or action, such as dependency checks, Pylint, MyPy, Black formatting, documentation checks, or automatic fixes. ```Shell /project code/tools/lint.sh [deps|pylint|mypy|black|docs|fix] ``` -------------------------------- ### Project Dependencies - Python Source: https://github.com/nvidia/nim-anywhere/blob/main/requirements.txt This snippet specifies the Python packages and their versions needed to run the project. It follows the standard requirements.txt format used by pip. ```Python requirements confz==2.0.1 fastapi==0.115.6 gradio==5.9.1 grandalf==0.8 jupyterlab>3.0 langchain==0.3.14 langchain-community==0.3.14 langchain-milvus==0.1.7 langchain-nvidia-ai-endpoints==0.3.7 langchain-openai==0.2.14 langserve==0.3.1 opentelemetry-instrumentation-fastapi==0.50b0 pydantic pymilvus==2.5.3 pypdf redis==5.2.1 sse-starlette==2.2.1 uvicorn==0.34.0 watchfiles==1.0.3 ``` -------------------------------- ### Perform Similarity Search (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Executes a similarity search query against the populated Milvus vector store using the initialized embedding model. It retrieves the top similar documents based on the query and prints the first result. ```python query = "How is NVIDIA working with Mercedes Benz?" docs = vector_store.similarity_search(query) print(docs[0]) ``` -------------------------------- ### Initialize Milvus Vector Store (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Initializes the `Milvus` vector store object using the previously created embedding function and configuration details for the Milvus connection and collection name. Sets `auto_id` to True. ```python from langchain_milvus.vectorstores.milvus import Milvus vector_store = Milvus( embedding_function=embedding_model, connection_args={"uri": config.milvus.url}, collection_name=config.milvus.collection_name, auto_id=True, ) ``` -------------------------------- ### Mermaid Diagram for Left-Only Frontend Layout Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md Visual representation using Mermaid syntax showing the frontend layout when only the left page is defined within a view. It depicts the menu bar at the top and a single-column layout below for the left content area, which expands to fill the available space. ```mermaid block-beta columns 1 menu["menu bar"] block columns 1 left:1 end ``` -------------------------------- ### Receiving and Handling Message (JavaScript) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md This snippet adds an event listener for `message` events on the current window. It checks if the received message is trusted (`event.isTrusted`). If trusted, it finds a Gradio component by its `elem_id` and updates its `value` property using the data from the received message (`event.data`). This allows synchronizing component states across pages. ```javascript window.addEventListener( "message", (event) => { if (event.isTrusted) { use_kb = gradio_config.components.find((element) => element.props.elem_id == "use_kb"); use_kb.props.value = event.data["use_kb"]; }; }, false); ``` -------------------------------- ### List of Excluded Packages - Configuration List Source: https://github.com/nvidia/nim-anywhere/blob/main/req.filters.txt Specifies the list of package names that should be excluded from the final container image during the build process. These packages are explicitly omitted. ```Configuration List jupyterlab grandalf watchfiles ``` -------------------------------- ### Authenticating Docker with NGC Registry (Bash) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/0_2_docker_auth.md Logs the Docker client into the NVIDIA NGC container registry (`nvcr.io`). This is required to pull NVIDIA NIM containers. When prompted, use `$oauthtoken` as the username and your NGC Personal Key as the password. ```bash docker login nvcr.io ``` -------------------------------- ### Execute PDF Upload (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Sets the number of documents to upload and calls the `upload_pdf_files` function to process PDF files from the specified dataset folder (`../data/dataset`) and add their content to the Milvus vector store. ```python NUM_DOCS_TO_UPLOAD=10 upload_pdf_files("../data/dataset", NUM_DOCS_TO_UPLOAD) ``` -------------------------------- ### Sending Message to App Shell (JavaScript) Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md This snippet sends a message to the top-level window (application shell) using `window.top.postMessage`. The message contains a JSON object payload. The second argument `*` specifies that the message can be sent to any origin, which is suitable for communication within the same application structure. ```javascript window.top.postMessage({"use_kb": true}, '*'); ``` -------------------------------- ### Apache License 2.0 Boilerplate Notice Source: https://github.com/nvidia/nim-anywhere/blob/main/LICENSE.txt The standard boilerplate notice recommended by the Apache License, Version 2.0 for inclusion in source files. Fields enclosed in brackets '{}' should be replaced with specific project information. This text is typically placed within comments appropriate for the file format. ```Text Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### HTML Structure for Frontend Logo Source: https://github.com/nvidia/nim-anywhere/blob/main/docs/3.1_frontend.md Shows the basic HTML structure used for displaying the logo in the application shell. The SVG content within the `div` with the ID `logo` can be replaced with a different SVG definition to customize the logo image. ```html ``` -------------------------------- ### Define PDF Upload Functions (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Defines two helper functions: `upload_document` to load, split, and add a single PDF file's content to the vector store, and `upload_pdf_files` to iterate through a specified folder and upload a given number of PDF files. ```python import glob from langchain_community.document_loaders import PyPDFLoader from langchain.text_splitter import RecursiveCharacterTextSplitter def upload_document(file_path): loader = PyPDFLoader(str(file_path)) data = loader.load() text_splitter = RecursiveCharacterSplitter() all_splits = text_splitter.split_documents(data) vector_store.add_documents(documents=all_splits) return f"uploaded {file_path}" def upload_pdf_files(folder_path, num_files): i = 0 for file_path in glob.glob(f"{folder_path}/*.pdf"): print(upload_document(file_path)) i += 1 if i >= num_files: break ``` -------------------------------- ### Print Milvus Collection Name (Python) Source: https://github.com/nvidia/nim-anywhere/blob/main/code/upload-pdfs.ipynb Prints the configured collection name for the Milvus vector database. This is useful for verifying that the correct collection name is being used. ```python print(config.milvus.collection_name) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.