From ed39e16ec46a93fe77fd5201561ca965bea7d08d Mon Sep 17 00:00:00 2001 From: James Date: Fri, 8 Nov 2024 11:38:11 +0700 Subject: [PATCH 1/5] docs: add cors docs --- docs/docs/configurations/cors.mdx | 176 +++++++++++++++++++++++++++++ docs/docs/configurations/index.mdx | 12 ++ docs/sidebars.ts | 67 ++++++++--- 3 files changed, 239 insertions(+), 16 deletions(-) create mode 100644 docs/docs/configurations/cors.mdx create mode 100644 docs/docs/configurations/index.mdx diff --git a/docs/docs/configurations/cors.mdx b/docs/docs/configurations/cors.mdx new file mode 100644 index 000000000..2ea6907de --- /dev/null +++ b/docs/docs/configurations/cors.mdx @@ -0,0 +1,176 @@ +--- +title: CORS +description: Setting up CORS +slug: "cors" +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +:::warning +🚧 Cortex.cpp is currently under development. Our documentation outlines the intended behavior of Cortex, which may not yet be fully implemented in the codebase. +::: + +# CORS Configuration Guide + +This document describes how to configure Cross-Origin Resource Sharing (CORS) settings for the API server using both CLI commands and HTTP API endpoints. + +## Command Line Interface (CLI) + +### Basic Usage + +```bash +cortex config [OPTIONS] [COMMAND] +``` + +### Commands + +- `status`: Display all current configurations + + ```bash + cortex config status + ``` + + Example Output: + + ```bash + +-----------------+-------------------+ + | Config name | Value | + +-----------------+-------------------+ + | allowed_origins | http://localhost | + +-----------------+-------------------+ + | allowed_origins | https://cortex.so | + +-----------------+-------------------+ + | cors | true | + +-----------------+-------------------+ + ``` + +### Options + +| Option | Description | Example | +| ----------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------- | +| `-h, --help` | Print help message and exit | +| `--cors [on/off]` | Toggle CORS functionality | cortex config --cors on | +| `--allowed_origins [origins]` | Set allowed origins for CORS, comma separated without spaces | `cortex config --allowed_origins http://localhost,https://cortex.so` | + +### Examples + +1. Toggle CORS on: + + ```bash + cortex config --cors on + ``` + +2. Toggle CORS off: + + ```bash + cortex config --cors off + ``` + +3. Set allowed origins: + + ```bash + cortex config --allowed_origins http://localhost,https://cortex.so + ``` + +4. View current configuration: + ```bash + cortex config status + ``` + +## CORS API Configuration + +This document describes the REST API endpoints available for managing CORS configurations. + +### Endpoints + +#### Get Current Configuration + +```http +GET /v1/configs +``` + +Retrieves the current CORS configuration settings. + +##### Response + +```json +{ + "allowed_origins": ["http://localhost:39281"], + "cors": true +} +``` + +#### Update Configuration + +```http +PATCH /v1/configs +``` + +Updates CORS configuration settings. + +##### Request Headers + +``` +Content-Type: application/json +``` + +##### Request Body + +```json +{ + "cors": true, + "allowed_origins": ["http://localhost:39281"] +} +``` + +##### Parameters + +| Field | Type | Description | +| ----------------- | -------- | ---------------------------- | +| `cors` | boolean | Enable or disable CORS | +| `allowed_origins` | string[] | Array of allowed origin URLs | + +##### Response + +```json +{ + "config": { + "allowed_origins": ["http://localhost:39281"], + "cors": true + }, + "message": "Configuration updated successfully" +} +``` + +### Example cURL Commands + +#### Get Configuration + +```bash +curl --location 'http://127.0.0.1:39281/v1/configs' +``` + +#### Update Configuration + +```bash +curl --location --request PATCH 'http://127.0.0.1:39281/v1/configs' \ +--header 'Content-Type: application/json' \ +--data '{ + "cors": true, + "allowed_origins": [ + "http://localhost:39281" + ] +}' +``` + +## Notes + +- Origins for CORS should be provided as comma-separated values without spaces +- The `--allowed_origins` option only takes effect when CORS is enabled + +## Best Practices + +1. Always verify CORS status after toggling +2. Double-check allowed origins to prevent security issues +3. Use the `status` command to confirm changes have been applied correctly diff --git a/docs/docs/configurations/index.mdx b/docs/docs/configurations/index.mdx new file mode 100644 index 000000000..38e7d8e92 --- /dev/null +++ b/docs/docs/configurations/index.mdx @@ -0,0 +1,12 @@ +--- +slug: /configurations +title: Cortex configurations +--- + +# Cortex Configurations + +Welcome to the Cortex configurations documentation. Here you will find detailed guides and references for configuring various aspects of Cortex, including: + +- **CORS**: Learn how to set up Cross-Origin Resource Sharing. + +Use the sidebar to navigate through the different configuration topics. diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 205d2a205..7c59ad254 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -36,7 +36,7 @@ const sidebars: SidebarsConfig = { label: "Installation", link: { type: "doc", - id: "installation" + id: "installation", }, collapsed: true, items: [ @@ -74,11 +74,28 @@ const sidebars: SidebarsConfig = { }, collapsed: true, items: [ - { type: "doc", id: "architecture/data-folder", label: "Cortex Data Folder" }, + { + type: "doc", + id: "architecture/data-folder", + label: "Cortex Data Folder", + }, { type: "doc", id: "architecture/cortex-db", label: "cortex.db" }, { type: "doc", id: "architecture/cortexrc", label: ".cortexrc" }, { type: "doc", id: "architecture/updater", label: "Updater" }, - ] + ], + }, + { + type: "category", + label: "Configurations", + link: { type: "doc", id: "configurations/index" }, + collapsed: true, + items: [ + { + type: "doc", + id: "configurations/cors", + label: "CORS", + }, + ], }, { type: "html", @@ -99,11 +116,19 @@ const sidebars: SidebarsConfig = { { type: "category", label: "Running Models", - link: { type: "doc", id: "capabilities/models/index"}, + link: { type: "doc", id: "capabilities/models/index" }, collapsed: true, items: [ - { type: "doc", id: "capabilities/models/model-yaml", label: "model.yaml" }, - { type: "doc", id: "capabilities/models/presets", label: "Model Presets" }, + { + type: "doc", + id: "capabilities/models/model-yaml", + label: "model.yaml", + }, + { + type: "doc", + id: "capabilities/models/presets", + label: "Model Presets", + }, ], }, { @@ -115,8 +140,11 @@ const sidebars: SidebarsConfig = { { type: "doc", id: "engines/llamacpp", label: "llama.cpp" }, // { type: "doc", id: "engines/tensorrt-llm", label: "TensorRT-LLM" }, // { type: "doc", id: "engines/onnx", label: "ONNX" }, - { type: "doc", id: "engines/engine-extension", label: "Building Engine Extensions" }, - + { + type: "doc", + id: "engines/engine-extension", + label: "Building Engine Extensions", + }, ], }, { @@ -124,10 +152,13 @@ const sidebars: SidebarsConfig = { label: "Hardware Awareness", link: { type: "doc", id: "capabilities/hardware/index" }, collapsed: true, - items: [ - ], + items: [], + }, + { + type: "doc", + id: "capabilities/text-generation", + label: "Text Generation", }, - { type: "doc", id: "capabilities/text-generation", label: "Text Generation" }, // { type: "doc", id: "capabilities/image-generation", label: "Image Generation" }, // { type: "doc", id: "capabilities/vision", label: "Vision" }, // { type: "doc", id: "capabilities/audio-generation", label: "Audio Generation" }, @@ -141,14 +172,18 @@ const sidebars: SidebarsConfig = { value: "GUIDES", className: "sidebar-divider", }, - { type: "doc", id: "guides/function-calling", label: "Function Calling"}, - { type: "doc", id: "guides/structured-outputs", label: "Structured Outputs"}, + { type: "doc", id: "guides/function-calling", label: "Function Calling" }, + { + type: "doc", + id: "guides/structured-outputs", + label: "Structured Outputs", + }, { type: "html", value: "ASSISTANTS", className: "sidebar-divider", }, - { type: "doc", id: "assistants/index", label: "Assistants"}, + { type: "doc", id: "assistants/index", label: "Assistants" }, { type: "category", label: "Tools", @@ -172,9 +207,9 @@ const sidebars: SidebarsConfig = { { type: "doc", id: "cli/models/index", label: "cortex models" }, { type: "doc", id: "cli/engines/index", label: "cortex engines" }, { type: "doc", id: "cli/ps", label: "cortex ps" }, - { type: "doc", id: "cli/update", label: "cortex update" }, + { type: "doc", id: "cli/update", label: "cortex update" }, { type: "doc", id: "cli/stop", label: "cortex stop" }, - ] + ], }; export default sidebars; From 7af3394c298efbb5b021f1e47a7776775270dc87 Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 13 Nov 2024 21:34:51 +0700 Subject: [PATCH 2/5] feat: install script for linux --- engine/templates/linux/install.sh | 230 ++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 engine/templates/linux/install.sh diff --git a/engine/templates/linux/install.sh b/engine/templates/linux/install.sh new file mode 100644 index 000000000..7cf72a6cd --- /dev/null +++ b/engine/templates/linux/install.sh @@ -0,0 +1,230 @@ +#!/bin/bash -e + +# Check for root privileges +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root. Please run again with sudo." + exit 1 +fi + +# Check and suggest installing jq and tar if not present +check_install_jq_tar() { + RED='\033[0;31m' + GREEN='\033[0;32m' + NC='\033[0m' # No Color + + if ! command -v jq &> /dev/null; then + echo -e "${RED}jq could not be found ...${NC}" + echo -e "${GREEN}Please install jq then rerun this script${NC}" + exit 1 + fi + + if ! command -v tar &> /dev/null; then + echo -e "${RED}tar could not be found ...${NC}" + echo -e "${GREEN}Please install tar then rerun this script${NC}" + exit 1 + fi +} + +# Function to fetch the latest version based on channel +get_latest_version() { + local channel=$1 + local tag_name + case $channel in + stable) + tag_name=$(curl -s "https://api.github.com/repos/janhq/cortex.cpp/releases/latest" | grep -oP '"tag_name": "\K(.*)(?=")') + ;; + beta) + tag_name=$(curl -s "https://api.github.com/repos/janhq/cortex.cpp/releases" | jq -r '.[] | select(.prerelease) | .tag_name' | head -n 1) + ;; + nightly) + tag_name=$(curl -s "https://delta.jan.ai/cortex/latest/version.json" | jq -r '.tag_name') + ;; + *) + echo "Invalid channel specified." + exit 1 + ;; + esac + echo "${tag_name#v}" +} + +# Determine the home directory based on the user +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} +if [ "$USER_TO_RUN_AS" = "root" ]; then + USER_HOME="/root" +else + USER_HOME="/home/$USER_TO_RUN_AS" +fi + +# Default values +CHANNEL="stable" +VERSION="" +IS_UPDATE="false" + +# Function to parse command-line arguments +parse_args() { + while [[ "$#" -gt 0 ]]; do + case $1 in + --channel) + CHANNEL="$2" + shift 2 + ;; + --version) + VERSION="$2" + shift 2 + ;; + --is_update) + IS_UPDATE="true" + shift 1 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac + done +} + +# Call parse_args function to handle options +parse_args "$@" + +# Check if VERSION is empty and fetch latest if necessary +if [ -z "$VERSION" ]; then + VERSION=$(get_latest_version $CHANNEL) +fi + +# Set paths based on channel +case $CHANNEL in + stable) + CLI_BINARY_NAME="cortex" + SERVER_BINARY_NAME="cortex-server" + DATA_DIR="$USER_HOME/cortexcpp" + UNINSTALL_SCRIPT="/usr/bin/cortex-uninstall.sh" + UPDATER_SCRIPT="/usr/bin/cortex-updater.sh" + CONFIGURATION_FILE="$USER_HOME/.cortexrc" + ;; + beta) + CLI_BINARY_NAME="cortex-beta" + SERVER_BINARY_NAME="cortex-server-beta" + DATA_DIR="$USER_HOME/cortexcpp-beta" + UNINSTALL_SCRIPT="/usr/bin/cortex-beta-uninstall.sh" + UPDATER_SCRIPT="/usr/bin/cortex-beta-updater.sh" + CONFIGURATION_FILE="$USER_HOME/.cortexrc-beta" + ;; + nightly) + CLI_BINARY_NAME="cortex-nightly" + SERVER_BINARY_NAME="cortex-server-nightly" + DATA_DIR="$USER_HOME/cortexcpp-nightly" + UNINSTALL_SCRIPT="/usr/bin/cortex-nightly-uninstall.sh" + UPDATER_SCRIPT="/usr/bin/cortex-nightly-updater.sh" + CONFIGURATION_FILE="$USER_HOME/.cortexrc-nightly" + ;; + *) + echo "Invalid channel specified." + exit 1 + ;; +esac + +INSTALL_DIR="/usr/bin" + +# Function to download and extract cortex +install_cortex() { + local channel=$1 + local version=$2 + local url="" + + case $channel in + stable) + url="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + ;; + beta) + url="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + ;; + nightly) + url="https://delta.jan.ai/cortex/v${version}/linux-amd64/cortex-nightly.tar.gz" + ;; + esac + echo "Downloading cortex $channel version $version from $url" + curl -L $url -o /tmp/cortex.tar.gz + tar -xzvf /tmp/cortex.tar.gz -C /tmp + chmod +x /tmp/cortex/* + cp /tmp/cortex/* /usr/bin/ + # Check is update or not + if [ "$IS_UPDATE" = "false" ]; then + su -c "$INSTALL_DIR/$CLI_BINARY_NAME engines install llama-cpp" $USER_TO_RUN_AS + su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS + fi +} + +# Function to create uninstall script +create_uninstall_script() { + cat << EOF > $UNINSTALL_SCRIPT +#!/bin/bash +# Check for root privileges +if [ "\$(id -u)" != "0" ]; then + echo "This script must be run as root. Please run again with sudo." + exit 1 +fi + +echo "Stopping cortex..." +su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS +rm -rf $INSTALL_DIR/$CLI_BINARY_NAME +rm -rf $INSTALL_DIR/$SERVER_BINARY_NAME +rm -f $UNINSTALL_SCRIPT +rm -f $UPDATER_SCRIPT + +echo "Do you want to delete the ~/$DATA_DIR data folder and file ~/$CONFIGURATION_FILE? (yes/no) [default: no]" +read -r answer +while true; do + case "\$answer" in + [yY][eE][sS]|[yY]) + echo "Deleting cortex data folders..." + if [ -d "$DATA_DIR" ]; then + echo "Removing $DATA_DIR" + rm -rf "$DATA_DIR" > /dev/null 2>&1 + fi + if [ -f "$CONFIGURATION_FILE" ]; then + echo "Removing $CONFIGURATION_FILE" + rm -f "$CONFIGURATION_FILE" > /dev/null 2>&1 + fi + break + ;; + [nN][oO]|[nN]|"") + echo "Keeping the 'cortex' data folders." + break + ;; + *) + echo "Invalid response. Please type 'yes', 'no', 'y', or 'n' (case-insensitive)." + read -r answer + ;; + esac +done + +EOF + chmod +x $UNINSTALL_SCRIPT + echo "Uninstall script created at $UNINSTALL_SCRIPT" +} + +# Function to create updater script +create_updater_script() { + cat << EOF > $UPDATER_SCRIPT +#!/bin/bash +# Check for root privileges +if [ "\$(id -u)" != "0" ]; then + echo "This script must be run as root. Please run again with sudo." + exit 1 +fi +echo "Stopping cortex for update..." +su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS +curl -s https://raw.githubusercontent.com/janhq/cortex/feat/linux-bash-install-script/engine/templates/linux/install.sh | bash -s -- --channel $CHANNEL --is_update +EOF + chmod +x $UPDATER_SCRIPT + echo "Updater script created at $UPDATER_SCRIPT" +} + +# Run installation +check_install_jq_tar +install_cortex $CHANNEL $VERSION +create_uninstall_script +create_updater_script + +echo "Installation complete. Run cortex-uninstall.sh to uninstall and cortex-updater.sh to update." From d9376ed1b7a5529e3b9fca17d02ff5e61bb4538d Mon Sep 17 00:00:00 2001 From: Hien To Date: Thu, 14 Nov 2024 17:27:59 +0700 Subject: [PATCH 3/5] feat: linux bash install script support both .deb and binary --- engine/templates/linux/install.sh | 139 ++++++++++++++++++++---------- 1 file changed, 95 insertions(+), 44 deletions(-) diff --git a/engine/templates/linux/install.sh b/engine/templates/linux/install.sh index 7cf72a6cd..e11b879c6 100644 --- a/engine/templates/linux/install.sh +++ b/engine/templates/linux/install.sh @@ -6,6 +6,14 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi +# Determine the home directory based on the user +USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} +if [ "$USER_TO_RUN_AS" = "root" ]; then + USER_HOME="/root" +else + USER_HOME="/home/$USER_TO_RUN_AS" +fi + # Check and suggest installing jq and tar if not present check_install_jq_tar() { RED='\033[0;31m' @@ -47,18 +55,11 @@ get_latest_version() { echo "${tag_name#v}" } -# Determine the home directory based on the user -USER_TO_RUN_AS=${SUDO_USER:-$(whoami)} -if [ "$USER_TO_RUN_AS" = "root" ]; then - USER_HOME="/root" -else - USER_HOME="/home/$USER_TO_RUN_AS" -fi - # Default values CHANNEL="stable" VERSION="" IS_UPDATE="false" +DEB_LOCAL="false" # Function to parse command-line arguments parse_args() { @@ -72,6 +73,10 @@ parse_args() { VERSION="$2" shift 2 ;; + --deb_local) + DEB_LOCAL="true" + shift 1 + ;; --is_update) IS_UPDATE="true" shift 1 @@ -99,24 +104,24 @@ case $CHANNEL in SERVER_BINARY_NAME="cortex-server" DATA_DIR="$USER_HOME/cortexcpp" UNINSTALL_SCRIPT="/usr/bin/cortex-uninstall.sh" - UPDATER_SCRIPT="/usr/bin/cortex-updater.sh" CONFIGURATION_FILE="$USER_HOME/.cortexrc" + DEB_APP_NAME="cortexcpp" ;; beta) CLI_BINARY_NAME="cortex-beta" SERVER_BINARY_NAME="cortex-server-beta" DATA_DIR="$USER_HOME/cortexcpp-beta" UNINSTALL_SCRIPT="/usr/bin/cortex-beta-uninstall.sh" - UPDATER_SCRIPT="/usr/bin/cortex-beta-updater.sh" CONFIGURATION_FILE="$USER_HOME/.cortexrc-beta" + DEB_APP_NAME="cortexcpp-beta" ;; nightly) CLI_BINARY_NAME="cortex-nightly" SERVER_BINARY_NAME="cortex-server-nightly" DATA_DIR="$USER_HOME/cortexcpp-nightly" UNINSTALL_SCRIPT="/usr/bin/cortex-nightly-uninstall.sh" - UPDATER_SCRIPT="/usr/bin/cortex-nightly-updater.sh" CONFIGURATION_FILE="$USER_HOME/.cortexrc-nightly" + DEB_APP_NAME="cortexcpp-nightly" ;; *) echo "Invalid channel specified." @@ -130,34 +135,67 @@ INSTALL_DIR="/usr/bin" install_cortex() { local channel=$1 local version=$2 - local url="" + local is_deb=$3 + local url_binary="" + local url_deb_local="" + local url_deb_network="" case $channel in stable) - url="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + url_binary="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + url_deb_local="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64-local-installer.deb" + url_deb_network="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64-network-installer.deb" ;; beta) - url="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + url_binary="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64.tar.gz" + url_deb_local="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64-local-installer.deb" + url_deb_network="https://github.com/janhq/cortex.cpp/releases/download/v${version}/cortex-${version}-linux-amd64-network-installer.deb" ;; nightly) - url="https://delta.jan.ai/cortex/v${version}/linux-amd64/cortex-nightly.tar.gz" + url_binary="https://delta.jan.ai/cortex/v${version}/linux-amd64/cortex-nightly.tar.gz" + url_deb_local="https://delta.jan.ai/cortex/v${version}/linux-amd64/cortex-${version}-linux-amd64-local-installer.deb" + url_deb_network="https://delta.jan.ai/cortex/v${version}/linux-amd64/cortex-${version}-linux-amd64-network-installer.deb" ;; esac - echo "Downloading cortex $channel version $version from $url" - curl -L $url -o /tmp/cortex.tar.gz - tar -xzvf /tmp/cortex.tar.gz -C /tmp - chmod +x /tmp/cortex/* - cp /tmp/cortex/* /usr/bin/ - # Check is update or not - if [ "$IS_UPDATE" = "false" ]; then - su -c "$INSTALL_DIR/$CLI_BINARY_NAME engines install llama-cpp" $USER_TO_RUN_AS - su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS + + if [ "$is_deb" = "true" ]; then + # Download the deb package + if [ "$DEB_LOCAL" = "true" ]; then + echo "Downloading cortex $channel version $version from $url_deb_local" + curl -L $url_deb_local -o /tmp/cortex.deb + else + echo "Downloading cortex $channel version $version from $url_deb_network" + curl -L $url_deb_network -o /tmp/cortex.deb + fi + + # Install the deb package + if [ "$IS_UPDATE" = "false" ]; then + apt-get install -y /tmp/cortex.deb + else + echo -e "n\n" | SKIP_POSTINSTALL=true apt-get install -y --allow-downgrades /tmp/cortex.deb + fi + rm -f /tmp/cortex.deb + else + echo "Downloading cortex $channel version $version from $url_binary" + curl -L $url_binary -o /tmp/cortex.tar.gz + tar -xzvf /tmp/cortex.tar.gz -C /tmp + chmod +x /tmp/cortex/* + cp /tmp/cortex/* /usr/bin/ + # Check is update or not + if [ "$IS_UPDATE" = "false" ]; then + su -c "$INSTALL_DIR/$CLI_BINARY_NAME engines install llama-cpp" $USER_TO_RUN_AS + su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS + fi + rm -rf /tmp/cortex + rm -f /tmp/cortex.tar.gz fi } # Function to create uninstall script create_uninstall_script() { - cat << EOF > $UNINSTALL_SCRIPT + local is_deb=$1 + if [ "$is_deb" = "false" ]; then + cat << EOF > $UNINSTALL_SCRIPT #!/bin/bash # Check for root privileges if [ "\$(id -u)" != "0" ]; then @@ -167,12 +205,11 @@ fi echo "Stopping cortex..." su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS -rm -rf $INSTALL_DIR/$CLI_BINARY_NAME -rm -rf $INSTALL_DIR/$SERVER_BINARY_NAME +rm -f $INSTALL_DIR/$CLI_BINARY_NAME +rm -f $INSTALL_DIR/$SERVER_BINARY_NAME rm -f $UNINSTALL_SCRIPT -rm -f $UPDATER_SCRIPT -echo "Do you want to delete the ~/$DATA_DIR data folder and file ~/$CONFIGURATION_FILE? (yes/no) [default: no]" +echo "Do you want to delete the $DATA_DIR data folder and file $CONFIGURATION_FILE? (yes/no) [default: no]" read -r answer while true; do case "\$answer" in @@ -200,31 +237,45 @@ while true; do done EOF - chmod +x $UNINSTALL_SCRIPT - echo "Uninstall script created at $UNINSTALL_SCRIPT" -} -# Function to create updater script -create_updater_script() { - cat << EOF > $UPDATER_SCRIPT + else + cat << EOF > $UNINSTALL_SCRIPT #!/bin/bash # Check for root privileges if [ "\$(id -u)" != "0" ]; then echo "This script must be run as root. Please run again with sudo." exit 1 fi -echo "Stopping cortex for update..." -su -c "$INSTALL_DIR/$CLI_BINARY_NAME stop > /dev/null 2>&1" $USER_TO_RUN_AS -curl -s https://raw.githubusercontent.com/janhq/cortex/feat/linux-bash-install-script/engine/templates/linux/install.sh | bash -s -- --channel $CHANNEL --is_update + +apt-get remove -y $DEB_APP_NAME +rm -f $UNINSTALL_SCRIPT EOF - chmod +x $UPDATER_SCRIPT - echo "Updater script created at $UPDATER_SCRIPT" + fi + + chmod +x $UNINSTALL_SCRIPT + echo "Uninstall script created at $UNINSTALL_SCRIPT" } # Run installation check_install_jq_tar -install_cortex $CHANNEL $VERSION -create_uninstall_script -create_updater_script -echo "Installation complete. Run cortex-uninstall.sh to uninstall and cortex-updater.sh to update." +IS_DEB="false" + +# Check if apt-get command is available +if command -v apt-get &> /dev/null; then + if [ "$IS_UPDATE" = "true" ]; then + # check if cortexcpp deb package is installed + if dpkg -l | grep -q $DEB_APP_NAME; then + IS_DEB="true" + else + IS_DEB="false" + fi + else + IS_DEB="true" + fi +fi + +install_cortex $CHANNEL $VERSION $IS_DEB +create_uninstall_script $IS_DEB + +echo "Installation complete. Run cortex-uninstall.sh to uninstall." From ba4c625b0c2d021421ee7849d25fdcd875ba7f98 Mon Sep 17 00:00:00 2001 From: Gabrielle Ong Date: Fri, 15 Nov 2024 16:24:43 +0800 Subject: [PATCH 4/5] cleanup github readme + upcoming features --- .github/ISSUE_TEMPLATE/epic-request.md | 52 ++++++++++- README.md | 119 +++++++++++++------------ 2 files changed, 110 insertions(+), 61 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/epic-request.md b/.github/ISSUE_TEMPLATE/epic-request.md index 486ae90b6..9056ec3dc 100644 --- a/.github/ISSUE_TEMPLATE/epic-request.md +++ b/.github/ISSUE_TEMPLATE/epic-request.md @@ -6,12 +6,56 @@ labels: 'type: epic' assignees: '' --- +## Goal -**Problem** +## Success Criteria -**Success Criteria** -- -**Tasklist** +## Tasklist - [ ] + +## API / CLI Documentation +### API +#### 1. Feature +``` +GET /v1/endpoint +``` + +Body: +```json +{ + "key": "value" +} +``` +**Response** +```json +200 +{ +} +Error +{ +} +``` + +### CLI +#### 1. Feature +``` +GET /v1/endpoint +``` +Response: +``` +``` +#### Help Command +``` +❯ cortex ... +Usage: +cortex [options] [subcommand] +Options: + -h,--help Print this help message and exit + ... ... + +Subcommands: + start Start a model by ID + ... ... +``` \ No newline at end of file diff --git a/README.md b/README.md index 335bbc5b6..14c9d959a 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,15 @@ Cortex is a Local AI API Platform that is used to run and customize LLMs. Key Features: -- Straightforward CLI (inspired by Ollama) -- Full C++ implementation, packageable into Desktop and Mobile apps - Pull from Huggingface, or Cortex Built-in Models - Models stored in universal file formats (vs blobs) - Swappable Engines (default: [`llamacpp`](https://github.com/janhq/cortex.llamacpp), future: [`ONNXRuntime`](https://github.com/janhq/cortex.onnx), [`TensorRT-LLM`](https://github.com/janhq/cortex.tensorrt-llm)) - Cortex can be deployed as a standalone API server, or integrated into apps like [Jan.ai](https://jan.ai/) -Cortex's roadmap is to implement the full OpenAI API including Tools, Runs, Multi-modal and Realtime APIs. +Coming soon; now available on [cortex-nightly](#beta--nightly-versions): +- Engines Management (install specific llama-cpp version and variants) +- Nvidia Hardware detection & activation (current: Nvidia, future: AMD, Intel, Qualcomm) +- Cortex's roadmap is to implement the full OpenAI API including Tools, Runs, Multi-modal and Realtime APIs. ## Local Installation @@ -44,19 +45,19 @@ Cortex also has a [Network Installer](#network-installer) which downloads the ne

Windows: - cortex-windows-local-installer.exe + cortex.exe

MacOS (Silicon/Intel): - cortex-mac-local-installer.pkg + cortex.pkg

Linux: - cortex-linux-local-installer.deb + cortex.deb (Coming soon: Linux installation script)

- For Linux: Download the installer and run the following command in terminal: @@ -74,12 +75,21 @@ Cortex also has a [Network Installer](#network-installer) which downloads the ne After installation, you can run Cortex.cpp from the command line by typing `cortex --help`. ``` +# Run a Model cortex pull llama3.2 cortex pull bartowski/Meta-Llama-3.1-8B-Instruct-GGUF -cortex run llama3.2 -cortex models ps -cortex models stop llama3.2 -cortex stop +cortex run llama3.2 + +# Resource Management +cortex ps (view active models & RAM/VRAM used) +cortex models stop llama3.2 + +# Available on cortex-nightly: +cortex engines install llama-cpp -m (lists versions and variants) +cortex hardware list (hardware detection) +cortex hardware activate + +cortex stop ``` Refer to our [Quickstart](https://cortex.so/docs/quickstart/) and @@ -92,9 +102,7 @@ Refer to our [API documentation](https://cortex.so/api-reference) for more detai ## Models -Cortex.cpp allows users to pull models from multiple Model Hubs, offering flexibility and extensive model access. - -Currently Cortex supports pulling from: +Cortex.cpp allows users to pull models from multiple Model Hubs, offering flexibility and extensive model access: - [Hugging Face](https://huggingface.co): GGUF models eg `author/Model-GGUF` - Cortex Built-in Models @@ -141,41 +149,15 @@ Select a model (1-9): ``` ## Advanced Installation - -### Network Installer (Stable) - -Cortex.cpp is available with a Network Installer, which is a smaller installer but requires internet connection during installation to download the necessary dependencies. - -

- - Windows: - cortex-windows-network-installer.exe -

- -

- - MacOS (Universal): - cortex-mac-network-installer.pkg -

- -

- - Linux: - cortex-linux-network-installer.deb -

+### Beta & Nightly Versions (Local Installer) -### Beta & Nightly Versions - -Cortex releases 2 preview versions for advanced users to try new features early (we appreciate your feedback!) -- Beta (early preview) - - CLI command: `cortex-beta` -- Nightly (released every night) - - CLI Command: `cortex-nightly` +Cortex releases Beta and Nightly versions for advanced users to try new features (we appreciate your feedback!) +- Beta (early preview): CLI command: `cortex-beta` +- Nightly (released every night): CLI Command: `cortex-nightly` - Nightly automatically pulls the latest changes from upstream [llama.cpp](https://github.com/ggerganov/llama.cpp/) repo, creates a PR and runs tests. - If all test pass, the PR is automatically merged into our repo, with the latest llama.cpp version. -#### Local Installer (Default) @@ -188,19 +170,19 @@ Cortex releases 2 preview versions for advanced users to try new features early @@ -209,25 +191,27 @@ Cortex releases 2 preview versions for advanced users to try new features early
Version - cortex-beta-windows-local-installer.exe + cortex.exe - cortex-beta-mac-local-installer.pkg + cortex.pkg - cortex-beta-linux-local-installer.deb + cortex.deb
- cortex-nightly-windows-local-installer.exe + cortex.exe - cortex-nightly-mac-local-installer.pkg + cortex.pkg - cortex-nightly-linux-local-installer.deb + cortex.deb
-#### Network Installer +### Network Installer + +Cortex.cpp is available with a Network Installer, which is a smaller installer but requires internet connection during installation to download the necessary dependencies. @@ -236,24 +220,45 @@ Cortex releases 2 preview versions for advanced users to try new features early + + + + + + @@ -262,19 +267,19 @@ Cortex releases 2 preview versions for advanced users to try new features early From 0075e5fe33eb2c396a4e30ff4a61c35cad49f67d Mon Sep 17 00:00:00 2001 From: Gabrielle Ong Date: Fri, 15 Nov 2024 17:28:07 +0800 Subject: [PATCH 5/5] chore: CORS CLI doc --- docs/docs/cli/config.mdx | 78 ++++++++++++++++++++++++++++++++++++++++ docs/docs/cli/start.mdx | 2 +- docs/sidebars.ts | 1 + 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 docs/docs/cli/config.mdx diff --git a/docs/docs/cli/config.mdx b/docs/docs/cli/config.mdx new file mode 100644 index 000000000..471a7a04a --- /dev/null +++ b/docs/docs/cli/config.mdx @@ -0,0 +1,78 @@ +--- +title: Cortex Config +description: Cortex config command +slug: "config" +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# `cortex config` + +This command allows you to update server configurations such as CORS and Allowed Headers. + +## Usage +:::info +You can use the `--verbose` flag to display more detailed output of the internal processes. To apply this flag, use the following format: `cortex --verbose [subcommand]`. +::: + + + + ```sh + cortex config [options] [subcommand] + ``` + + + ```sh + cortex.exe config [options] [subcommand] + ``` + + + +**Options**: + +| Option | Description | Required | Default value | Example | +|------------------|-------------------------------------------|----------|----------------------|---------| +| `--cors` | Toggle CORS | No | true | `on`, `off` | +| `--allowed_origins`| Allowed origins for CORS | No | `http://localhost:39281`, `http://127.0.0.1:39281` | `http://localhost:3000` | +| `-h`, `--help` | Display help information for the command. | No | - | `-h` | + +--- +# Subcommands: + +## `cortex config status` +:::info +This CLI command calls the following API endpoint: +- [Get Configurations](/api-reference#tag/configurations/get/v1/configs) +::: +This command returns all server configurations. + +**Usage**: + + + ```sh + cortex config status + ``` + + + ```sh + cortex.exe config status + + ``` + + + +For example, it returns the following: + +``` ++-------------------------------------------------------------------------------------+ +| Config name | Value | ++-------------------------------------------------------------------------------------+ +| allowed_origins | http://localhost:39281 | ++-------------------------------------------------------------------------------------+ +| allowed_origins | http://127.0.0.1:39281/ | ++-------------------------------------------------------------------------------------+ +| cors | true | ++-------------------------------------------------------------------------------------+ + +``` \ No newline at end of file diff --git a/docs/docs/cli/start.mdx b/docs/docs/cli/start.mdx index 91a8e2819..703e5f535 100644 --- a/docs/docs/cli/start.mdx +++ b/docs/docs/cli/start.mdx @@ -35,7 +35,7 @@ You can use the `--verbose` flag to display more detailed output of the internal | ---------------------------- | ----------------------------------------- | -------- | ------------- | ----------------------------- | | `-h`, `--help` | Display help information for the command. | No | - | `-h` | | `-p`, `--port ` | Port to serve the application. | No | - | `-p 39281` | -| `--loglevel ` | Setup loglevel for cortex server, supported levels are TRACE, DEBUG, INFO, WARN, ERROR | No | - | `--loglevel DEBUG` | +| `--loglevel ` | Setup loglevel for cortex server, in the priority of `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE` | No | - | `--loglevel INFO` will display ERROR, WARN and INFO logs| diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 205d2a205..5249c743d 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -166,6 +166,7 @@ const sidebars: SidebarsConfig = { { type: "doc", id: "cli/cortex", label: "cortex" }, { type: "doc", id: "cli/start", label: "cortex start" }, { type: "doc", id: "cli/run", label: "cortex run" }, + { type: "doc", id: "cli/config", label: "cortex config" }, // { type: "doc", id: "cli/embeddings", label: "cortex embeddings" }, // { type: "doc", id: "cli/presets", label: "cortex presets" }, { type: "doc", id: "cli/pull", label: "cortex pull" },
MacOS Linux
Stable (Recommended) + + + cortex.exe + + + + + cortex.pkg + + + + + cortex.deb + +
Beta (Preview) - - cortex-beta-windows-network-installer.exe + + cortex.exe - cortex-beta-mac-network-installer.pkg + cortex.pkg - cortex-beta-linux-network-installer.deb + cortex.deb
- cortex-nightly-windows-network-installer.exe + cortex.exe - cortex-nightly-mac-network-installer.pkg + cortex.pkg - cortex-nightly-linux-network-installer.deb + cortex.deb