### Install Cactus CLI from Source (macOS) Source: https://cactuscompute.com/docs/v1.7/cli Installs the Cactus CLI by cloning the repository and running the setup script. This method is suitable for macOS users who want to build from source. ```bash git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setup ``` -------------------------------- ### Install Cactus CLI with Homebrew Source: https://cactuscompute.com/docs/v1.7/cli Installs the Cactus CLI using the Homebrew package manager on macOS. This is the recommended and simplest way to get started. ```bash brew install cactus-compute/cactus/cactus ``` -------------------------------- ### Install Cactus CLI from Source (Linux) Source: https://cactuscompute.com/docs/v1.7/cli Installs the Cactus CLI from source on Linux systems. This requires installing prerequisite packages like python3, pip, cmake, and build essentials. ```bash sudo apt-get install python3 python3-venv python3-pip cmake build-essential libcurl4-openssl-dev git clone https://github.com/cactus-compute/cactus && cd cactus && source ./setup ``` -------------------------------- ### Run a Local AI Model Source: https://cactuscompute.com/docs/v1.7/cli Starts an interactive playground to run a specified AI model locally. The CLI automatically downloads the model if it's not already present. ```bash # Download and run LiquidAI's LFM2-350M cactus run LiquidAI/LFM2-350M # Or use a specific model cactus run google/gemma-3-270m-it ``` -------------------------------- ### Include Cactus Header in C++ Source: https://cactuscompute.com/docs/v1.7/cpp This snippet shows how to include the main Cactus header file in your C++ project to start using the SDK. Ensure the Cactus library is correctly linked during the build process. ```cpp #include ``` -------------------------------- ### Download AI Models Source: https://cactuscompute.com/docs/v1.7/cli Downloads AI model weights for offline use. Models are stored in the `./weights/` directory. Supports specifying model precision. ```bash # Download a model for offline use cactus download LiquidAI/LFM2.5-1.2B-Instruct # Download with specific precision cactus download LiquidAI/LFM2.5-1.2B-Instruct --precision int8 # Models are stored in ./weights/ ``` -------------------------------- ### Basic Text Completion with Cactus C++ SDK Source: https://cactuscompute.com/docs/v1.7/cpp Demonstrates a basic text completion request using the Cactus C++ SDK. It initializes a model, prepares messages, and generates a response. Optional generation settings can be provided. ```cpp #include // Initialize model cactus_model_t model = cactus_init( "path/to/weight/folder", "path/to/rag/documents", // optional: for auto-RAG ); // Prepare messages const char* messages = R"([\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "What is the capital of France?"}\n])"; // Optional: generation settings const char* options = R"({\n "max_tokens": 50,\n "stop_sequences": ["<|im_end|>"]\n})"; // Generate response char response[4096]; int result = cactus_complete( model, // model handle messages, // chat messages (JSON array) response, // output buffer sizeof(response),// buffer size options, // generation options (or nullptr) nullptr, // tools for function calling (or nullptr) nullptr, // streaming callback (or nullptr) nullptr // user data for callback ); ``` -------------------------------- ### Building Computation Graph with Cactus Graph API (C++) Source: https://cactuscompute.com/docs/v1.7/cpp Demonstrates how to define and execute a custom computation graph using the Cactus Graph API in C++. This allows for the implementation of custom models with optimized performance. ```cpp #include CactusGraph graph; // Define inputs auto a = graph.input({2, 3}, Precision::FP16); auto b = graph.input({3, 4}, Precision::INT8); // Build computation graph auto x1 = graph.matmul(a, b, false); auto x2 = graph.transpose(x1); auto result = graph.matmul(b, x2, true); // Set input data float a_data[6] = {1.1f, 2.3f, 3.4f, 4.2f, 5.7f, 6.8f}; float b_data[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; graph.set_input(a, a_data, Precision::FP16); graph.set_input(b, b_data, Precision::INT8); // Execute graph.execute(); // Get output void* output_data = graph.get_output(result); // Clean up graph.hard_reset(); ``` -------------------------------- ### Streaming Responses with Cactus C++ SDK Source: https://cactuscompute.com/docs/v1.7/cpp Shows how to implement streaming responses using a callback function with the Cactus C++ SDK. The `token_callback` function is invoked for each generated token, allowing real-time output. ```cpp void token_callback(const char* token, int token_id, void* user_data) { printf("%s", token); fflush(stdout); } cactus_complete( model, messages, response, sizeof(response), nullptr, nullptr, token_callback, // streaming callback nullptr // user data ); ``` -------------------------------- ### Function Calling with Cactus C++ SDK Source: https://cactuscompute.com/docs/v1.7/cpp Illustrates how to enable function calling with the Cactus C++ SDK. By providing a 'tools' JSON array, the SDK can identify and format function calls based on user input. ```cpp const char* tools = R"([\n {\n "name": "get_weather",\n "description": "Get current weather for a location",\n "parameters": {\n "type": "object",\n "properties": {\n "location": {"type": "string"}\n },\n "required": ["location"]\n }\n }\n])"; char response[4096]; cactus_complete( model, messages, response, sizeof(response), nullptr, // use default options tools, // pass tools JSON nullptr, nullptr ); ``` -------------------------------- ### Configure Cloud Authentication Source: https://cactuscompute.com/docs/v1.7/cli Sets up cloud API credentials for Cactus, enabling hybrid cloud routing. This allows the CLI to automatically switch to cloud-based models when local performance is insufficient. ```bash cactus auth ``` -------------------------------- ### Perform Audio Transcription Source: https://cactuscompute.com/docs/v1.7/cli Transcribes audio from a file or live microphone input using a specified model. Supports cloud fallback for improved accuracy on noisy audio. ```bash # Transcribe an audio file cactus transcribe openai/whisper-small --file recording.mp3 # Live microphone transcription cactus transcribe UsefulSensors/moonshine-base # With cloud fallback for noisy audio cactus transcribe openai/whisper-small --file recording.mp3 --cloud-key YOUR_API_KEY ``` -------------------------------- ### Test AI Models on Different Platforms Source: https://cactuscompute.com/docs/v1.7/cli Runs tests for AI models on specified platforms like iOS or Android. Allows for targeting specific models and precision levels during testing. ```bash # Test on iOS simulator cactus test --ios --model LiquidAI/LFM2-350M # Test on Android with specific precision cactus test --android --model google/gemma-3-270m-it --precision int8 ``` -------------------------------- ### Convert Model with LoRA Adapter Source: https://cactuscompute.com/docs/v1.7/cli Converts a model to the `.cact` format and supports merging LoRA adapters during the conversion process. This is useful for applying fine-tuning to existing models. ```bash # Convert a model with LoRA adapter cactus convert LiquidAI/LFM2-350M ./output --lora path/to/lora ``` -------------------------------- ### Handle Cactus Compute API Errors (C++) Source: https://cactuscompute.com/docs/v1.7/cpp This snippet demonstrates how to check for and handle errors returned by the Cactus Compute API. It assumes the API returns an integer status code, where non-zero indicates an error. Error details can be parsed from a JSON response. ```c++ int result = cactus_complete(...); if (result != 0) { // Parse error from response JSON // error field will contain specific error message } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.