### Setup Python Virtual Environment and Install Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Agent-Granite/Serve-Example/README.md Navigate to the example directory, create a Python virtual environment, activate it, and install necessary dependencies including Gradio and project requirements. ```bash # Navigate to the example directory cd Serve-Example # Create a Python virtual environment python -m venv .venv # Activate the virtual environment . .venv\Scripts\activate # windows source .venv/bin/activate # macOS # Install all required dependencies pip install gradio pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies for RAG Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-LLM/Serve-Example/README.md Commands to set up a Python virtual environment and install required dependencies for the RAG example. Ensure you are in the 'Serve-Example' directory. ```bash # Navigate to the example directory cd Serve-Example # Create a Python virtual environment python -m venv .venv # Activate the virtual environment .\.venv\Scripts\activate # windows source .venv/bin/activate # macOS # Install all required dependencies pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies for RAG Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-LLM/Python-Binding-Example/README.md Installs all required Python dependencies for the RAG example. Ensure you have activated your virtual environment before running this command. ```bash cd Python-Binding-Example python -m venv .venv .\.venv\Scripts\activate # windows source .venv/bin/activate # macOS pip install -r requirements.txt ``` -------------------------------- ### Run LLM Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the LLM example script. This is a basic command to start the Large Language Model functionality. ```bash python llm.py ``` -------------------------------- ### Install Dependencies for Agent-Granite Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Agent-Granite/Python-Binding-Example/README.md Installs necessary dependencies for the Agent-Granite example. Ensure you are in the example directory and have activated your virtual environment before running. ```bash # Navigate to the example directory cd Python-Binding-Example # Create a Python virtual environment python -m venv .venv # Activate the virtual environment .\.venv\Scripts\activate # windows source .venv/bin/activate # macOS # Install all required dependencies pip install gradio pip install -r requirements.txt ``` -------------------------------- ### Run Example Script Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/ag2/README.md Execute the main example script for AG2 and Nexa SDK integration. ```bash python example.py ``` -------------------------------- ### Run Nexa SDK Server Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/llama-index/README.md Start the Nexa SDK server in a separate terminal. This is a prerequisite for running the examples. ```bash # In another terminal nexa serve ``` -------------------------------- ### Set Up Python Environment with uv Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Create and activate a virtual environment using uv, install dependencies, and optionally install memory features. Also installs Playwright browsers. ```bash # Navigate to web-ui directory cd web-ui # Create virtual environment with uv uv venv --python 3.11 # Activate virtual environment source .venv/bin/activate # macOS/Linux # or .\.venv\Scripts\Activate.ps1 # Windows PowerShell # Install Python dependencies uv pip install -r requirements.txt # (Optional) Install memory features for enhanced agent learning capabilities # This adds ~110MB of ML dependencies (torch, transformers, etc.) uv pip install "browser-use[memory]" # Install Playwright browsers (recommend Chromium only) playwright install chromium --with-deps ``` -------------------------------- ### Start Web-UI Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Start the Web-UI application in a new terminal, ensuring the Python environment is activated. ```bash # Navigate to project root directory cd Nexa-Web-UI # Activate your Python environment source web-ui/.venv/bin/activate # or conda activate nexa-webui # Start the web interface python web-ui/webui.py --ip 127.0.0.1 --port 7788 ``` -------------------------------- ### Install Standard Demo App Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/android/README.md Install the pre-built standard demo application using ADB. Ensure the APK file is downloaded first. ```bash # Download: https://nexa-model-hub-bucket.s3.us-west-1.amazonaws.com/public/android-demo-release/nexaai-demo-app.apk adb install nexaai-demo-app.apk ``` -------------------------------- ### Run Diarize Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the Diarize example script. Provide the path to an audio file for speaker diarization. ```bash python diarize.py --audio path/to/audio.wav ``` -------------------------------- ### Install GPT-OSS NPU Demo App Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/android/README.md Install the pre-built demo application specifically for running the GPT-OSS model on Qualcomm NPUs using ADB. Download the APK before installation. ```bash # Download: https://nexa-model-hub-bucket.s3.us-west-1.amazonaws.com/public/nexa_sdk/huggingface-models/gpt-oss-android-demo/nexaai-gpt-oss-npu.apk adb install nexaai-gpt-oss-npu.apk ``` -------------------------------- ### Run RAG Gradio UI Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-LLM/Python-Binding-Example/README.md Launches the Gradio-based graphical user interface for the RAG application. This command starts a local web server, typically accessible at http://localhost:7860, offering a chat interface. ```bash python gradio_ui.py ``` -------------------------------- ### Run Multi-Modal Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the VLM (Vision Language Model) example script. This command initiates the multi-modal AI functionalities. ```bash python vlm.py ``` -------------------------------- ### Pull and Serve Nexa Models Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/edsl/README.md Use these commands to pull a specified model and start the Nexa serve process. Ensure nexa is installed and accessible in your PATH. ```bash nexa pull unsloth/Qwen3-4B-Instruct-2507-GGUF nexa serve ``` -------------------------------- ### Setup Virtual Environment and Activate Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/live-translate/README.md Navigate to the project directory and set up a Python virtual environment. Activate the environment using the appropriate script for your operating system. ```bash cd cookbook/PC/live-translate python -m venv .venv # Windows .venv\Scripts\activate # Linux source .venv/bin/activate ``` -------------------------------- ### Run TTS Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the TTS (Text-to-Speech) example script. Provide text to synthesize speech. ```bash python tts.py --text "Hello, world!" ``` -------------------------------- ### Set Up Python Environment with conda Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Create and activate a conda environment, install dependencies, and optionally install memory features. Also installs Playwright browsers. ```bash # Navigate to web-ui directory cd web-ui # Create conda environment conda create -n nexa-webui python=3.11 -y conda activate nexa-webui # Install Python dependencies pip install -r requirements.txt # (Optional) Install memory features for enhanced agent learning capabilities # This adds ~110MB of ML dependencies (torch, transformers, etc.) pip install "browser-use[memory]" # Install Playwright browsers (recommend Chromium only) playwright install chromium --with-deps ``` -------------------------------- ### Setup Go Environment (Windows x64) Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Enables CGO for the Go environment on Windows x64. This is a prerequisite for building the project. ```powershell go env -w CGO_ENABLED=1 ``` -------------------------------- ### Run ImageGen Examples Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the ImageGen example script for image generation. Supports text-to-image and image-to-image transformations. ```bash # Text-to-image python image_gen.py --prompt "A beautiful sunset over the ocean" ``` ```bash # Image-to-image python image_gen.py --prompt "A beautiful sunset" --init-image path/to/image.png ``` -------------------------------- ### Python SDK: Stream LLM Generation Source: https://github.com/qualcomm/nexa-sdk/blob/main/README.md Example of initializing an LLM, applying a chat template, and streaming generated tokens. Requires the nexaai package to be installed. ```python from nexaai import LLM, GenerationConfig, ModelConfig, LlmChatMessage llm = LLM.from_(model="NexaAI/Qwen3-0.6B-GGUF", config=ModelConfig()) conversation = [ LlmChatMessage(role="user", content="Hello, tell me a joke") ] prompt = llm.apply_chat_template(conversation) for token in llm.generate_stream(prompt, GenerationConfig(max_tokens=100)): print(token, end="", flush=True) ``` -------------------------------- ### Install psutil and Run Tests Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Installs the 'psutil' Python package and executes the project's tests using the provided Python script. Ensure Python is installed and accessible in your PATH. ```bash pip install psutil python tests/run.py ``` -------------------------------- ### Nexa CLI Infer and Serve Commands Source: https://context7.com/qualcomm/nexa-sdk/llms.txt Examples of using the Nexa CLI for model inference, pulling models, and starting the OpenAI-compatible server. Set the NEXA_TOKEN environment variable for NPU access on supported hardware. ```bash # Set NPU access token (Snapdragon X Elite / Windows ARM64) export NEXA_TOKEN="key/eyJ..." # LLM chat nexa infer ggml-org/Qwen3-1.7B-GGUF # Multimodal VLM (drag an image into the CLI prompt) nexa infer NexaAI/Qwen3-VL-4B-Instruct-GGUF # NPU-accelerated model (Qualcomm Snapdragon) nexa infer NexaAI/OmniNeural-4B # Pull a model to local cache from HuggingFace nexa pull NexaAI/Qwen3-4B-GGUF # Pull from a specific hub (volces | modelscope | s3 | hf) nexa pull NexaAI/Qwen3-4B-GGUF --model-hub hf # Import from local filesystem nexa pull NexaAI/Qwen3-4B-GGUF --model-hub localfs --local-path /path/to/modeldir # Start OpenAI-compatible server (default port 18181) nexa serve ``` -------------------------------- ### Install Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/ag2/README.md Install project dependencies using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install NexaAI and Gradio Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Multimodal-Qwen3VL/README.md Installs the necessary Python packages for the NexaAI VLM application. Ensure you are in the example directory and have activated your virtual environment before running these commands. ```bash cd Python-Binding-Example python -m venv .venv .\.venv\Scripts\activate source .venv/bin/activate pip install nexaai pip install gradio ``` -------------------------------- ### Install NexaAI Python SDK Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Install the NexaAI Python SDK using pip. The -v flag can be used for verbose output during installation. ```bash pip install nexaai -v ``` -------------------------------- ### Run Nexa Serve Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/ag2/README.md Start the Nexa service. Ensure you have pulled the desired model first. ```bash nexa pull NexaAI/Qwen3-4B-GGUF nexa serve ``` -------------------------------- ### Start Nexa Server Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Start the Nexa server with specified host, port, and keepalive settings. Ensure you are in the project root directory. ```bash # Navigate to project root directory cd Nexa-Web-UI nexa serve --host 127.0.0.1:8080 --keepalive 600 ``` -------------------------------- ### Install NexaSDK CLI for Linux Source: https://context7.com/qualcomm/nexa-sdk/llms.txt Download and install the NexaSDK CLI for Linux. Supports both ARM64 and x64 architectures. ```bash # ARM64 curl -LO https://github.com/NexaAI/nexa-sdk/releases/latest/download/nexa-cli_linux_arm64.sh bash nexa-cli_linux_arm64.sh # x64 curl -LO https://github.com/NexaAI/nexa-sdk/releases/latest/download/nexa-cli_linux_x86_64.sh bash nexa-cli_linux_x86_64.sh ``` -------------------------------- ### Run AG2 Example Script Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-ag2.md Execute the provided example Python script to test the AG2 and Nexa SDK integration. ```bash python cookbook/ag2/example.py ``` -------------------------------- ### Install Playwright Browsers Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Execute this command to install Playwright browsers, including their dependencies, and force a reinstallation if issues arise. This is useful when Playwright browsers fail to install correctly. ```bash playwright install chromium --with-deps --force ``` -------------------------------- ### Install AG2 with OpenAI Support Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-ag2.md Install the AG2 library with the necessary dependencies for OpenAI compatibility. ```bash pip install "ag2[openai]" ``` -------------------------------- ### Run RAG Example (CLI Version) Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-LLM/Serve-Example/README.md Execute the RAG example using the command-line interface. This provides an interactive terminal for agent interaction. ```bash # Option 1: Run the CLI version which provides an interactive terminal interface # This version allows direct interaction with the agent through command line python rag_nexa.py --data ../docs ``` -------------------------------- ### Run Models with Nexa CLI Source: https://github.com/qualcomm/nexa-sdk/blob/main/README.md Examples of how to run different types of models using the Nexa CLI. Includes chat, multimodal, and NPU-specific model inference. ```bash # Chat with Qwen3 nexa infer ggml-org/Qwen3-1.7B-GGUF ``` ```bash # Multimodal: drag images into the CLI nexa infer NexaAI/Qwen3-VL-4B-Instruct-GGUF ``` ```bash # NPU (Windows arm64 with Snapdragon X Elite) nexa infer NexaAI/OmniNeural-4B ``` -------------------------------- ### Run Reranker Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the Reranker example script. This command is used to run the document reranking functionality. ```bash python rerank.py ``` -------------------------------- ### Install nexasdk-bridge from Local Files Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Links the nexasdk-bridge library from local files using the make command. This is an alternative method for installing the bridge library. ```bash make link ``` -------------------------------- ### Run Embedder Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the Embedder example script. This command is used to run the text vectorization and similarity computation functionality. ```bash python embedder.py ``` -------------------------------- ### Build Project Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Compiles the project after the prerequisites and bridge library have been installed. This command initiates the build process. ```bash make build ``` -------------------------------- ### Start Clawdbot Gateway Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/clawd/README.md Initiate the Clawdbot gateway service. This command should be run after configuring Clawdbot. ```bash clawdbot gateway ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/solutions/embedneural/README.md Installs the necessary Python libraries for running the EmbedNeural demo, including Gradio for the UI and other project requirements. ```bash pip install gradio pip install -r requirements.txt ``` -------------------------------- ### Install nexasdk-bridge from S3 Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Downloads the nexasdk-bridge library from an S3 bucket using the make command. This is one of the methods to install the bridge library. ```bash make download ``` -------------------------------- ### Start Nexa Serve Locally Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/docker/RAG-VLM/README.md Starts the Nexa serve process locally, making the AutoNeural model accessible via an API endpoint. ```bash nexa serve --host 127.0.0.1:18181 ``` -------------------------------- ### Run the Live Translator Application Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/live-translate/README.md Start the live translation application by running the main Python script. Access the web UI by navigating to the provided URL in your browser. ```bash python app.py ``` -------------------------------- ### Install Nexa AI Python SDK Source: https://github.com/qualcomm/nexa-sdk/blob/main/README.md Install the Nexa AI Python SDK using pip. This is the first step to using the SDK in your Python projects. ```bash pip install nexaai ``` -------------------------------- ### Configure Clawdbot with Nexa SDK Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/clawd/README.md Copy the example Clawdbot configuration file to set up Clawdbot to use the Nexa SDK's OpenAI-compatible API endpoint. ```bash cp clawdbot.example.json ~/.clawdbot/clawdbot.json ``` -------------------------------- ### Start Live Translation Recording Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/live-translate/index.html Initiates microphone access, sets up the audio context, and starts recording audio for live translation. It handles both AudioWorklet and ScriptProcessor implementations. ```javascript async function startRecording() { try { state.mediaStream = await navigator.mediaDevices.getUserMedia({ audio: { autoGainControl: true, sampleRate: 16000, }, }); logger.info('✓ Microphone access granted'); if (!state.socket || !state.socket.connected) { logger.error('Socket not connected!'); updateStatus('originalStatus', 'Socket not connected. Reload page.'); return; } logger.info(`Emitting start_stream with target_lang: ${state.targetLanguage}`); state.socket.emit('start_stream', { target_lang: state.targetLanguage }); await new Promise(resolve => setTimeout(resolve, 300)); state.audioContext = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 }); state.sourceNode = state.audioContext.createMediaStreamSource(state.mediaStream); const resampleTo16k = (input, inputSampleRate) => { if (inputSampleRate === 16000) return input; const ratio = inputSampleRate / 16000; const newLength = Math.floor(input.length / ratio); const output = new Float32Array(newLength); for (let i = 0; i < newLength; i++) { const srcPos = i * ratio; const srcIdx = Math.floor(srcPos); const srcFrac = srcPos - srcIdx; const s0 = input[srcIdx] || 0; const s1 = input[srcIdx + 1] || 0; output[i] = s0 + (s1 - s0) * srcFrac; } return output; }; const sendPcm16 = (float32Samples) => { if (!state.socket || !state.socket.connected) return; const pcm16k = resampleTo16k(float32Samples, state.audioContext.sampleRate); const int16 = new Int16Array(pcm16k.length); for (let i = 0; i < pcm16k.length; i++) { const s = Math.max(-1, Math.min(1, pcm16k[i])); int16[i] = s < 0 ? s * 0x8000 : s * 0x7FFF; } const buf = int16.buffer; logger.debug(`Emitting audio_chunk PCM: ${buf.byteLength} bytes (samples: ${int16.length})`); state.socket.emit('audio_chunk', buf); }; if (state.audioContext.audioWorklet) { const workletCode = ` class PCMProcessor extends AudioWorkletProcessor { constructor() { super(); this.buffer = []; this.bufferSize = 1024; } process(inputs) { const input = inputs[0]; if (!input || input.length === 0) return true; const channel = input[0]; if (!channel || channel.length === 0) return true; this.buffer.push(...channel); if (this.buffer.length >= this.bufferSize) { const chunk = new Float32Array(this.buffer.slice(0, this.bufferSize)); this.port.postMessage(chunk); this.buffer = this.buffer.slice(this.bufferSize); } return true; } } registerProcessor('pcm-processor', PCMProcessor); `; const blob = new Blob([workletCode], { type: 'application/javascript' }); const url = URL.createObjectURL(blob); await state.audioContext.audioWorklet.addModule(url); state.workletNode = new AudioWorkletNode(state.audioContext, 'pcm-processor'); state.workletNode.port.onmessage = (event) => { const samples = event.data; if (samples && samples.length) { sendPcm16(samples); } }; state.sourceNode.connect(state.workletNode); state.workletNode.connect(state.audioContext.destination); logger.info('AudioContext + AudioWorklet started (PCM 16k, 1024-sample chunks)'); } else { const bufferSize = 4096; state.scriptProcessor = state.audioContext.createScriptProcessor(bufferSize, 1, 1); state.scriptProcessor.onaudioprocess = (event) => { const input = event.inputBuffer.getChannelData(0); sendPcm16(input); }; state.sourceNode.connect(state.scriptProcessor); state.scriptProcessor.connect(state.audioContext.destination); logger.info('AudioContext + ScriptProcessor started (M 16k)'); } state.isRecording = true; elements.startBtn.style.display = 'none'; elements.stopBtn.style.display = 'flex'; elements.originalText.textContent = ''; elements.translatedText.textContent = ''; updateStatus('originalStatus', 'Recording... Listening for speech'); updateStatus('translatedStatus', ''); logger.info('✓ Recording started'); } catch (error) { logger.error('Microphone access error:', error); updateStatus('originalStatus', `Error: ${error.message}`); } } ``` -------------------------------- ### Run Computer Vision OCR Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/README.md Execute the Computer Vision OCR (Optical Character Recognition) example script. This command is used for text recognition in images. ```bash python cv_ocr.py ``` -------------------------------- ### Start Nexa Server Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Agent-Granite/Serve-Example/README.md Initiate the Nexa server in a dedicated terminal. This server is required for the agent to function. ```bash # Start Nexa server nexa serve ``` -------------------------------- ### Setup Go Environment (Windows arm64) Source: https://github.com/qualcomm/nexa-sdk/blob/main/runner/README.md Configures the Go environment for Windows arm64, enabling CGO and setting the C and C++ compilers to clang. This is necessary for building the project on this architecture. ```powershell go env -w CGO_ENABLED=1 go env -w CC=clang.exe go env -w CXX=clang++.exe ``` -------------------------------- ### VLM Inference Example with NexaAI Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/notebook/macos.ipynb Demonstrates VLM inference using the NexaAI SDK. It covers model loading, multimodal conversation setup, prompt formatting, and streaming response generation. Ensure the image path is valid for full multimodal functionality. ```python import os import io from nexaai import ( GenerationConfig, ModelConfig, VlmChatMessage, VlmContent, ) from nexaai.vlm import VLM def vlm_example(): """VLM Inference example""" print("=== VLM Inference Example ===") # Model configuration # Use huggingface repo ID model_name = "NexaAI/gemma-3n-E2B-4bit-MLX" plugin_id = "mlx" max_tokens = 100 system_message = "You are a helpful assistant that can understand images and text." image_path = '/your/image/path' # Replace with actual image path if available print(f"Loading model: {model_name}") print(f"Using plugin: {plugin_id}") # Check for image existence if not (image_path and os.path.exists(image_path)): print( f"\033[93mWARNING: The specified image_path ('{image_path}') does not exist or was not provided. Multimodal prompts will not include image input.\033[0m") # Create model instance config = ModelConfig() vlm = VLM.from_(model=model_name, config=config, plugin_id=plugin_id) # Create conversation history conversation = [ VlmChatMessage( role="system", contents=[VlmContent(type="text", text=system_message)] ) ] # Example multimodal conversations test_cases = [ { "text": "What do you see in this image?", "image_path": image_path } ] for i, case in enumerate(test_cases, 1): print(f"\n--- Multimodal Conversation {i} ---") print(f"User: {case['text']}") # Build message content contents = [] if case['text']: contents.append(VlmContent(type="text", text=case['text'])) # Add image content if available if case['image_path'] and os.path.exists(case['image_path']): contents.append(VlmContent(type="image", text=case['image_path'])) print(f"Including image: {case['image_path']}") # Add user message conversation.append(VlmChatMessage(role="user", contents=contents)) # Apply chat template formatted_prompt = vlm.apply_chat_template(conversation) # Generate response print("Assistant: ", end="", flush=True) response_buffer = io.StringIO() # Prepare image and audio paths image_paths = [case['image_path']] if case['image_path'] and os.path.exists(case['image_path']) else None audio_paths = None gen = vlm.generate_stream( formatted_prompt, config=GenerationConfig( max_tokens=max_tokens, image_paths=image_paths, audio_paths=audio_paths ) ) result = None try: while True: token = next(gen) print(token, end="", flush=True) response_buffer.write(token) except StopIteration as e: result = e.value # Get profiling data if result and hasattr(result, "profile_data") and result.profile_data: print(f"\n{result.profile_data}") # Add assistant response to conversation history conversation.append( VlmChatMessage( role="assistant", contents=[ VlmContent(type="text", text=response_buffer.getvalue()) ] ) ) print("\n" + "=" * 50) vlm_example() ``` -------------------------------- ### Install LangChain Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-langchain.md Install the necessary LangChain packages for OpenAI compatibility and general use. Ensure Python 3.10+ is installed. ```bash pip install langchain langchain-openai openai ``` -------------------------------- ### Build Docker Image for AutoNeural Video Demo Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/docker/RAG-VLM/README.md Builds the Docker image for the AutoNeural video demo. Ensure you are in the correct directory. ```bash cd cookbook/docker/RAG-VLM docker build -t autoneural-video-demo . ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/Web-Agent-Qwen3VL/README.md Clone the Nexa-Web-UI repository and navigate into the project directory. ```bash git clone https://github.com/mtilyxuegao/Nexa-Web-UI.git cd Nexa-Web-UI ``` -------------------------------- ### Android SDK: Initialize and Run VLM Model Source: https://github.com/qualcomm/nexa-sdk/blob/main/README.md Initialize the Nexa SDK and load a VLM model for inference. This example demonstrates setting up the VLM wrapper and streaming generation results. ```kotlin // Initialize SDK NexaSdk.getInstance().init(this) // Load and run model VlmWrapper.builder() .vlmCreateInput(VlmCreateInput( model_name = "omni-neural", model_path = "/data/data/your.app/files/models/OmniNeural-4B/files-1-1.nexa", plugin_id = "npu", config = ModelConfig() )) .build() .onSuccess { vlm -> vlm.generateStreamFlow("Hello!", GenerationConfig()).collect { print(it) } } ``` -------------------------------- ### Install CrewAI Dependency Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-crewai.md Install the CrewAI library using pip. This is a prerequisite for using CrewAI in your Python projects. ```bash pip install crewai ``` -------------------------------- ### Run Docker Container for AutoNeural Demo Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/docker/RAG-VLM/README.md Runs the AutoNeural video demo Docker container. It maps ports, sets the Nexa token, and mounts a cache directory. ```bash docker run -d \ --name autoneural-demo \ --privileged \ -p 18182:18181 \ -p 7860:7860 \ -e NEXA_TOKEN \ -v ~/.cache/nexa.ai:/root/.cache/nexa.ai \ autoneural-video-demo ``` -------------------------------- ### Start Web UI for NexaAI VLM Demo Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/function-calling/README.md Launches the web-based user interface for the NexaAI VLM demo. This provides a graphical way to interact with the model and its Google Calendar integration. ```powershell python .\app\flask_ui.py ``` -------------------------------- ### Run NexaAI VLM Demo (Audio with Text) Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/function-calling/README.md Executes the NexaAI VLM demo with audio and text input. This enables functionalities like transcribing audio and adding calendar events based on the content. ```bash python main.py --audio audio.mp3 --text "transcribe and add to calendar" ``` -------------------------------- ### Start Nexa Server Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-VLM/README.md Run the Nexa server in a separate terminal. This command starts the necessary backend services for the RAG system to function. ```bash nexa serve ``` -------------------------------- ### Run CrewAI Example Script Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-crewai.md Execute the Python script that contains the CrewAI integration example. This script will initiate the AI agent workflow. ```bash python cookbook/crewai/example.py ``` -------------------------------- ### Install LlamaIndex Packages Source: https://github.com/qualcomm/nexa-sdk/blob/main/docs/integrate-llamaindex.md Install the necessary LlamaIndex packages for core functionality and OpenAI-like LLM integration. This is a prerequisite for using the Nexa SDK with LlamaIndex. ```bash pip install llama-index-core llama-index-llms-openai-like ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-VLM/README.md Install the required Python packages, including Gradio for the UI and other dependencies listed in 'requirements.txt'. A new conda environment is recommended for isolation. ```bash # Create a new conda environment (optional) conda create -n rag-nexa python=3.10 -y conda activate rag-nexa # install python dependencies pip install gradio pip install -r requirements.txt ``` -------------------------------- ### Download Models for Snapdragon NPU (Windows ARM64) Source: https://github.com/qualcomm/nexa-sdk/blob/main/cookbook/PC/RAG-LLM/Serve-Example/README.md Use these commands to download models optimized for Qualcomm NPU on Windows ARM64 systems. ```bash nexa pull NexaAI/embeddinggemma-300m-npu nexa pull NexaAI/jina-v2-rerank-npu nexa pull NexaAI/Llama3.2-3B-NPU-Turbo ``` -------------------------------- ### VLM Inference Example Source: https://github.com/qualcomm/nexa-sdk/blob/main/bindings/python/notebook/windows(x64).ipynb This example demonstrates VLM inference using the OmniNeural-4B model. It includes model and plugin configuration, handling multimodal conversations with images and text, and streaming the generated response. A warning is printed if the specified image path does not exist. ```python import os import io from nexaai import ( GenerationConfig, ModelConfig, VlmChatMessage, VlmContent, ) from nexaai.vlm import VLM def vlm_example(): """VLM Inference example""" print("=== VLM Inference Example ===") # Model configuration model_name = "ggml-org/gemma-3-4b-it-GGUF/gemma-3-4b-it-Q4_K_M.gguf" mmproj_path = "ggml-org/gemma-3-4b-it-GGUF/mmproj-model-f16.gguf" plugin_id = "cpu_gpu" max_tokens = 100 system_message = "You are a helpful assistant that can understand images and text." image_path = '/your/image/path' # Replace with actual image path if available print(f"Loading model: {model_name}") print(f"Using plugin: {plugin_id}") # Check for image existence if not (image_path and os.path.exists(image_path)): print( f"\033[93mWARNING: The specified image_path ('{image_path}') does not exist or was not provided. Multimodal prompts will not include image input.\033[0m") # Create model instance config = ModelConfig() vlm = VLM.from_(model=model_name, mmproj_path=mmproj_path, config=config, plugin_id=plugin_id) # Create conversation history conversation = [ VlmChatMessage( role="system", contents=[VlmContent(type="text", text=system_message)] ) ] # Example multimodal conversations test_cases = [ { "text": "What do you see in this image?", "image_path": image_path } ] for i, case in enumerate(test_cases, 1): print(f"\n--- Multimodal Conversation {i} ---") print(f"User: {case['text']}") # Build message content contents = [] if case['text']: contents.append(VlmContent(type="text", text=case['text'])) # Add image content if available if case['image_path'] and os.path.exists(case['image_path']): contents.append(VlmContent(type="image", text=case['image_path'])) print(f"Including image: {case['image_path']}") # Add user message conversation.append(VlmChatMessage(role="user", contents=contents)) # Apply chat template formatted_prompt = vlm.apply_chat_template(conversation) # Generate response print("Assistant: ", end="", flush=True) response_buffer = io.StringIO() # Prepare image and audio paths image_paths = [case['image_path']] if case['image_path'] and os.path.exists(case['image_path']) else None audio_paths = None gen = vlm.generate_stream( formatted_prompt, config=GenerationConfig( max_tokens=max_tokens, image_paths=image_paths, audio_paths=audio_paths ) ) result = None try: while True: token = next(gen) print(token, end="", flush=True) response_buffer.write(token) except StopIteration as e: result = e.value # Get profiling data if result and hasattr(result, "profile_data") and result.profile_data: print(f"\n{result.profile_data}") # Add assistant response to conversation history conversation.append( VlmChatMessage( role="assistant", contents=[ VlmContent(type="text", text=response_buffer.getvalue()) ] ) ) print("\n" + "=" * 50) vlm_example() ```